From 9e74b34b5daa7891ea259a7d65540bf904663b77 Mon Sep 17 00:00:00 2001 From: sneak Date: Fri, 20 Jun 2025 08:58:29 -0700 Subject: [PATCH] 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 --- internal/vault/integration_test.go | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/internal/vault/integration_test.go b/internal/vault/integration_test.go index d33a415..393a88b 100644 --- a/internal/vault/integration_test.go +++ b/internal/vault/integration_test.go @@ -13,11 +13,7 @@ import ( func TestVaultWithRealFilesystem(t *testing.T) { // Create a temporary directory for our tests - tempDir, err := os.MkdirTemp("", "secret-test-") - if err != nil { - t.Fatalf("Failed to create temp dir: %v", err) - } - defer os.RemoveAll(tempDir) // Clean up after test + tempDir := t.TempDir() // Use the real filesystem fs := afero.NewOsFs() @@ -25,28 +21,9 @@ func TestVaultWithRealFilesystem(t *testing.T) { // Test mnemonic 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 - os.Setenv(secret.EnvMnemonic, testMnemonic) - os.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) - } - }() + t.Setenv(secret.EnvMnemonic, testMnemonic) + t.Setenv(secret.EnvUnlockPassphrase, "test-passphrase") // Test symlink handling t.Run("SymlinkHandling", func(t *testing.T) {