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.
func TestSecretManagerIntegration(t *testing.T) {
// Enable debug logging to diagnose issues
os.Setenv("GODEBUG", "berlin.sneak.pkg.secret")
defer os.Unsetenv("GODEBUG")
t.Setenv("GODEBUG", "berlin.sneak.pkg.secret")
// Reinitialize debug logging to pick up the environment variable change
secret.InitDebugLogging()
@ -66,8 +65,7 @@ func TestSecretManagerIntegration(t *testing.T) {
tempDir := t.TempDir()
// Set environment variables for the test
os.Setenv("SB_SECRET_STATE_DIR", tempDir)
defer os.Unsetenv("SB_SECRET_STATE_DIR")
t.Setenv("SB_SECRET_STATE_DIR", tempDir)
// Find the secret binary path (needed for tests that still use exec.Command)
wd, err := os.Getwd()
@ -1570,7 +1568,7 @@ func test23ErrorHandling(t *testing.T, tempDir, secretPath, testMnemonic string,
cmdOutput, err = cmd.CombinedOutput()
assert.Error(t, err, "get without mnemonic should fail")
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)