diff --git a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_auth_test.go b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_auth_test.go index 6e11673768..03e8606e5d 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_auth_test.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_auth_test.go @@ -16,10 +16,13 @@ func writeStaticConfig(t *testing.T, configContent string) string { t.Fatalf("Failed to create temp directory: %v", err) } - configPath := tmpDir + "/config.json" - err = os.WriteFile(configPath, []byte(configContent), 0600) - if err != nil { - t.Fatalf("Failed to write config.json: %v", err) + // only set auth if content is empty + if configContent != "" { + configPath := tmpDir + "/config.json" + err = os.WriteFile(configPath, []byte(configContent), 0600) + if err != nil { + t.Fatalf("Failed to write config.json: %v", err) + } } // Set the DOCKER_CONFIG environment variable to the temp directory @@ -28,6 +31,9 @@ func writeStaticConfig(t *testing.T, configContent string) string { } func TestGetAuthWithNoAuthSetReturnsNilAndNoError(t *testing.T) { + // update docker config env var + tmpDir := writeStaticConfig(t, "") + defer os.RemoveAll(tmpDir) authConfig, err := GetAuthFromDockerConfig("my-repo/my-image:latest") assert.NoError(t, err) assert.Nil(t, authConfig, "Auth config should be nil")