fix: replace remaining os.Setenv with t.Setenv in tests

Replace all os.Setenv calls with t.Setenv in test functions to ensure
proper test environment cleanup and better test isolation. This leaves
only legitimate application code and helper functions using os.Setenv.
This commit is contained in:
2025-06-20 09:22:01 -07:00
parent c6935d8f0f
commit c450e1c13d
4 changed files with 9 additions and 80 deletions
+2 -12
View File
@@ -131,18 +131,8 @@ func TestPassphraseUnlockerWithRealFS(t *testing.T) {
}
})
// Save original environment variables and set test ones
oldPassphrase := os.Getenv(secret.EnvUnlockPassphrase)
os.Setenv(secret.EnvUnlockPassphrase, testPassphrase)
// Clean up after test
defer func() {
if oldPassphrase != "" {
os.Setenv(secret.EnvUnlockPassphrase, oldPassphrase)
} else {
os.Unsetenv(secret.EnvUnlockPassphrase)
}
}()
// Set test environment variable (cleaned up automatically)
t.Setenv(secret.EnvUnlockPassphrase, testPassphrase)
// Test getting identity from environment variable
t.Run("GetIdentityFromEnv", func(t *testing.T) {