From c52430554a49349fab1be8609df067d5afc8977c Mon Sep 17 00:00:00 2001 From: sneak Date: Fri, 20 Jun 2025 08:24:54 -0700 Subject: [PATCH] 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 --- internal/cli/integration_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/cli/integration_test.go b/internal/cli/integration_test.go index c1a4144..8abe250 100644 --- a/internal/cli/integration_test.go +++ b/internal/cli/integration_test.go @@ -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)