mirror of
https://github.com/ahmetb/kubectx.git
synced 2026-03-17 19:32:27 +00:00
refactor: replace testutil.WithEnvVar with t.Setenv (#479)
t.Setenv is the modern standard Go testing utility (since Go 1.17) that automatically restores environment variables when the test completes. This replaces the custom testutil.WithEnvVar function which manually saved and restored env var state. The testutil.go file is deleted as it only contained WithEnvVar. The testutil package remains for its other utilities like KubeconfigBuilder.
This commit is contained in:
@@ -18,8 +18,6 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/ahmetb/kubectx/internal/testutil"
|
||||
)
|
||||
|
||||
func TestNSFile(t *testing.T) {
|
||||
@@ -50,7 +48,7 @@ func TestNSFile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNSFile_path_windows(t *testing.T) {
|
||||
defer testutil.WithEnvVar("_FORCE_GOOS", "windows")()
|
||||
t.Setenv("_FORCE_GOOS", "windows")
|
||||
fp := NewNSFile("a:b:c").path()
|
||||
|
||||
if expected := "a__b__c"; !strings.HasSuffix(fp, expected) {
|
||||
@@ -68,7 +66,7 @@ func Test_isWindows(t *testing.T) {
|
||||
t.Fatalf("isWindows() returned true for %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
defer testutil.WithEnvVar("_FORCE_GOOS", "windows")()
|
||||
t.Setenv("_FORCE_GOOS", "windows")
|
||||
if !isWindows() {
|
||||
t.Fatalf("isWindows() failed to detect windows with env override.")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user