From 4ffe7a793477046932a98afe2a3a0c22097a15a4 Mon Sep 17 00:00:00 2001 From: Junhao Zou Date: Sun, 28 Jan 2024 12:52:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BD=AC=E6=8D=A2=E8=A7=84?= =?UTF-8?q?=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/cli.go | 3 +-- pkg/cli_test.go | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) 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)