18321: Fix config export
[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", "12345", -1)
21         cfg, err := testLoader(c, confdata, nil).Load()
22         c.Assert(err, check.IsNil)
23         cluster, err := cfg.GetCluster("xxxxx")
24         c.Assert(err, check.IsNil)
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         var exportedStr = exported.String()
37         c.Check(exportedStr, check.Matches, `(?ms).*ClusterID":"xxxxx.*`)
38         c.Check(exportedStr, check.Not(check.Matches), `(?ms).*abcdefg.*`)
39 }