From be8c386368f6c2dbefc000b2faf91b759f4db87c Mon Sep 17 00:00:00 2001 From: "Wilson E. Husin" Date: Wed, 4 Nov 2020 13:04:01 -0800 Subject: [PATCH] Deterministic TagPair assertion of custom registry (#1183) 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 --- pkg/image/manifest.go | 2 +- pkg/image/manifest_test.go | 30 ++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/pkg/image/manifest.go b/pkg/image/manifest.go index 2c2551ca1..f63663a00 100644 --- a/pkg/image/manifest.go +++ b/pkg/image/manifest.go @@ -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 { diff --git a/pkg/image/manifest_test.go b/pkg/image/manifest_test.go index 0c595da11..c06b970c5 100644 --- a/pkg/image/manifest_test.go +++ b/pkg/image/manifest_test.go @@ -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) } }