1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

chore: add unit tests for pkg/utils/image (#4508)

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
This commit is contained in:
Charles-Edouard Brétéché 2022-09-05 22:46:57 +02:00 committed by GitHub
parent bcd06c7cbd
commit 1eb67422ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -61,9 +61,50 @@ func Test_GetImageInfo(t *testing.T) {
"docker.io/test/centos@sha256:dead07b4d8ed7e29e98de0f4504d87e8880d4347859d839686a31da35a3b532f")
}
func Test_ReferenceWithTag(t *testing.T) {
testCases := []struct {
input string
expected string
}{{
input: "nginx",
expected: "docker.io/nginx:latest",
}, {
input: "nginx:v10.3",
expected: "docker.io/nginx:v10.3",
}, {
input: "docker.io/test/nginx:v10.3",
expected: "docker.io/test/nginx:v10.3",
}, {
input: "test/nginx",
expected: "docker.io/test/nginx:latest",
}, {
input: "localhost:4443/test/nginx",
expected: "localhost:4443/test/nginx:latest",
}, {
input: "docker.io/test/centos@sha256:dead07b4d8ed7e29e98de0f4504d87e8880d4347859d839686a31da35a3b532f",
expected: "docker.io/test/centos:",
}}
for _, test := range testCases {
imageInfo, err := GetImageInfo(test.input)
assert.NoError(t, err)
assert.Equal(t, test.expected, imageInfo.ReferenceWithTag())
}
}
func Test_ParseError(t *testing.T) {
testCases := []string{
"++",
}
for _, test := range testCases {
imageInfo, err := GetImageInfo(test)
assert.Error(t, err)
assert.Nil(t, imageInfo)
}
}
func validateImageInfo(t *testing.T, raw, name, path, registry, tag, digest, str string) {
i1, err := GetImageInfo(raw)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, name, i1.Name)
assert.Equal(t, path, i1.Path)
assert.Equal(t, registry, i1.Registry)