Fix remaining usetesting errors in vault integration test

Replace os.MkdirTemp() with t.TempDir() and os.Setenv() with t.Setenv()
Remove manual environment cleanup as t.Setenv handles it automatically
This commit is contained in:
Jeffrey Paul 2025-06-20 08:58:29 -07:00
parent 47afe117f4
commit 9e74b34b5d

View File

@ -13,11 +13,7 @@ import (
func TestVaultWithRealFilesystem(t *testing.T) { func TestVaultWithRealFilesystem(t *testing.T) {
// Create a temporary directory for our tests // Create a temporary directory for our tests
tempDir, err := os.MkdirTemp("", "secret-test-") tempDir := t.TempDir()
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
defer os.RemoveAll(tempDir) // Clean up after test
// Use the real filesystem // Use the real filesystem
fs := afero.NewOsFs() fs := afero.NewOsFs()
@ -25,28 +21,9 @@ func TestVaultWithRealFilesystem(t *testing.T) {
// Test mnemonic // Test mnemonic
testMnemonic := "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about" testMnemonic := "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
// Save original environment variables
oldMnemonic := os.Getenv(secret.EnvMnemonic)
oldPassphrase := os.Getenv(secret.EnvUnlockPassphrase)
// Set test environment variables // Set test environment variables
os.Setenv(secret.EnvMnemonic, testMnemonic) t.Setenv(secret.EnvMnemonic, testMnemonic)
os.Setenv(secret.EnvUnlockPassphrase, "test-passphrase") t.Setenv(secret.EnvUnlockPassphrase, "test-passphrase")
// 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 symlink handling // Test symlink handling
t.Run("SymlinkHandling", func(t *testing.T) { t.Run("SymlinkHandling", func(t *testing.T) {