Merge branch '15106-trgm-text-search'
[arvados.git] / lib / config / export_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package config
6
7 import (
8         "bytes"
9         "regexp"
10         "strings"
11
12         "git.curoverse.com/arvados.git/sdk/go/ctxlog"
13         check "gopkg.in/check.v1"
14 )
15
16 var _ = check.Suite(&ExportSuite{})
17
18 type ExportSuite struct{}
19
20 func (s *ExportSuite) TestExport(c *check.C) {
21         confdata := bytes.Replace(DefaultYAML, []byte("SAMPLE"), []byte("testkey"), -1)
22         cfg, err := Load(bytes.NewBuffer(confdata), ctxlog.TestLogger(c))
23         c.Assert(err, check.IsNil)
24         cluster := cfg.Clusters["xxxxx"]
25         cluster.ManagementToken = "abcdefg"
26
27         var exported bytes.Buffer
28         err = ExportJSON(&exported, &cluster)
29         c.Check(err, check.IsNil)
30         if err != nil {
31                 c.Logf("If all the new keys are safe, add these to whitelist in export.go:")
32                 for _, k := range regexp.MustCompile(`"[^"]*"`).FindAllString(err.Error(), -1) {
33                         c.Logf("\t%q: true,", strings.Replace(k, `"`, "", -1))
34                 }
35         }
36         c.Check(exported.String(), check.Not(check.Matches), `(?ms).*abcdefg.*`)
37 }