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: 89467ad3e9b051515fa9632a7373d6ef01723256
This commit is contained in:
Chris Bandy
2023-04-15 10:09:47 -05:00
committed by Kubernetes Publisher
parent 383ccb06d0
commit 18ffb5c67f
3 changed files with 10 additions and 23 deletions

View File

@@ -897,12 +897,9 @@ func TestLoadingGetLoadingPrecedence(t *testing.T) {
},
}
kubeconfig := os.Getenv("KUBECONFIG")
defer os.Setenv("KUBECONFIG", kubeconfig)
for name, test := range testCases {
t.Run(name, func(t *testing.T) {
os.Setenv("KUBECONFIG", test.env)
t.Setenv("KUBECONFIG", test.env)
rules := test.rules
if rules == nil {
rules = NewDefaultClientConfigLoadingRules()