diff --git a/pkg/cli.go b/pkg/cli.go index a2f460a..3befd84 100644 --- a/pkg/cli.go +++ b/pkg/cli.go @@ -78,8 +78,7 @@ func (c *Cli) Source2Target(source string) (*Output, error) { } } - if !strings.Contains(target, ":") && - !strings.Contains(source, "@sha256") && strings.Contains(source, ":") { + if !strings.Contains(target, ":") && strings.Contains(source, ":") { parts := strings.Split(source, ":") if len(parts) > 1 { target += ":" + parts[1] diff --git a/pkg/cli_test.go b/pkg/cli_test.go index 90f6bc0..cb8cd9f 100644 --- a/pkg/cli_test.go +++ b/pkg/cli_test.go @@ -27,6 +27,12 @@ func TestSource2Target(t *testing.T) { assert.Equal(t, source, output.Source) assert.Equal(t, "docker.io/togettoyou/registry.k8s.io.kube-apiserver:v1.27.4", output.Target) + source = "registry.k8s.io/kube-apiserver$kube-apiserver" + output, err = cli.Source2Target(source) + assert.Nil(t, err) + assert.Equal(t, "registry.k8s.io/kube-apiserver", output.Source) + assert.Equal(t, "docker.io/togettoyou/kube-apiserver", output.Target) + source = "registry.k8s.io/kube-apiserver:v1.27.4$kube-apiserver" output, err = cli.Source2Target(source) assert.Nil(t, err) @@ -43,7 +49,7 @@ func TestSource2Target(t *testing.T) { output, err = cli.Source2Target(source) assert.Nil(t, err) assert.Equal(t, "nginx@sha256:123456", output.Source) - assert.Equal(t, "docker.io/togettoyou/nginx", output.Target) + assert.Equal(t, "docker.io/togettoyou/nginx:123456", output.Target) source = "nginx@sha256:123456$nginx:mytag" output, err = cli.Source2Target(source)