Tests: use t.Setenv to set env vars (#69516)

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
2023-06-05 17:31:03 +08:00
committed by GitHub
parent 4c794fe8b9
commit cf1945d0c3
13 changed files with 35 additions and 98 deletions

View File

@ -14,8 +14,7 @@ import (
func TestExpandVar_EnvSuccessful(t *testing.T) {
const key = "GF_TEST_SETTING_EXPANDER_ENV"
const expected = "aurora borealis"
err := os.Setenv(key, expected)
require.NoError(t, err)
t.Setenv(key, expected)
// expanded format
{