Skip to content

Commit 3432ef8

Browse files
authored
remove env isolator (#1035)
1 parent 4deab5f commit 3432ef8

File tree

7 files changed

+12
-116
lines changed

7 files changed

+12
-116
lines changed

api/v1/models_language_test.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/stackrox/scanner/cpe/nvdtoolscache"
1212
"github.com/stackrox/scanner/database"
1313
"github.com/stackrox/scanner/pkg/component"
14-
"github.com/stackrox/scanner/pkg/testutils"
1514
"github.com/stretchr/testify/assert"
1615
"github.com/stretchr/testify/require"
1716
)
@@ -117,12 +116,9 @@ func TestShouldDedupeLanguageFeature(t *testing.T) {
117116
}
118117

119118
func TestLatestLanguageFeatureVersion(t *testing.T) {
120-
envIsolator := testutils.NewEnvIsolator(t)
121-
defer envIsolator.RestoreAll()
122-
123119
_, filename, _, _ := runtime.Caller(0)
124120
defsDir := filepath.Join(filepath.Dir(filename), "/testdata")
125-
envIsolator.Setenv("NVD_DEFINITIONS_DIR", defsDir)
121+
t.Setenv("NVD_DEFINITIONS_DIR", defsDir)
126122

127123
prevBoltPath := nvdtoolscache.BoltPath
128124
defer func() {
@@ -160,12 +156,9 @@ func TestLatestLanguageFeatureVersion(t *testing.T) {
160156
}
161157

162158
func TestAddLanguageVulns(t *testing.T) {
163-
envIsolator := testutils.NewEnvIsolator(t)
164-
defer envIsolator.RestoreAll()
165-
166159
_, filename, _, _ := runtime.Caller(0)
167160
defsDir := filepath.Join(filepath.Dir(filename), "/testdata")
168-
envIsolator.Setenv("NVD_DEFINITIONS_DIR", defsDir)
161+
t.Setenv("NVD_DEFINITIONS_DIR", defsDir)
169162

170163
prevBoltPath := nvdtoolscache.BoltPath
171164
defer func() {
@@ -229,12 +222,9 @@ func TestGetLanguageComponents(t *testing.T) {
229222
// This should have similar results as TestAddLanguageVulns.
230223
// The component duplicates are not filtered, and vulnerabilities are not included.
231224

232-
envIsolator := testutils.NewEnvIsolator(t)
233-
defer envIsolator.RestoreAll()
234-
235225
_, filename, _, _ := runtime.Caller(0)
236226
defsDir := filepath.Join(filepath.Dir(filename), "/testdata")
237-
envIsolator.Setenv("NVD_DEFINITIONS_DIR", defsDir)
227+
t.Setenv("NVD_DEFINITIONS_DIR", defsDir)
238228

239229
prevBoltPath := nvdtoolscache.BoltPath
240230
defer func() {
@@ -289,12 +279,9 @@ func TestGetLanguageComponents(t *testing.T) {
289279
func TestGetLanguageFeatures(t *testing.T) {
290280
// This should give the same results as TestAddLanguageVulns.
291281

292-
envIsolator := testutils.NewEnvIsolator(t)
293-
defer envIsolator.RestoreAll()
294-
295282
_, filename, _, _ := runtime.Caller(0)
296283
defsDir := filepath.Join(filepath.Dir(filename), "/testdata")
297-
envIsolator.Setenv("NVD_DEFINITIONS_DIR", defsDir)
284+
t.Setenv("NVD_DEFINITIONS_DIR", defsDir)
298285

299286
prevBoltPath := nvdtoolscache.BoltPath
300287
defer func() {

api/v1/models_rhelv2_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
v1 "github.com/stackrox/scanner/generated/scanner/api/v1"
1212
"github.com/stackrox/scanner/pkg/archop"
1313
"github.com/stackrox/scanner/pkg/env"
14-
"github.com/stackrox/scanner/pkg/testutils"
1514
"github.com/stackrox/scanner/pkg/types"
1615
"github.com/stretchr/testify/assert"
1716
)
@@ -53,9 +52,7 @@ func newMockRHELv2Datastore() *mockRHELv2Datastore {
5352
}
5453

5554
func TestLayerFromDatabaseModelRHELv2(t *testing.T) {
56-
envIsolator := testutils.NewEnvIsolator(t)
57-
defer envIsolator.RestoreAll()
58-
envIsolator.Setenv(env.LanguageVulns.EnvVar(), "false")
55+
t.Setenv(env.LanguageVulns.EnvVar(), "false")
5956

6057
now := time.Now()
6158
db := newMockRHELv2Datastore()
@@ -220,9 +217,7 @@ func TestLayerFromDatabaseModelRHELv2(t *testing.T) {
220217
}
221218

222219
func TestComponentsFromDatabaseModelRHELv2(t *testing.T) {
223-
envIsolator := testutils.NewEnvIsolator(t)
224-
defer envIsolator.RestoreAll()
225-
envIsolator.Setenv(env.LanguageVulns.EnvVar(), "false")
220+
t.Setenv(env.LanguageVulns.EnvVar(), "false")
226221

227222
db := newMockRHELv2Datastore()
228223
db.layers["layer1"] = []*database.RHELv2Layer{

api/v1/models_test.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
v1 "github.com/stackrox/scanner/generated/scanner/api/v1"
99
"github.com/stackrox/scanner/pkg/component"
1010
"github.com/stackrox/scanner/pkg/env"
11-
"github.com/stackrox/scanner/pkg/testutils"
1211
"github.com/stretchr/testify/assert"
1312

1413
// Register the CPE validators.
@@ -20,9 +19,7 @@ import (
2019
)
2120

2221
func TestLatestUbuntuFeatureVersion(t *testing.T) {
23-
envIsolator := testutils.NewEnvIsolator(t)
24-
envIsolator.Setenv(env.LanguageVulns.EnvVar(), "false")
25-
defer envIsolator.RestoreAll()
22+
t.Setenv(env.LanguageVulns.EnvVar(), "false")
2623

2724
providedExecs := map[string]set.StringSet{"/exec/me": {}, "/pls/exec/me": {}}
2825
expectedExecs := make([]*v1.Executable, 0, len(providedExecs))
@@ -80,9 +77,7 @@ func TestLatestUbuntuFeatureVersion(t *testing.T) {
8077
}
8178

8279
func TestLatestCentOSFeatureVersion(t *testing.T) {
83-
envIsolator := testutils.NewEnvIsolator(t)
84-
envIsolator.Setenv(env.LanguageVulns.EnvVar(), "false")
85-
defer envIsolator.RestoreAll()
80+
t.Setenv(env.LanguageVulns.EnvVar(), "false")
8681

8782
providedExecs := map[string]set.StringSet{"/exec/me": {}, "/pls/exec/me": {}}
8883
expectedExecs := make([]*v1.Executable, 0, len(providedExecs))
@@ -152,9 +147,7 @@ func TestLatestCentOSFeatureVersion(t *testing.T) {
152147
}
153148

154149
func TestNotesNoLanguageVulns(t *testing.T) {
155-
envIsolator := testutils.NewEnvIsolator(t)
156-
envIsolator.Setenv(env.LanguageVulns.EnvVar(), "false")
157-
defer envIsolator.RestoreAll()
150+
t.Setenv(env.LanguageVulns.EnvVar(), "false")
158151

159152
dbLayer := database.Layer{
160153
Name: "example",

pkg/repo2cpe/mapping_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@ import (
55
"runtime"
66
"testing"
77

8-
"github.com/stackrox/scanner/pkg/testutils"
98
"github.com/stretchr/testify/assert"
109
)
1110

1211
func TestMapping(t *testing.T) {
13-
envIsolator := testutils.NewEnvIsolator(t)
14-
defer envIsolator.RestoreAll()
15-
1612
_, filename, _, _ := runtime.Caller(0)
1713
cpesDir := filepath.Join(filepath.Dir(filename), "/testdata")
18-
envIsolator.Setenv("REPO_TO_CPE_DIR", cpesDir)
14+
t.Setenv("REPO_TO_CPE_DIR", cpesDir)
1915

2016
repos := []string{
2117
"3scale-amp-2-rpms-for-rhel-8-x86_64-debug-rpms",

pkg/rhelv2/rpm/bench_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/stackrox/scanner/pkg/analyzer"
1010
"github.com/stackrox/scanner/pkg/tarutil"
11-
"github.com/stackrox/scanner/pkg/testutils"
1211
"github.com/stretchr/testify/require"
1312
)
1413

@@ -20,10 +19,8 @@ func BenchmarkListFeatures(b *testing.B) {
2019
manifest, err := os.ReadFile(filepath.Join(filepath.Dir(filename), "/testdata/test.json"))
2120
require.NoError(b, err)
2221

23-
envIsolator := testutils.NewEnvIsolator(b)
2422
cpesDir := filepath.Join(filepath.Dir(filename), "/testdata")
25-
envIsolator.Setenv("REPO_TO_CPE_DIR", cpesDir)
26-
defer envIsolator.RestoreAll()
23+
b.Setenv("REPO_TO_CPE_DIR", cpesDir)
2724

2825
filemap := tarutil.CreateNewLayerFiles(map[string]analyzer.FileData{
2926
"var/lib/rpm/Packages": {Contents: d},

pkg/rhelv2/rpm/rpm_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/stackrox/scanner/pkg/analyzer"
1212
"github.com/stackrox/scanner/pkg/features"
1313
"github.com/stackrox/scanner/pkg/tarutil"
14-
"github.com/stackrox/scanner/pkg/testutils"
1514
"github.com/stretchr/testify/assert"
1615
"github.com/stretchr/testify/require"
1716
)
@@ -277,9 +276,7 @@ func Test_listFeatures(t *testing.T) {
277276

278277
// Run test.
279278
t.Run(tt.name, func(t *testing.T) {
280-
envIsolator := testutils.NewEnvIsolator(t)
281-
defer envIsolator.RestoreAll()
282-
envIsolator.Setenv("REPO_TO_CPE_DIR", filepath.Join(testDirectory, "/testdata"))
279+
t.Setenv("REPO_TO_CPE_DIR", filepath.Join(testDirectory, "/testdata"))
283280
tt.args.layerFiles = tarutil.CreateNewLayerFiles(tt.files)
284281

285282
// Functions call.

pkg/testutils/env_isolator.go

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)