18487: Fixes error checking on nonexistant vocabulary file. Adds tests.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Tue, 18 Jan 2022 15:54:59 +0000 (12:54 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Tue, 18 Jan 2022 20:23:39 +0000 (17:23 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

lib/config/cmd.go
lib/config/cmd_test.go

index e532a7e32a09e1f04a4b93c319fefc8b7bdd21d6..2f90bc80dd850a6fca9db5d3b07a3ed387eb2cd3 100644 (file)
@@ -148,7 +148,7 @@ func (checkCommand) RunCommand(prog string, args []string, stdin io.Reader, stdo
                if cc.API.VocabularyPath == "" {
                        continue
                }
-               _, err = os.Stat(cc.API.VocabularyPath)
+               vd, err := os.ReadFile(cc.API.VocabularyPath)
                if err != nil {
                        if errors.Is(err, os.ErrNotExist) {
                                // If the vocabulary path doesn't exist, it might mean that
@@ -156,11 +156,6 @@ func (checkCommand) RunCommand(prog string, args []string, stdin io.Reader, stdo
                                // error.
                                continue
                        }
-                       fmt.Fprintf(stderr, "Error checking vocabulary path %q for cluster %s: %s\n", cc.API.VocabularyPath, id, err)
-                       return 1
-               }
-               vd, err := os.ReadFile(cc.API.VocabularyPath)
-               if err != nil {
                        fmt.Fprintf(stderr, "Error reading vocabulary file %q for cluster %s: %s\n", cc.API.VocabularyPath, id, err)
                        return 1
                }
index a5cc28b80c978670a52cfceaa385b567fa73b245..6b5ca4e577143849fcca13deb36bccdb213db268 100644 (file)
@@ -53,6 +53,7 @@ Clusters:
   SystemRootToken: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
   API:
     MaxItemsPerResponse: 1234
+    VocabularyPath: /this/path/does/not/exist
   Collections:
     BlobSigningKey: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
   PostgreSQL:
@@ -77,6 +78,60 @@ Clusters:
        c.Check(stderr.String(), check.Equals, "")
 }
 
+func (s *CommandSuite) TestCheck_VocabularyErrors(c *check.C) {
+       tmpFile, err := ioutil.TempFile("", "")
+       c.Assert(err, check.IsNil)
+       defer os.Remove(tmpFile.Name())
+       _, err = tmpFile.WriteString(`
+{
+ "tags": {
+  "IDfoo": {
+   "labels": [
+    {"label": "foo"}
+   ]
+  },
+  "IDfoo": {
+   "labels": [
+    {"label": "baz"}
+   ]
+  }
+ }
+}`)
+       c.Assert(err, check.IsNil)
+       tmpFile.Close()
+       vocPath := tmpFile.Name()
+       var stdout, stderr bytes.Buffer
+       in := `
+Clusters:
+ z1234:
+  ManagementToken: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+  SystemRootToken: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+  API:
+    MaxItemsPerResponse: 1234
+    VocabularyPath: ` + vocPath + `
+  Collections:
+    BlobSigningKey: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+  PostgreSQL:
+    Connection:
+      sslmode: require
+  Services:
+    RailsAPI:
+      InternalURLs:
+        "http://0.0.0.0:8000": {}
+  Workbench:
+    UserProfileFormFields:
+      color:
+        Type: select
+        Options:
+          fuchsia: {}
+    ApplicationMimetypesWithViewIcon:
+      whitespace: {}
+`
+       code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
+       c.Check(code, check.Equals, 1)
+       c.Check(stderr.String(), check.Matches, `(?s).*Error loading vocabulary file.*duplicate JSON key\(s\).*`)
+}
+
 func (s *CommandSuite) TestCheck_DeprecatedKeys(c *check.C) {
        var stdout, stderr bytes.Buffer
        in := `