Skip to content

Commit

Permalink
Merge pull request #358 from estroz/bugfix/annotation-compare-validation
Browse files Browse the repository at this point in the history
pkg/lib/bundle/generate.go: do not compare number of annotations
  • Loading branch information
openshift-merge-robot committed Jun 11, 2020
2 parents b3fdc91 + a434c6f commit 275301b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions pkg/lib/bundle/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
k8syaml "k8s.io/apimachinery/pkg/util/yaml"
)

Expand Down Expand Up @@ -274,24 +275,22 @@ func ValidateAnnotations(existing, expected []byte) error {
return err
}

if len(fileAnnotations.Annotations) != len(expectedAnnotations.Annotations) {
return fmt.Errorf("Unmatched number of fields. Expected (%d) vs existing (%d)",
len(expectedAnnotations.Annotations), len(fileAnnotations.Annotations))
}

// Ensure each expected annotation key and value exist in existing.
var errs []error
for label, item := range expectedAnnotations.Annotations {
value, ok := fileAnnotations.Annotations[label]
if ok == false {
return fmt.Errorf("Missing field: %s", label)
value, hasAnnotation := fileAnnotations.Annotations[label]
if !hasAnnotation {
errs = append(errs, fmt.Errorf("Missing field: %s", label))
continue
}

if item != value {
return fmt.Errorf(`Expect field "%s" to have value "%s" instead of "%s"`,
label, item, value)
errs = append(errs, fmt.Errorf("Expect field %q to have value %q instead of %q",
label, item, value))
}
}

return nil
return utilerrors.NewAggregate(errs)
}

// ValidateChannelDefault validates provided default channel to ensure it exists in
Expand Down
2 changes: 1 addition & 1 deletion pkg/lib/bundle/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestValidateAnnotations(t *testing.T) {
"test1": "stable",
"test2": "stable,beta",
}),
fmt.Errorf("Unmatched number of fields. Expected (2) vs existing (3)"),
nil,
},
{
buildTestAnnotations("annotations",
Expand Down

0 comments on commit 275301b

Please sign in to comment.