@@ -12,12 +12,8 @@ import (
1212
1313func TestGetAndVerifyCredentialsFromEnv (t * testing.T ) {
1414 // Set environment variables for test
15- os .Setenv ("REGISTRY_USERNAME" , "user" )
16- os .Setenv ("REGISTRY_PASSWORD" , "pass" )
17- defer func () {
18- os .Unsetenv ("REGISTRY_USERNAME" )
19- os .Unsetenv ("REGISTRY_PASSWORD" )
20- }()
15+ t .Setenv ("REGISTRY_USERNAME" , "user" )
16+ t .Setenv ("REGISTRY_PASSWORD" , "pass" )
2117
2218 log := logger .New ()
2319 da := New (log )
@@ -87,22 +83,8 @@ func TestGetAndVerifyCredentialsNoCredentials(t *testing.T) {
8783 os .Unsetenv ("REGISTRY_USERNAME" )
8884 os .Unsetenv ("REGISTRY_PASSWORD" )
8985
90- // Remove docker config if it exists (temporarily)
91- homeDir , _ := os .UserHomeDir ()
92- dockerConfigPath := homeDir + "/.docker/config.json"
93- var backupConfig []byte
94- var configExisted bool
95-
96- if data , err := os .ReadFile (dockerConfigPath ); err == nil {
97- backupConfig = data
98- configExisted = true
99- os .Remove (dockerConfigPath )
100- }
101- defer func () {
102- if configExisted {
103- os .WriteFile (dockerConfigPath , backupConfig , 0644 )
104- }
105- }()
86+ // Use a temporary home directory to simulate missing credentials.
87+ t .Setenv ("HOME" , t .TempDir ())
10688
10789 log := logger .New ()
10890 da := New (log )
0 commit comments