1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 "git.arvados.org/arvados.git/lib/cmd"
14 check "gopkg.in/check.v1"
17 var _ = check.Suite(&CommandSuite{})
20 // Commands must satisfy cmd.Handler interface
21 _ cmd.Handler = dumpCommand{}
22 _ cmd.Handler = checkCommand{}
25 type CommandSuite struct{}
27 func (s *CommandSuite) SetUpSuite(c *check.C) {
28 os.Unsetenv("ARVADOS_API_HOST")
29 os.Unsetenv("ARVADOS_API_HOST_INSECURE")
30 os.Unsetenv("ARVADOS_API_TOKEN")
33 func (s *CommandSuite) TestDump_BadArg(c *check.C) {
34 var stderr bytes.Buffer
35 code := DumpCommand.RunCommand("arvados config-dump", []string{"-badarg"}, bytes.NewBuffer(nil), bytes.NewBuffer(nil), &stderr)
36 c.Check(code, check.Equals, 2)
37 c.Check(stderr.String(), check.Matches, `(?ms)flag provided but not defined: -badarg\nUsage:\n.*`)
40 func (s *CommandSuite) TestDump_EmptyInput(c *check.C) {
41 var stdout, stderr bytes.Buffer
42 code := DumpCommand.RunCommand("arvados config-dump", []string{"-config", "-"}, &bytes.Buffer{}, &stdout, &stderr)
43 c.Check(code, check.Equals, 1)
44 c.Check(stderr.String(), check.Matches, `config does not define any clusters\n`)
47 func (s *CommandSuite) TestCheck_NoWarnings(c *check.C) {
48 var stdout, stderr bytes.Buffer
52 ManagementToken: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
53 SystemRootToken: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
55 MaxItemsPerResponse: 1234
57 BlobSigningKey: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
64 "http://0.0.0.0:8000": {}
66 UserProfileFormFields:
71 ApplicationMimetypesWithViewIcon:
74 code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
75 c.Check(code, check.Equals, 0)
76 c.Check(stdout.String(), check.Equals, "")
77 c.Check(stderr.String(), check.Equals, "")
80 func (s *CommandSuite) TestCheck_DeprecatedKeys(c *check.C) {
81 var stdout, stderr bytes.Buffer
86 MaxItemsPerResponse: 1234
88 code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
89 c.Check(code, check.Equals, 1)
90 c.Check(stdout.String(), check.Matches, `(?ms).*\n\- +.*MaxItemsPerResponse: 1000\n\+ +MaxItemsPerResponse: 1234\n.*`)
93 func (s *CommandSuite) TestCheck_OldKeepstoreConfigFile(c *check.C) {
94 f, err := ioutil.TempFile("", "")
95 c.Assert(err, check.IsNil)
96 defer os.Remove(f.Name())
98 io.WriteString(f, "Listen: :12345\nDebug: true\n")
100 var stdout, stderr bytes.Buffer
107 code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-", "-legacy-keepstore-config", f.Name()}, bytes.NewBufferString(in), &stdout, &stderr)
108 c.Check(code, check.Equals, 1)
109 c.Check(stdout.String(), check.Matches, `(?ms).*\n\- +.*LogLevel: info\n\+ +LogLevel: debug\n.*`)
110 c.Check(stderr.String(), check.Matches, `(?ms).*you should remove the legacy keepstore config file.*\n`)
113 func (s *CommandSuite) TestCheck_UnknownKey(c *check.C) {
114 var stdout, stderr bytes.Buffer
128 code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
129 c.Log(stderr.String())
130 c.Check(code, check.Equals, 1)
131 c.Check(stderr.String(), check.Matches, `(?ms).*deprecated or unknown config entry: Clusters.z1234.Bogus1"\n.*`)
132 c.Check(stderr.String(), check.Matches, `(?ms).*deprecated or unknown config entry: Clusters.z1234.BogusSection"\n.*`)
133 c.Check(stderr.String(), check.Matches, `(?ms).*deprecated or unknown config entry: Clusters.z1234.API.Bogus3"\n.*`)
134 c.Check(stderr.String(), check.Matches, `(?ms).*unexpected object in config entry: Clusters.z1234.PostgreSQL.ConnectionPool"\n.*`)
137 func (s *CommandSuite) TestDump_Formatting(c *check.C) {
138 var stdout, stderr bytes.Buffer
148 http://localhost:12345: {}
150 code := DumpCommand.RunCommand("arvados config-dump", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
151 c.Check(code, check.Equals, 0)
152 c.Check(stdout.String(), check.Matches, `(?ms).*TimeoutBooting: 10m\n.*`)
153 c.Check(stdout.String(), check.Matches, `(?ms).*http://localhost:12345/: {}\n.*`)
156 func (s *CommandSuite) TestDump_UnknownKey(c *check.C) {
157 var stdout, stderr bytes.Buffer
162 ManagementToken: secret
164 code := DumpCommand.RunCommand("arvados config-dump", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
165 c.Check(code, check.Equals, 0)
166 c.Check(stderr.String(), check.Matches, `(?ms).*deprecated or unknown config entry: Clusters.z1234.UnknownKey.*`)
167 c.Check(stdout.String(), check.Matches, `(?ms)(.*\n)?Clusters:\n z1234:\n.*`)
168 c.Check(stdout.String(), check.Matches, `(?ms).*\n *ManagementToken: secret\n.*`)
169 c.Check(stdout.String(), check.Not(check.Matches), `(?ms).*UnknownKey.*`)