test: use T.Setenv to set env vars in tests (#189)

This commit replaces `os.Setenv` with `t.Setenv` in tests. The
environment variable is automatically restored to its original value
when the test and all its subtests complete.

Reference: https://pkg.go.dev/testing#T.Setenv
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun
2022-06-30 09:15:34 +09:00
committed by GitHub
parent a5b7c2b08d
commit ce3b81e2a1
8 changed files with 20 additions and 52 deletions
+1 -3
View File
@@ -94,11 +94,9 @@ func TestGetTillerlessEnv(t *testing.T) {
hc := &HelmContext{
Tillerless: test.tillerless,
}
os.Setenv(kubeconfigEnv, test.kubeconfig)
t.Setenv(kubeconfigEnv, test.kubeconfig)
result := hc.getTillerlessEnv()
require.Equalf(t, test.expected, result, "expected result %s, received result %s", test.expected, result)
}
defer os.Unsetenv(kubeconfigEnv)
}