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:
@@ -128,19 +128,9 @@ func TestPerSecretKeyFunctionality(t *testing.T) {
|
||||
// Create an in-memory filesystem for testing
|
||||
fs := afero.NewMemMapFs()
|
||||
|
||||
// Set up test environment variables
|
||||
oldMnemonic := os.Getenv(EnvMnemonic)
|
||||
defer func() {
|
||||
if oldMnemonic == "" {
|
||||
os.Unsetenv(EnvMnemonic)
|
||||
} else {
|
||||
os.Setenv(EnvMnemonic, oldMnemonic)
|
||||
}
|
||||
}()
|
||||
|
||||
// Set test mnemonic for direct encryption/decryption
|
||||
testMnemonic := "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
|
||||
os.Setenv(EnvMnemonic, testMnemonic)
|
||||
t.Setenv(EnvMnemonic, testMnemonic)
|
||||
|
||||
// Set up a test vault structure
|
||||
baseDir := "/test-config/berlin.sneak.pkg.secret"
|
||||
@@ -312,9 +302,7 @@ func TestSecretGetValueWithEnvMnemonicUsesVaultDerivationIndex(t *testing.T) {
|
||||
|
||||
// Set up test mnemonic
|
||||
testMnemonic := "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
|
||||
originalEnv := os.Getenv(EnvMnemonic)
|
||||
os.Setenv(EnvMnemonic, testMnemonic)
|
||||
defer os.Setenv(EnvMnemonic, originalEnv)
|
||||
t.Setenv(EnvMnemonic, testMnemonic)
|
||||
|
||||
// Create temporary directory for vaults
|
||||
fs := afero.NewOsFs()
|
||||
|
||||
Reference in New Issue
Block a user