Replace os.Setenv with testing.T.Setenv in tests

T.Setenv ensures that the environment is returned to its prior state
when the test ends. It also panics when called from a parallel test to
prevent racy test interdependencies.
This commit is contained in:
Chris Bandy 2023-06-05 21:03:21 -05:00
parent c07c739f04
commit ac5ce5cbce

View File

@ -149,7 +149,7 @@ func TestToleratingMissingFiles(t *testing.T) {
func TestWarningMissingFiles(t *testing.T) {
envVarValue := "bogus"
os.Setenv(RecommendedConfigPathEnvVar, envVarValue)
t.Setenv(RecommendedConfigPathEnvVar, envVarValue)
loadingRules := NewDefaultClientConfigLoadingRules()
buffer := &bytes.Buffer{}
@ -174,7 +174,7 @@ func TestWarningMissingFiles(t *testing.T) {
func TestNoWarningMissingFiles(t *testing.T) {
envVarValue := "bogus"
os.Setenv(RecommendedConfigPathEnvVar, envVarValue)
t.Setenv(RecommendedConfigPathEnvVar, envVarValue)
loadingRules := NewDefaultClientConfigLoadingRules()
buffer := &bytes.Buffer{}