mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #105344 from jonyhy96/add-benchmark-test
add benchmark test for replaceRegistryInImageURLWithList
This commit is contained in:
commit
956da16a8d
@ -24,7 +24,66 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/diff"
|
"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) {
|
func TestReplaceRegistryInImageURL(t *testing.T) {
|
||||||
registryTests := []struct {
|
registryTests := []struct {
|
||||||
in string
|
in string
|
||||||
|
Loading…
Reference in New Issue
Block a user