Merge branch '13647-load-old-config'
[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         check "gopkg.in/check.v1"
13 )
14
15 var _ = check.Suite(&ExportSuite{})
16
17 type ExportSuite struct{}
18
19 func (s *ExportSuite) TestExport(c *check.C) {
20         confdata := strings.Replace(string(DefaultYAML), "SAMPLE", "testkey", -1)
21         cfg, err := testLoader(c, confdata, nil).Load()
22         c.Assert(err, check.IsNil)
23         cluster := cfg.Clusters["xxxxx"]
24         cluster.ManagementToken = "abcdefg"
25
26         var exported bytes.Buffer
27         err = ExportJSON(&exported, &cluster)
28         c.Check(err, check.IsNil)
29         if err != nil {
30                 c.Logf("If all the new keys are safe, add these to whitelist in export.go:")
31                 for _, k := range regexp.MustCompile(`"[^"]*"`).FindAllString(err.Error(), -1) {
32                         c.Logf("\t%q: true,", strings.Replace(k, `"`, "", -1))
33                 }
34         }
35         c.Check(exported.String(), check.Not(check.Matches), `(?ms).*abcdefg.*`)
36 }