17944: Only check for value aliases collision between different values.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Wed, 10 Nov 2021 19:31:12 +0000 (16:31 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Wed, 10 Nov 2021 19:31:12 +0000 (16:31 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

sdk/go/arvados/vocabulary.go
sdk/go/arvados/vocabulary_test.go

index 8de6970781f8a60593b2ad0312857cc3ed685a4c..150091b308505b51f1830d33351cc7a706161650 100644 (file)
@@ -112,13 +112,14 @@ func (v *Vocabulary) validate() error {
                        if tagValues[lcVal] != "" {
                                return fmt.Errorf("duplicate tag value %q for tag %q", val, key)
                        }
+                       // Checks for collisions between labels from different values.
                        tagValues[lcVal] = val
                        for _, tagLbl := range v.Tags[key].Values[val].Labels {
                                label := strings.ToLower(tagLbl.Label)
-                               if tagValues[label] != "" {
-                                       return fmt.Errorf("tag value label %q for pair (%q:%q) already seen as a value key or label", tagLbl.Label, key, val)
+                               if tagValues[label] != "" && tagValues[label] != val {
+                                       return fmt.Errorf("tag value label %q for pair (%q:%q) already seen on value %q", tagLbl.Label, key, val, tagValues[label])
                                }
-                               tagValues[label] = tagLbl.Label
+                               tagValues[label] = val
                        }
                }
        }
index 3099495a33da0bf2238cf95a2b96982b25e9a97a..5a5189de2b3e1c9d66d6c818bd1ce1f11554bf17 100644 (file)
@@ -220,7 +220,8 @@ func (s *VocabularySuite) TestNewVocabulary(c *check.C) {
                                        "labels": [{"label": "Animal"}, {"label": "Creature"}],
                                        "values": {
                                                "IDVALANIMAL1":{"labels":[{"label":"Human"}, {"label":"Homo sapiens"}]},
-                                               "IDVALANIMAL2":{"labels":[{"label":"Elephant"}, {"label":"Loxodonta"}]}
+                                               "IDVALANIMAL2":{"labels":[{"label":"Elephant"}, {"label":"Loxodonta"}]},
+                                               "DOG":{"labels":[{"label":"Dog"}, {"label":"Canis lupus familiaris"}, {"label":"dOg"}]}
                                        }
                                }
                        }}`,
@@ -248,6 +249,9 @@ func (s *VocabularySuite) TestNewVocabulary(c *check.C) {
                                                        "IDVALANIMAL2": {
                                                                Labels: []VocabularyLabel{{Label: "Elephant"}, {Label: "Loxodonta"}},
                                                        },
+                                                       "DOG": {
+                                                               Labels: []VocabularyLabel{{Label: "Dog"}, {Label: "Canis lupus familiaris"}, {Label: "dOg"}},
+                                                       },
                                                },
                                        },
                                },
@@ -405,7 +409,28 @@ func (s *VocabularySuite) TestValidationErrors(c *check.C) {
                                        },
                                },
                        },
-                       "tag value label.*for pair.*already seen.*",
+                       "tag value label.*for pair.*already seen.*on value.*",
+               },
+               {
+                       "Collision between tag value labels (case-insensitive)",
+                       &Vocabulary{
+                               StrictTags: false,
+                               Tags: map[string]VocabularyTag{
+                                       "IDTAGANIMALS": {
+                                               Strict: false,
+                                               Labels: []VocabularyLabel{{Label: "Animal"}, {Label: "Creature"}},
+                                               Values: map[string]VocabularyTagValue{
+                                                       "IDVALANIMAL1": {
+                                                               Labels: []VocabularyLabel{{Label: "Human"}, {Label: "Mammal"}},
+                                                       },
+                                                       "IDVALANIMAL2": {
+                                                               Labels: []VocabularyLabel{{Label: "Elephant"}, {Label: "mAMMAL"}},
+                                                       },
+                                               },
+                                       },
+                               },
+                       },
+                       "tag value label.*for pair.*already seen.*on value.*",
                },
                {
                        "Strict tag key, with no values",