From 3ffcfabea203efd6fff7c80bb4590f2444e8d764 Mon Sep 17 00:00:00 2001 From: Chris Bandy Date: Mon, 5 Jun 2023 21:03:21 -0500 Subject: [PATCH] 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. Kubernetes-commit: ac5ce5cbce7ddb6ffeff755d1cf670afadb8e1fb --- tools/clientcmd/loader_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/clientcmd/loader_test.go b/tools/clientcmd/loader_test.go index 5458a9fb..fbc45283 100644 --- a/tools/clientcmd/loader_test.go +++ b/tools/clientcmd/loader_test.go @@ -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{}