Skip to content

Commit

Permalink
Deterministic TagPair assertion of custom registry (#1183)
Browse files Browse the repository at this point in the history
This ensures that we are testing images which were overriden by custom
registry. Some registries are meant to be excluded from override.

See #1181 for details.

Signed-off-by: Wilson E. Husin <whusin@vmware.com>
  • Loading branch information
wilsonehusin authored Nov 4, 2020
1 parent 7419e1d commit be8c386
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/image/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func GetE2EImages(e2eRegistryConfig, version string) ([]string, error) {
return imageNames, nil
}

// GetE2EImagePairs gets a list of E2E image tag pairs from the default src to custom destination
// GetE2EImageTagPairs gets a list of E2E image tag pairs from the default src to custom destination
func GetE2EImageTagPairs(e2eRegistryConfig, version string) ([]TagPair, error) {
defaultImageRegistry, err := NewRegistryList("", version)
if err != nil {
Expand Down
30 changes: 20 additions & 10 deletions pkg/image/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,31 @@ func TestGetE2EImageTagPairs(t *testing.T) {
}
expectedDefaultRegistry := defaultRegistry.v1_17()
if len(imageTagPairs) != len(expectedDefaultRegistry) {
t.Fatalf("Unexpected number of image tag pairs returned, expected %v, got %v", len(expectedDefaultRegistry), len(imageTagPairs))
t.Fatalf("unexpected number of image tag pairs returned, expected %v, got %v", len(expectedDefaultRegistry), len(imageTagPairs))
}

// Check one of the returned image pairs to ensure correct format
imageTagPair := imageTagPairs[0]
if strings.HasPrefix(imageTagPair.Src, customRegistry) {
t.Errorf("Src image should not have custom registry prefix: %q", imageTagPair.Src)
// As a sample, check one of the images for E2E and assert their mapping
var e2eImageTagPair TagPair
for _, imageTagPair := range imageTagPairs {
if strings.Contains(imageTagPair.Src, "e2e") {
e2eImageTagPair = imageTagPair
break
}
}

if e2eImageTagPair == (TagPair{}) {
t.Errorf("no e2eImageTagPair is found")
}
if strings.HasPrefix(e2eImageTagPair.Src, customRegistry) {
t.Errorf("src image should not have custom registry prefix: %q", e2eImageTagPair.Src)
}

imageComponents := strings.SplitAfter(imageTagPair.Src, "/")
if !strings.HasPrefix(imageTagPair.Dst, customRegistry) {
t.Errorf("Expected Dst image to have prefix %q, got %q", customRegistry, imageTagPair.Dst)
imageComponents := strings.SplitAfter(e2eImageTagPair.Src, "/")
if !strings.HasPrefix(e2eImageTagPair.Dst, customRegistry) {
t.Errorf("expected Dst image to have prefix %q, got %q", customRegistry, e2eImageTagPair.Dst)
}
if !strings.HasSuffix(imageTagPair.Dst, imageComponents[len(imageComponents)-1]) {
t.Errorf("Expected Dst image to have suffix %q, got %q", imageComponents[len(imageComponents)-1], imageTagPair.Dst)
if !strings.HasSuffix(e2eImageTagPair.Dst, imageComponents[len(imageComponents)-1]) {
t.Errorf("expected Dst image to have suffix %q, got %q", imageComponents[len(imageComponents)-1], e2eImageTagPair.Dst)
}
}

Expand Down

0 comments on commit be8c386

Please sign in to comment.