From 58f72a2d195b9bc1f0d7b40d86b57a182a946da1 Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Thu, 22 May 2025 11:50:32 -0600 Subject: [PATCH] Use client.out for logging Signed-off-by: Terry Howe --- pkg/registry/client.go | 6 +++--- pkg/registry/client_test.go | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/registry/client.go b/pkg/registry/client.go index a27559e4d..8a9dd7f2a 100644 --- a/pkg/registry/client.go +++ b/pkg/registry/client.go @@ -232,10 +232,10 @@ type ( // Added for backwards compatibility for Helm < 3.18.0 after moving to ORAS v2 // ref: https://github.com/helm/helm/issues/30873 // TODO: document that Helm 4 `registry login` does accept repositories -func stripRepository(host string) string { +func (c *Client) stripRepository(host string) string { if idx := strings.Index(host, "/"); idx != -1 { host = host[:idx] - fmt.Printf("WARNING: Invalid registry passed: registries must NOT include a repository. Use %q instead\n", host) + fmt.Fprintf(c.out, "WARNING: Invalid registry passed: registries must NOT include a repository. Use %q instead\n", host) return host } return host @@ -244,7 +244,7 @@ func stripRepository(host string) string { // Login logs into a registry func (c *Client) Login(host string, options ...LoginOption) error { // This is the lowest available point to strip the repository - host = stripRepository(host) + host = c.stripRepository(host) for _, option := range options { option(&loginOperation{host, c}) diff --git a/pkg/registry/client_test.go b/pkg/registry/client_test.go index 5765134ba..e97308b3c 100644 --- a/pkg/registry/client_test.go +++ b/pkg/registry/client_test.go @@ -17,6 +17,7 @@ limitations under the License. package registry import ( + "io" "testing" "github.com/containerd/containerd/remotes" @@ -33,7 +34,11 @@ func TestNewClientResolverNotSupported(t *testing.T) { } func TestStripRepository(t *testing.T) { - assert.Equal(t, "127.0.0.1:15000", stripRepository("127.0.0.1:15000/asdf")) - assert.Equal(t, "127.0.0.1:15000", stripRepository("127.0.0.1:15000/asdf/asdf")) - assert.Equal(t, "127.0.0.1:15000", stripRepository("127.0.0.1:15000")) + client := &Client{ + out: io.Discard, + } + + assert.Equal(t, "127.0.0.1:15000", client.stripRepository("127.0.0.1:15000/asdf")) + assert.Equal(t, "127.0.0.1:15000", client.stripRepository("127.0.0.1:15000/asdf/asdf")) + assert.Equal(t, "127.0.0.1:15000", client.stripRepository("127.0.0.1:15000")) }