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.Equals, "error parsing command line arguments: flag provided but not defined: -badarg (try -help)\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
56 VocabularyPath: /this/path/does/not/exist
58 BlobSigningKey: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
65 "http://0.0.0.0:8000": {}
67 UserProfileFormFields:
72 ApplicationMimetypesWithViewIcon:
75 code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
76 c.Check(code, check.Equals, 0)
77 c.Check(stdout.String(), check.Equals, "")
78 c.Check(stderr.String(), check.Equals, "")
81 func (s *CommandSuite) TestCheck_VocabularyErrors(c *check.C) {
82 tmpFile, err := ioutil.TempFile("", "")
83 c.Assert(err, check.IsNil)
84 defer os.Remove(tmpFile.Name())
85 _, err = tmpFile.WriteString(`
100 c.Assert(err, check.IsNil)
102 vocPath := tmpFile.Name()
103 var stdout, stderr bytes.Buffer
107 ManagementToken: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
108 SystemRootToken: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
110 MaxItemsPerResponse: 1234
111 VocabularyPath: ` + vocPath + `
113 BlobSigningKey: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
120 "http://0.0.0.0:8000": {}
122 UserProfileFormFields:
127 ApplicationMimetypesWithViewIcon:
130 code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
131 c.Check(code, check.Equals, 1)
132 c.Check(stderr.String(), check.Matches, `(?ms).*Error loading vocabulary file.*for cluster.*duplicate JSON key.*tags.IDfoo.*`)
135 func (s *CommandSuite) TestCheck_DeprecatedKeys(c *check.C) {
136 var stdout, stderr bytes.Buffer
141 MaxItemsPerResponse: 1234
143 code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
144 c.Check(code, check.Equals, 1)
145 c.Check(stdout.String(), check.Matches, `(?ms).*\n\- +.*MaxItemsPerResponse: 1000\n\+ +MaxItemsPerResponse: 1234\n.*`)
148 func (s *CommandSuite) TestCheck_OldKeepstoreConfigFile(c *check.C) {
149 f, err := ioutil.TempFile("", "")
150 c.Assert(err, check.IsNil)
151 defer os.Remove(f.Name())
153 io.WriteString(f, "Listen: :12345\nDebug: true\n")
155 var stdout, stderr bytes.Buffer
162 code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-", "-legacy-keepstore-config", f.Name()}, bytes.NewBufferString(in), &stdout, &stderr)
163 c.Check(code, check.Equals, 1)
164 c.Check(stdout.String(), check.Matches, `(?ms).*\n\- +.*LogLevel: info\n\+ +LogLevel: debug\n.*`)
165 c.Check(stderr.String(), check.Matches, `(?ms).*you should remove the legacy keepstore config file.*\n`)
168 func (s *CommandSuite) TestCheck_UnknownKey(c *check.C) {
169 var stdout, stderr bytes.Buffer
183 code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
184 c.Log(stderr.String())
185 c.Check(code, check.Equals, 1)
186 c.Check(stderr.String(), check.Matches, `(?ms).*deprecated or unknown config entry: Clusters.z1234.Bogus1"\n.*`)
187 c.Check(stderr.String(), check.Matches, `(?ms).*deprecated or unknown config entry: Clusters.z1234.BogusSection"\n.*`)
188 c.Check(stderr.String(), check.Matches, `(?ms).*deprecated or unknown config entry: Clusters.z1234.API.Bogus3"\n.*`)
189 c.Check(stderr.String(), check.Matches, `(?ms).*unexpected object in config entry: Clusters.z1234.PostgreSQL.ConnectionPool"\n.*`)
192 func (s *CommandSuite) TestCheck_DuplicateWarnings(c *check.C) {
193 var stdout, stderr bytes.Buffer
198 code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
199 c.Check(code, check.Equals, 1)
200 c.Check(stderr.String(), check.Matches, `(?ms).*SystemRootToken.*`)
201 c.Check(stderr.String(), check.Not(check.Matches), `(?ms).*SystemRootToken.*SystemRootToken.*`)
204 func (s *CommandSuite) TestDump_Formatting(c *check.C) {
205 var stdout, stderr bytes.Buffer
215 http://localhost:12345: {}
217 code := DumpCommand.RunCommand("arvados config-dump", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
218 c.Check(code, check.Equals, 0)
219 c.Check(stdout.String(), check.Matches, `(?ms).*TimeoutBooting: 10m\n.*`)
220 c.Check(stdout.String(), check.Matches, `(?ms).*http://localhost:12345/: {}\n.*`)
223 func (s *CommandSuite) TestDump_UnknownKey(c *check.C) {
224 var stdout, stderr bytes.Buffer
229 ManagementToken: secret
231 code := DumpCommand.RunCommand("arvados config-dump", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
232 c.Check(code, check.Equals, 0)
233 c.Check(stderr.String(), check.Matches, `(?ms).*deprecated or unknown config entry: Clusters.z1234.UnknownKey.*`)
234 c.Check(stdout.String(), check.Matches, `(?ms)(.*\n)?Clusters:\n z1234:\n.*`)
235 c.Check(stdout.String(), check.Matches, `(?ms).*\n *ManagementToken: secret\n.*`)
236 c.Check(stdout.String(), check.Not(check.Matches), `(?ms).*UnknownKey.*`)
239 func (s *CommandSuite) TestDump_KeyOrder(c *check.C) {
252 for trial := 0; trial < 20; trial++ {
253 var stdout, stderr bytes.Buffer
254 code := DumpCommand.RunCommand("arvados config-dump", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
255 c.Assert(code, check.Equals, 0)
256 if !c.Check(stdout.String(), check.Matches, `(?ms).*a:.*b:.*c:.*d:.*e:.*`) {
257 c.Logf("config-dump did not use lexical key order on trial %d", trial)
258 c.Log("stdout:\n", stdout.String())
259 c.Log("stderr:\n", stderr.String())
265 func (s *CommandSuite) TestCheck_KeyOrder(c *check.C) {
269 ManagementToken: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
270 SystemRootToken: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
272 BlobSigningKey: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
278 for trial := 0; trial < 20; trial++ {
279 var stdout, stderr bytes.Buffer
280 code := CheckCommand.RunCommand("arvados config-check", []string{"-config=-", "-strict=true"}, bytes.NewBufferString(in), &stdout, &stderr)
281 if !c.Check(code, check.Equals, 0) || stdout.String() != "" || stderr.String() != "" {
282 c.Logf("config-check returned error or non-empty output on trial %d", trial)
283 c.Log("stdout:\n", stdout.String())
284 c.Log("stderr:\n", stderr.String())