diff --git a/pkg/envinfo/envinfo_test.go b/pkg/envinfo/envinfo_test.go index 72cca7e68d9..191423f9dc7 100644 --- a/pkg/envinfo/envinfo_test.go +++ b/pkg/envinfo/envinfo_test.go @@ -17,7 +17,7 @@ func TestSetEnvInfo(t *testing.T) { t.Fatal(err) } defer tempEnvFile.Close() - os.Setenv(envInfoEnvName, tempEnvFile.Name()) + t.Setenv(envInfoEnvName, tempEnvFile.Name()) testDebugPort := 5005 invalidParam := "invalidParameter" @@ -85,7 +85,7 @@ func TestUnsetEnvInfo(t *testing.T) { t.Fatal(err) } defer tempEnvFile.Close() - os.Setenv(envInfoEnvName, tempEnvFile.Name()) + t.Setenv(envInfoEnvName, tempEnvFile.Name()) testDebugPort := 15005 invalidParam := "invalidParameter" diff --git a/pkg/odo/genericclioptions/context_test.go b/pkg/odo/genericclioptions/context_test.go index aa20447f12d..2c7a876831e 100644 --- a/pkg/odo/genericclioptions/context_test.go +++ b/pkg/odo/genericclioptions/context_test.go @@ -344,7 +344,7 @@ func TestNew(t *testing.T) { os.RemoveAll(prefixDir) // the second one to cleanup after execution defer os.RemoveAll(prefixDir) - os.Setenv("KUBECONFIG", filepath.Join(prefixDir, ".kube", "config")) + t.Setenv("KUBECONFIG", filepath.Join(prefixDir, ".kube", "config")) ctrl := gomock.NewController(t) defer ctrl.Finish() diff --git a/pkg/preference/implem_test.go b/pkg/preference/implem_test.go index 8a29b023451..e79586cab0b 100644 --- a/pkg/preference/implem_test.go +++ b/pkg/preference/implem_test.go @@ -19,7 +19,7 @@ func TestNew(t *testing.T) { t.Fatal(err) } defer tempConfigFile.Close() - os.Setenv(GlobalConfigEnvName, tempConfigFile.Name()) + t.Setenv(GlobalConfigEnvName, tempConfigFile.Name()) tests := []struct { name string @@ -77,7 +77,7 @@ func TestGetPushTimeout(t *testing.T) { t.Fatal(err) } defer tempConfigFile.Close() - os.Setenv(GlobalConfigEnvName, tempConfigFile.Name()) + t.Setenv(GlobalConfigEnvName, tempConfigFile.Name()) nonzeroValue := 5 * time.Second @@ -123,7 +123,7 @@ func TestGetTimeout(t *testing.T) { t.Fatal(err) } defer tempConfigFile.Close() - os.Setenv(GlobalConfigEnvName, tempConfigFile.Name()) + t.Setenv(GlobalConfigEnvName, tempConfigFile.Name()) zeroValue := 0 * time.Second nonzeroValue := 5 * time.Second tests := []struct { @@ -179,7 +179,7 @@ func TestSetConfiguration(t *testing.T) { t.Fatal(err) } defer tempConfigFile.Close() - os.Setenv(GlobalConfigEnvName, tempConfigFile.Name()) + t.Setenv(GlobalConfigEnvName, tempConfigFile.Name()) trueValue := true falseValue := false minValue := minimumDurationValue @@ -407,7 +407,7 @@ func TestConsentTelemetry(t *testing.T) { t.Fatal(err) } defer tempConfigFile.Close() - os.Setenv(GlobalConfigEnvName, tempConfigFile.Name()) + t.Setenv(GlobalConfigEnvName, tempConfigFile.Name()) trueValue := true falseValue := false @@ -463,7 +463,7 @@ func TestGetupdateNotification(t *testing.T) { t.Fatal(err) } defer tempConfigFile.Close() - os.Setenv(GlobalConfigEnvName, tempConfigFile.Name()) + t.Setenv(GlobalConfigEnvName, tempConfigFile.Name()) trueValue := true falseValue := false @@ -692,7 +692,7 @@ func TestGetConsentTelemetry(t *testing.T) { t.Fatal(err) } defer tempConfigFile.Close() - os.Setenv(GlobalConfigEnvName, tempConfigFile.Name()) + t.Setenv(GlobalConfigEnvName, tempConfigFile.Name()) trueValue := true falseValue := false diff --git a/pkg/registry/registry_test.go b/pkg/registry/registry_test.go index ada89098b08..077acc966ca 100644 --- a/pkg/registry/registry_test.go +++ b/pkg/registry/registry_test.go @@ -36,8 +36,7 @@ OdoSettings: t.Error(err) } - os.Setenv(preference.GlobalConfigEnvName, tempConfigFile.Name()) - defer os.Unsetenv(preference.GlobalConfigEnvName) + t.Setenv(preference.GlobalConfigEnvName, tempConfigFile.Name()) tests := []struct { name string diff --git a/pkg/registry/utils_test.go b/pkg/registry/utils_test.go index 1c9ade9f81d..0ea1cf02cac 100644 --- a/pkg/registry/utils_test.go +++ b/pkg/registry/utils_test.go @@ -2,7 +2,6 @@ package registry import ( "io/ioutil" - "os" "reflect" "testing" @@ -20,7 +19,7 @@ func TestIsSecure(t *testing.T) { t.Fatal(err) } defer tempConfigFile.Close() - os.Setenv(GlobalConfigEnvName, tempConfigFile.Name()) + t.Setenv(GlobalConfigEnvName, tempConfigFile.Name()) tests := []struct { name string diff --git a/pkg/segment/integrations_test.go b/pkg/segment/integrations_test.go index 2a2387d8a08..2cb7c736b00 100644 --- a/pkg/segment/integrations_test.go +++ b/pkg/segment/integrations_test.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "io/ioutil" - "os" "testing" "github.com/devfile/registry-support/registry-library/library" @@ -18,11 +17,7 @@ func TestGetRegistryOptions(t *testing.T) { } defer tempConfigFile.Close() - err = os.Setenv(preference.GlobalConfigEnvName, tempConfigFile.Name()) - - if err != nil { - t.Fatal(err) - } + t.Setenv(preference.GlobalConfigEnvName, tempConfigFile.Name()) tests := []struct { testName string diff --git a/pkg/segment/segment_test.go b/pkg/segment/segment_test.go index 5a1e9ac26c4..38ba5389c53 100644 --- a/pkg/segment/segment_test.go +++ b/pkg/segment/segment_test.go @@ -231,7 +231,7 @@ func TestIsTelemetryEnabled(t *testing.T) { }, } for _, tt := range tests { - os.Setenv(DisableTelemetryEnv, tt.envVar) + t.Setenv(DisableTelemetryEnv, tt.envVar) ctrl := gomock.NewController(t) cfg := preference.NewMockClient(ctrl) cfg.EXPECT().GetConsentTelemetry().Return(tt.preferenceValue).AnyTimes()