X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/af44b96bc1f843c1b7878049e161602fef839d1d..1a61611cbb8ed4471eb2e04e60bad548bff94678:/sdk/go/arvados/vocabulary_test.go?ds=sidebyside diff --git a/sdk/go/arvados/vocabulary_test.go b/sdk/go/arvados/vocabulary_test.go index da62d5c251..af62833a31 100644 --- a/sdk/go/arvados/vocabulary_test.go +++ b/sdk/go/arvados/vocabulary_test.go @@ -6,6 +6,8 @@ package arvados import ( "encoding/json" + "regexp" + "strings" check "gopkg.in/check.v1" ) @@ -56,7 +58,7 @@ func (s *VocabularySuite) SetUpTest(c *check.C) { }, }, } - err := s.testVoc.validate() + _, err := s.testVoc.validate() c.Assert(err, check.IsNil) } @@ -228,14 +230,17 @@ func (s *VocabularySuite) TestNewVocabulary(c *check.C) { true, "", &Vocabulary{ reservedTagKeys: map[string]bool{ - "type": true, - "template_uuid": true, - "groups": true, - "username": true, - "image_timestamp": true, + "container_request": true, + "container_uuid": true, + "cwl_input": true, + "cwl_output": true, "docker-image-repo-tag": true, "filters": true, - "container_request": true, + "groups": true, + "image_timestamp": true, + "template_uuid": true, + "type": true, + "username": true, }, StrictTags: false, Tags: map[string]VocabularyTag{ @@ -267,7 +272,7 @@ func (s *VocabularySuite) TestNewVocabulary(c *check.C) { false, `invalid JSON format:.*\(line \d+, column \d+\)`, nil, }, { - "Invalid JSON with duplicate keys", + "Invalid JSON with duplicate & reserved keys", `{"tags":{ "type":{ "strict": false, @@ -277,17 +282,7 @@ func (s *VocabularySuite) TestNewVocabulary(c *check.C) { "labels": [] } }}`, - false, "(?s).*tags.type.labels.0.label\ntags.type", nil, - }, - { - "Valid data, but uses reserved key", - `{"tags":{ - "type":{ - "strict": false, - "labels": [{"label": "Class"}] - } - }}`, - false, "(?s).*tag key.*is reserved", nil, + false, "(?s).*duplicate JSON key \"tags.type.labels.0.label\"\nduplicate JSON key \"tags.type\"\ntag key \"type\" is reserved", nil, }, } @@ -306,6 +301,37 @@ func (s *VocabularySuite) TestNewVocabulary(c *check.C) { } } +func (s *VocabularySuite) TestValidSystemProperties(c *check.C) { + s.testVoc.StrictTags = true + properties := map[string]interface{}{ + "arv:gitBranch": "main", + "arv:OK": true, + "arv:cost": 123, + } + c.Check(s.testVoc.Check(properties), check.IsNil) +} + +func (s *VocabularySuite) TestSystemPropertiesPrefixTypo(c *check.C) { + s.testVoc.StrictTags = true + for _, key := range []string{ + // Extra characters in prefix + "arv :foo", + " arv:foo", + // Wrong punctuation + "arv.foo", + "arv-foo", + "arv_foo", + // Wrong case + "Arv:foo", + // Wrong word + "arvados", + "arvados:foo", + } { + properties := map[string]interface{}{key: "value"} + c.Check(s.testVoc.Check(properties), check.NotNil) + } +} + func (s *VocabularySuite) TestValidationErrors(c *check.C) { tests := []struct { name string @@ -489,10 +515,23 @@ func (s *VocabularySuite) TestValidationErrors(c *check.C) { } for _, tt := range tests { c.Log(c.TestName()+" ", tt.name) - err := tt.voc.validate() + validationErrs, err := tt.voc.validate() c.Assert(err, check.NotNil) for _, errMatch := range tt.errMatches { - c.Assert(err, check.ErrorMatches, errMatch) + seen := false + for _, validationErr := range validationErrs { + if regexp.MustCompile(errMatch).MatchString(validationErr) { + seen = true + break + } + } + if len(validationErrs) == 0 { + c.Assert(err, check.ErrorMatches, errMatch) + } else { + c.Assert(seen, check.Equals, true, + check.Commentf("Expected to see error matching %q:\n%s", + errMatch, strings.Join(validationErrs, "\n"))) + } } } }