From 010641c849a8e09078c8da816471cfdfa05a604f Mon Sep 17 00:00:00 2001 From: jonyhy Date: Wed, 29 Sep 2021 17:46:11 +0800 Subject: [PATCH] test: add benchmark test Signed-off-by: jonyhy --- test/utils/image/manifest_test.go | 61 ++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/test/utils/image/manifest_test.go b/test/utils/image/manifest_test.go index 3dc09a5d212..3a5ac2166e8 100644 --- a/test/utils/image/manifest_test.go +++ b/test/utils/image/manifest_test.go @@ -24,7 +24,66 @@ import ( "k8s.io/apimachinery/pkg/util/diff" ) -// ToDo Add Benchmark +func BenchmarkReplaceRegistryInImageURL(b *testing.B) { + registryTests := []struct { + in string + out string + }{ + { + in: "docker.io/library/test:123", + out: "test.io/library/test:123", + }, { + in: "docker.io/library/test", + out: "test.io/library/test", + }, { + in: "test", + out: "test.io/library/test", + }, { + in: "k8s.gcr.io/test:123", + out: "test.io/test:123", + }, { + in: "gcr.io/k8s-authenticated-test/test:123", + out: "test.io/k8s-authenticated-test/test:123", + }, { + in: "k8s.gcr.io/sig-storage/test:latest", + out: "test.io/sig-storage/test:latest", + }, { + in: "invalid.com/invalid/test:latest", + out: "test.io/invalid/test:latest", + }, { + in: "mcr.microsoft.com/test:latest", + out: "test.io/microsoft/test:latest", + }, { + in: "k8s.gcr.io/e2e-test-images/test:latest", + out: "test.io/promoter/test:latest", + }, { + in: "k8s.gcr.io/build-image/test:latest", + out: "test.io/build/test:latest", + }, { + in: "gcr.io/authenticated-image-pulling/test:latest", + out: "test.io/gcAuth/test:latest", + }, + } + reg := RegistryList{ + DockerLibraryRegistry: "test.io/library", + GcRegistry: "test.io", + PrivateRegistry: "test.io/k8s-authenticated-test", + SigStorageRegistry: "test.io/sig-storage", + InvalidRegistry: "test.io/invalid", + MicrosoftRegistry: "test.io/microsoft", + PromoterE2eRegistry: "test.io/promoter", + BuildImageRegistry: "test.io/build", + GcAuthenticatedRegistry: "test.io/gcAuth", + } + for i := 0; i < b.N; i++ { + tt := registryTests[i%len(registryTests)] + s, _ := replaceRegistryInImageURLWithList(tt.in, reg) + if s != tt.out { + b.Errorf("got %q, want %q", s, tt.out) + } + } +} + func TestReplaceRegistryInImageURL(t *testing.T) { registryTests := []struct { in string