Skip to content

Commit

Permalink
don't write empty auth config
Browse files Browse the repository at this point in the history
  • Loading branch information
tedim52 committed Jan 14, 2025
1 parent 0819b8c commit 3e8f0a5
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down

0 comments on commit 3e8f0a5

Please sign in to comment.