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:
@@ -3,7 +3,6 @@ package notifiers
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -70,7 +69,7 @@ func TestNotificationAsConfig(t *testing.T) {
|
||||
|
||||
t.Run("Can read correct properties", func(t *testing.T) {
|
||||
setup()
|
||||
_ = os.Setenv("TEST_VAR", "default")
|
||||
t.Setenv("TEST_VAR", "default")
|
||||
cfgProvider := &configReader{
|
||||
orgService: orgService,
|
||||
encryptionService: encryptionService,
|
||||
@@ -78,7 +77,6 @@ func TestNotificationAsConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
cfg, err := cfgProvider.readConfig(context.Background(), correctProperties)
|
||||
_ = os.Unsetenv("TEST_VAR")
|
||||
if err != nil {
|
||||
t.Fatalf("readConfig return an error %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user