Skip to content

Commit 3e8f0a5

Browse files
committed
don't write empty auth config
1 parent 0819b8c commit 3e8f0a5

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

container-engine-lib/lib/backend_impls/docker/docker_manager/docker_auth_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ func writeStaticConfig(t *testing.T, configContent string) string {
1616
t.Fatalf("Failed to create temp directory: %v", err)
1717
}
1818

19-
configPath := tmpDir + "/config.json"
20-
err = os.WriteFile(configPath, []byte(configContent), 0600)
21-
if err != nil {
22-
t.Fatalf("Failed to write config.json: %v", err)
19+
// only set auth if content is empty
20+
if configContent != "" {
21+
configPath := tmpDir + "/config.json"
22+
err = os.WriteFile(configPath, []byte(configContent), 0600)
23+
if err != nil {
24+
t.Fatalf("Failed to write config.json: %v", err)
25+
}
2326
}
2427

2528
// Set the DOCKER_CONFIG environment variable to the temp directory
@@ -28,6 +31,9 @@ func writeStaticConfig(t *testing.T, configContent string) string {
2831
}
2932

3033
func TestGetAuthWithNoAuthSetReturnsNilAndNoError(t *testing.T) {
34+
// update docker config env var
35+
tmpDir := writeStaticConfig(t, "")
36+
defer os.RemoveAll(tmpDir)
3137
authConfig, err := GetAuthFromDockerConfig("my-repo/my-image:latest")
3238
assert.NoError(t, err)
3339
assert.Nil(t, authConfig, "Auth config should be nil")

0 commit comments

Comments
 (0)