52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package discovery_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/shcizo/package-updater/internal/discovery"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestNormaliseImage(t *testing.T) {
|
|
cases := []struct {
|
|
in string
|
|
want string
|
|
}{
|
|
{"registry.example.com/myapp", "registry.example.com/myapp"},
|
|
{"registry.example.com/myapp:v1.2.3", "registry.example.com/myapp"},
|
|
{"registry.example.com/myapp:latest", "registry.example.com/myapp"},
|
|
{"registry.example.com/myapp@sha256:abc123", "registry.example.com/myapp"},
|
|
{"registry.example.com/myapp:v1.2.3@sha256:abc123", "registry.example.com/myapp"},
|
|
{"nginx", "nginx"},
|
|
{"nginx:1.25-alpine", "nginx"},
|
|
{"library/nginx:latest", "library/nginx"},
|
|
{"gcr.io/proj/svc:tag", "gcr.io/proj/svc"},
|
|
{"localhost:5000/myimg:v1", "localhost:5000/myimg"},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.in, func(t *testing.T) {
|
|
require.Equal(t, c.want, discovery.NormaliseImage(c.in))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestImagesMatch(t *testing.T) {
|
|
require.True(t, discovery.ImagesMatch(
|
|
"registry.example.com/myapp",
|
|
"registry.example.com/myapp:v1.2.3",
|
|
))
|
|
require.True(t, discovery.ImagesMatch(
|
|
"registry.example.com/myapp:v1.0.0",
|
|
"registry.example.com/myapp:v9.9.9",
|
|
))
|
|
require.False(t, discovery.ImagesMatch(
|
|
"registry.example.com/myapp",
|
|
"registry.example.com/otherapp",
|
|
))
|
|
// Case-sensitive per spec section 5.2
|
|
require.False(t, discovery.ImagesMatch(
|
|
"registry.example.com/MyApp",
|
|
"registry.example.com/myapp",
|
|
))
|
|
}
|