Fix usetesting errors in CLI integration test

Replace os.Setenv() with t.Setenv() for GODEBUG and SB_SECRET_STATE_DIR
environment variables in TestSecretManagerIntegration and test23ErrorHandling
This commit is contained in:
Jeffrey Paul 2025-06-20 08:24:54 -07:00
parent fd7ab06fb1
commit c52430554a

View File

@ -52,8 +52,7 @@ func TestMain(m *testing.M) {
// This test serves as both validation and documentation of the program's behavior. // This test serves as both validation and documentation of the program's behavior.
func TestSecretManagerIntegration(t *testing.T) { func TestSecretManagerIntegration(t *testing.T) {
// Enable debug logging to diagnose issues // Enable debug logging to diagnose issues
os.Setenv("GODEBUG", "berlin.sneak.pkg.secret") t.Setenv("GODEBUG", "berlin.sneak.pkg.secret")
defer os.Unsetenv("GODEBUG")
// Reinitialize debug logging to pick up the environment variable change // Reinitialize debug logging to pick up the environment variable change
secret.InitDebugLogging() secret.InitDebugLogging()
@ -66,8 +65,7 @@ func TestSecretManagerIntegration(t *testing.T) {
tempDir := t.TempDir() tempDir := t.TempDir()
// Set environment variables for the test // Set environment variables for the test
os.Setenv("SB_SECRET_STATE_DIR", tempDir) t.Setenv("SB_SECRET_STATE_DIR", tempDir)
defer os.Unsetenv("SB_SECRET_STATE_DIR")
// Find the secret binary path (needed for tests that still use exec.Command) // Find the secret binary path (needed for tests that still use exec.Command)
wd, err := os.Getwd() wd, err := os.Getwd()
@ -1570,7 +1568,7 @@ func test23ErrorHandling(t *testing.T, tempDir, secretPath, testMnemonic string,
cmdOutput, err = cmd.CombinedOutput() cmdOutput, err = cmd.CombinedOutput()
assert.Error(t, err, "get without mnemonic should fail") assert.Error(t, err, "get without mnemonic should fail")
assert.Contains(t, string(cmdOutput), "failed to unlock", "should indicate unlock failure") assert.Contains(t, string(cmdOutput), "failed to unlock", "should indicate unlock failure")
os.Setenv("SB_SECRET_MNEMONIC", unsetMnemonic) t.Setenv("SB_SECRET_MNEMONIC", unsetMnemonic)
// Invalid secret names (already tested in test 12) // Invalid secret names (already tested in test 12)