mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-19 05:45:56 +02:00
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:
@@ -2,7 +2,6 @@ package tmpl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
@@ -234,10 +233,7 @@ func Test_renderTemplateToString(t *testing.T) {
|
||||
tt := tests[i]
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
for k, v := range tt.args.envs {
|
||||
err := os.Setenv(k, v)
|
||||
if err != nil {
|
||||
t.Error("renderTemplateToString() could not set env var for testing")
|
||||
}
|
||||
t.Setenv(k, v)
|
||||
}
|
||||
got, err := renderTemplateToString(tt.args.s, tt.args.data)
|
||||
if (err != nil) != tt.wantErr {
|
||||
|
||||
Reference in New Issue
Block a user