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, cmd.EXIT_INVALIDARGUMENT)
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:
73 code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
74 c.Check(code, check.Equals, 0)
75 c.Check(stdout.String(), check.Equals, "")
76 c.Check(stderr.String(), check.Equals, "")
79 func (s *CommandSuite) TestCheck_VocabularyErrors(c *check.C) {
80 tmpFile, err := ioutil.TempFile("", "")
81 c.Assert(err, check.IsNil)
82 defer os.Remove(tmpFile.Name())
83 _, err = tmpFile.WriteString(`
98 c.Assert(err, check.IsNil)
100 vocPath := tmpFile.Name()
101 var stdout, stderr bytes.Buffer
105 ManagementToken: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
106 SystemRootToken: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
108 MaxItemsPerResponse: 1234
109 VocabularyPath: ` + vocPath + `
111 BlobSigningKey: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
118 "http://0.0.0.0:8000": {}
120 UserProfileFormFields:
126 code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
127 c.Check(code, check.Equals, 1)
128 c.Check(stderr.String(), check.Matches, `(?ms).*Error loading vocabulary file.*for cluster.*duplicate JSON key.*tags.IDfoo.*`)
131 func (s *CommandSuite) TestCheck_DeprecatedKeys(c *check.C) {
132 var stdout, stderr bytes.Buffer
137 MaxItemsPerResponse: 1234
139 code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
140 c.Check(code, check.Equals, 1)
141 c.Check(stdout.String(), check.Matches, `(?ms).*\n\- +.*MaxItemsPerResponse: 1000\n\+ +MaxItemsPerResponse: 1234\n.*`)
144 func (s *CommandSuite) TestCheck_OldKeepstoreConfigFile(c *check.C) {
145 f, err := ioutil.TempFile("", "")
146 c.Assert(err, check.IsNil)
147 defer os.Remove(f.Name())
149 io.WriteString(f, "Listen: :12345\nDebug: true\n")
151 var stdout, stderr bytes.Buffer
158 code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-", "-legacy-keepstore-config", f.Name()}, bytes.NewBufferString(in), &stdout, &stderr)
159 c.Check(code, check.Equals, 1)
160 c.Check(stdout.String(), check.Matches, `(?ms).*\n\- +.*LogLevel: info\n\+ +LogLevel: debug\n.*`)
161 c.Check(stderr.String(), check.Matches, `(?ms).*you should remove the legacy keepstore config file.*\n`)
164 func (s *CommandSuite) TestCheck_UnknownKey(c *check.C) {
165 var stdout, stderr bytes.Buffer
179 code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
180 c.Log(stderr.String())
181 c.Check(code, check.Equals, 1)
182 c.Check(stderr.String(), check.Matches, `(?ms).*deprecated or unknown config entry: Clusters.z1234.Bogus1"\n.*`)
183 c.Check(stderr.String(), check.Matches, `(?ms).*deprecated or unknown config entry: Clusters.z1234.BogusSection"\n.*`)
184 c.Check(stderr.String(), check.Matches, `(?ms).*deprecated or unknown config entry: Clusters.z1234.API.Bogus3"\n.*`)
185 c.Check(stderr.String(), check.Matches, `(?ms).*unexpected object in config entry: Clusters.z1234.PostgreSQL.ConnectionPool"\n.*`)
188 func (s *CommandSuite) TestCheck_DuplicateWarnings(c *check.C) {
189 var stdout, stderr bytes.Buffer
194 code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
195 c.Check(code, check.Equals, 1)
196 c.Check(stderr.String(), check.Matches, `(?ms).*SystemRootToken.*`)
197 c.Check(stderr.String(), check.Not(check.Matches), `(?ms).*SystemRootToken.*SystemRootToken.*`)
200 func (s *CommandSuite) TestDump_Formatting(c *check.C) {
201 var stdout, stderr bytes.Buffer
211 http://localhost:12345: {}
213 code := DumpCommand.RunCommand("arvados config-dump", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
214 c.Check(code, check.Equals, 0)
215 c.Check(stdout.String(), check.Matches, `(?ms).*TimeoutBooting: 10m\n.*`)
216 c.Check(stdout.String(), check.Matches, `(?ms).*http://localhost:12345/:\n +ListenURL: ""\n.*`)
219 func (s *CommandSuite) TestDump_UnknownKey(c *check.C) {
220 var stdout, stderr bytes.Buffer
225 ManagementToken: secret
227 code := DumpCommand.RunCommand("arvados config-dump", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
228 c.Check(code, check.Equals, 0)
229 c.Check(stderr.String(), check.Matches, `(?ms).*deprecated or unknown config entry: Clusters.z1234.UnknownKey.*`)
230 c.Check(stdout.String(), check.Matches, `(?ms)(.*\n)?Clusters:\n z1234:\n.*`)
231 c.Check(stdout.String(), check.Matches, `(?ms).*\n *ManagementToken: secret\n.*`)
232 c.Check(stdout.String(), check.Not(check.Matches), `(?ms).*UnknownKey.*`)
235 func (s *CommandSuite) TestDump_KeyOrder(c *check.C) {
248 for trial := 0; trial < 20; trial++ {
249 var stdout, stderr bytes.Buffer
250 code := DumpCommand.RunCommand("arvados config-dump", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
251 c.Assert(code, check.Equals, 0)
252 if !c.Check(stdout.String(), check.Matches, `(?ms).*a:.*b:.*c:.*d:.*e:.*`) {
253 c.Logf("config-dump did not use lexical key order on trial %d", trial)
254 c.Log("stdout:\n", stdout.String())
255 c.Log("stderr:\n", stderr.String())
261 func (s *CommandSuite) TestCheck_KeyOrder(c *check.C) {
265 ManagementToken: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
266 SystemRootToken: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
268 BlobSigningKey: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
274 for trial := 0; trial < 20; trial++ {
275 var stdout, stderr bytes.Buffer
276 code := CheckCommand.RunCommand("arvados config-check", []string{"-config=-", "-strict=true"}, bytes.NewBufferString(in), &stdout, &stderr)
277 if !c.Check(code, check.Equals, 0) || stdout.String() != "" || stderr.String() != "" {
278 c.Logf("config-check returned error or non-empty output on trial %d", trial)
279 c.Log("stdout:\n", stdout.String())
280 c.Log("stderr:\n", stderr.String())