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 <sm28.kim@samsung.com>
pull/31211/head
kimsm28 12 hours ago
parent b9232c7853
commit 026981e724

@ -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)

@ -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()

Loading…
Cancel
Save