From 026981e724ba59e67a7cbfae0b1dcc8b6e48e985 Mon Sep 17 00:00:00 2001 From: kimsm28 Date: Mon, 13 Apr 2026 13:15:49 +0900 Subject: [PATCH] fix registry test failures by adjusting DockerRegistryHost and auth server listener management - Change DockerRegistryHost to use 127.0.0.1 for HTTP tests and helm-test-registry for TLS tests to match certificate hostname - Add defer ln.Close() to prevent resource leak in token auth server setup - Restore requestURL variable and assertion in test body instead of handler to avoid potential race condition Signed-off-by: kimsm28 --- pkg/registry/client_scope_test.go | 3 --- pkg/registry/registry_test.go | 12 ++++++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/registry/client_scope_test.go b/pkg/registry/client_scope_test.go index f0dec311f..3bde58a1d 100644 --- a/pkg/registry/client_scope_test.go +++ b/pkg/registry/client_scope_test.go @@ -44,7 +44,6 @@ func (suite *RegistryScopeTestSuite) TearDownSuite() { func (suite *RegistryScopeTestSuite) Test_1_Check_Push_Request_Scope() { var requestURL string - handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { requestURL = r.URL.String() w.WriteHeader(http.StatusOK) @@ -69,13 +68,11 @@ func (suite *RegistryScopeTestSuite) Test_1_Check_Push_Request_Scope() { //check the url that authentication server received suite.Equal("/auth?scope=repository%3Atestrepo%2Flocal-subchart%3Apull%2Cpush&service=testservice", requestURL) - } func (suite *RegistryScopeTestSuite) Test_2_Check_Pull_Request_Scope() { var requestURL string - handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { requestURL = r.URL.String() w.WriteHeader(http.StatusOK) diff --git a/pkg/registry/registry_test.go b/pkg/registry/registry_test.go index b492e3641..1111ac621 100644 --- a/pkg/registry/registry_test.go +++ b/pkg/registry/registry_test.go @@ -130,11 +130,14 @@ func setup(suite *TestRegistry, tlsEnabled, insecure bool, auth string) { suite.Nil(err, "no error finding free port for test registry") defer ln.Close() - // Change the registry host to another host which is not localhost. - // This is required because Docker enforces HTTP if the registry - // host is localhost/127.0.0.1. + // Use localhost for HTTP tests and helm-test-registry for TLS tests. + // TLS tests need a different hostname to match the certificate. port := ln.Addr().(*net.TCPAddr).Port - suite.DockerRegistryHost = fmt.Sprintf("helm-test-registry:%d", port) + if tlsEnabled { + suite.DockerRegistryHost = fmt.Sprintf("helm-test-registry:%d", port) + } else { + suite.DockerRegistryHost = fmt.Sprintf("127.0.0.1:%d", port) + } config.HTTP.Addr = ln.Addr().String() config.HTTP.DrainTimeout = time.Duration(10) * time.Second @@ -143,6 +146,7 @@ func setup(suite *TestRegistry, tlsEnabled, insecure bool, auth string) { if auth == "token" { ln, err := net.Listen("tcp", "127.0.0.1:0") suite.Nil(err, "no error finding free port for test auth server") + defer ln.Close() //set test auth server host suite.AuthServerHost = ln.Addr().String()