Fix all usetesting linter errors

- Replace os.MkdirTemp() with t.TempDir() in test files
- Replace os.Setenv() with t.Setenv() in test files
- Remove manual environment cleanup code (t.Setenv automatically restores)
- Remove unused "os" imports from files that no longer use os package
This commit is contained in:
2025-06-20 08:18:38 -07:00
parent fd7ab06fb1
commit ecaa5e101b
11 changed files with 34 additions and 163 deletions

View File

@@ -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) {

View File

@@ -1,7 +1,6 @@
package vault
import (
"os"
"path/filepath"
"testing"
@@ -11,29 +10,10 @@ 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)
}
}()
// 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()