test(iostreams): isolate NO_COLOR in detectIsColorEnabled default case

Description

Special thanks to @mikelolasagasti who originally created the original MR !3148 (closed).

Apply Gary's suggestion from !3148 (closed) to simplify the env var cleanup pattern in the default subtest of Test_isColorEnabled.

The default subtest assumed no NO_COLOR in the process environment. Fedora's rpmbuild (and other CI) often sets NO_COLOR globally, which made detectIsColorEnabled() correctly return false and broke the test.

This change saves and restores NO_COLOR and COLOR_ENABLED around the subtest using os.LookupEnv + os.Unsetenv + t.Cleanup, so the test is isolated from the caller's environment without relying on t.Setenv (which sets the variable to a value but cannot unset it).

The cleanup uses os.Setenv inside t.Cleanup (not t.Setenv) to avoid the anti-pattern of calling a test helper during teardown. Error return values are not suppressed with _ = per Gary's suggestion.

Resolves #8272 (closed)

How has this been tested?

go test ./internal/iostreams/... -run Test_isColorEnabled -v passes.

Edited by Filip Aleksic

Merge request reports

Loading