@@ -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
3033func 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