Skip to content

Commit ff439ea

Browse files
refactor: use t.Setenv instead of os.Setenv in tests
This PR refactors the test suite to use the testing framework’s Setenv helper instead of direct os.Setenv calls. By leveraging Setenv on *testing.T or *testing.M, we ensure automatic cleanup of environment variables and streamline error handling. - Use `t.Setenv` and friends instead of `os.Setenv` for test file(s): The original code manually invoked os.Setenv and exited on error, risking persistent side effects and boilerplate error handling. The patch replaces this with a call to m.Setenv (the *testing.M helper), which automatically restores the previous environment value after the test run and fails the test on setup errors, improving test isolation and readability. > This Autofix was generated by AI. Please review the change before merging.
1 parent da43d0b commit ff439ea

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

internal/main_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ func TestMain(m *testing.M) {
2222
os.Exit(1)
2323
}
2424

25-
if err := os.Setenv("HOME", dir); err != nil {
26-
os.Exit(1)
27-
}
25+
m.Setenv("HOME", dir)
2826

2927
// Override spinnerFunc with a mock to prevent data races from async goroutines
3028
spinnerFunc = func(_ string) (spinner, error) {

0 commit comments

Comments
 (0)