Skip to content

Commit 2d59a39

Browse files
committed
Use t.Setenv instead of os.Setenv
Signed-off-by: Maksym Pavlenko <[email protected]>
1 parent 887615c commit 2d59a39

3 files changed

Lines changed: 5 additions & 13 deletions

File tree

archive/compression/compression_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,15 @@ func TestDetectPigz(t *testing.T) {
135135
t.Fatal(err)
136136
}
137137

138-
oldPath := os.Getenv("PATH")
139-
os.Setenv("PATH", tempPath)
140-
defer os.Setenv("PATH", oldPath)
138+
t.Setenv("PATH", tempPath)
141139

142140
if pigzPath := detectPigz(); pigzPath == "" {
143141
t.Fatal("failed to detect pigz path")
144142
} else if pigzPath != fullPath {
145143
t.Fatalf("wrong pigz found: %s != %s", pigzPath, fullPath)
146144
}
147145

148-
os.Setenv(disablePigzEnv, "1")
149-
defer os.Unsetenv(disablePigzEnv)
146+
t.Setenv(disablePigzEnv, "1")
150147

151148
if pigzPath := detectPigz(); pigzPath != "" {
152149
t.Fatalf("disable via %s doesn't work", disablePigzEnv)

namespaces/context_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package namespaces
1818

1919
import (
2020
"context"
21-
"os"
2221
"testing"
2322
)
2423

@@ -47,9 +46,6 @@ func TestContext(t *testing.T) {
4746
}
4847

4948
func TestNamespaceFromEnv(t *testing.T) {
50-
oldenv := os.Getenv(NamespaceEnvVar)
51-
defer os.Setenv(NamespaceEnvVar, oldenv) // restore old env var
52-
5349
ctx := context.Background()
5450
namespace, ok := Namespace(ctx)
5551
if ok {
@@ -61,7 +57,7 @@ func TestNamespaceFromEnv(t *testing.T) {
6157
}
6258

6359
expected := "test-namespace"
64-
os.Setenv(NamespaceEnvVar, expected)
60+
t.Setenv(NamespaceEnvVar, expected)
6561
nctx := NamespaceFromEnv(ctx)
6662

6763
namespace, ok = Namespace(nctx)

runtime/v2/shim/shim_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package shim
1818

1919
import (
2020
"context"
21-
"os"
2221
"runtime"
2322
"testing"
2423
)
@@ -27,7 +26,7 @@ func TestRuntimeWithEmptyMaxEnvProcs(t *testing.T) {
2726
var oldGoMaxProcs = runtime.GOMAXPROCS(0)
2827
defer runtime.GOMAXPROCS(oldGoMaxProcs)
2928

30-
os.Setenv("GOMAXPROCS", "")
29+
t.Setenv("GOMAXPROCS", "")
3130
setRuntime()
3231

3332
var currentGoMaxProcs = runtime.GOMAXPROCS(0)
@@ -37,7 +36,7 @@ func TestRuntimeWithEmptyMaxEnvProcs(t *testing.T) {
3736
}
3837

3938
func TestRuntimeWithNonEmptyMaxEnvProcs(t *testing.T) {
40-
os.Setenv("GOMAXPROCS", "not_empty")
39+
t.Setenv("GOMAXPROCS", "not_empty")
4140
setRuntime()
4241
var oldGoMaxProcs2 = runtime.GOMAXPROCS(0)
4342
if oldGoMaxProcs2 != runtime.NumCPU() {

0 commit comments

Comments
 (0)