fix: replace os.Setenv with t.Setenv in tests (usetesting)

Replace os.Setenv calls with t.Setenv in test functions to ensure
proper test environment cleanup and better test isolation.
This commit is contained in:
2025-06-20 09:13:01 -07:00
parent b736789ecb
commit 08a42b16dd
2 changed files with 9 additions and 47 deletions

View File

@@ -1,7 +1,6 @@
package vault
import (
"os"
"path/filepath"
"testing"
@@ -11,29 +10,12 @@ import (
)
func TestVaultOperations(t *testing.T) {
// Save original environment variables
oldMnemonic := os.Getenv(secret.EnvMnemonic)
oldPassphrase := os.Getenv(secret.EnvUnlockPassphrase)
// Clean up after test
defer func() {
if oldMnemonic != "" {
os.Setenv(secret.EnvMnemonic, oldMnemonic)
} else {
os.Unsetenv(secret.EnvMnemonic)
}
if oldPassphrase != "" {
os.Setenv(secret.EnvUnlockPassphrase, oldPassphrase)
} else {
os.Unsetenv(secret.EnvUnlockPassphrase)
}
}()
// Test environment will be cleaned up automatically by t.Setenv
// Set test environment variables
testMnemonic := "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
os.Setenv(secret.EnvMnemonic, testMnemonic)
os.Setenv(secret.EnvUnlockPassphrase, "test-passphrase")
t.Setenv(secret.EnvMnemonic, testMnemonic)
t.Setenv(secret.EnvUnlockPassphrase, "test-passphrase")
// Use in-memory filesystem
fs := afero.NewMemMapFs()