Skip to content

remove env isolator #1035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions api/v1/models_language_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/stackrox/scanner/cpe/nvdtoolscache"
"github.com/stackrox/scanner/database"
"github.com/stackrox/scanner/pkg/component"
"github.com/stackrox/scanner/pkg/testutils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -117,12 +116,9 @@ func TestShouldDedupeLanguageFeature(t *testing.T) {
}

func TestLatestLanguageFeatureVersion(t *testing.T) {
envIsolator := testutils.NewEnvIsolator(t)
defer envIsolator.RestoreAll()

_, filename, _, _ := runtime.Caller(0)
defsDir := filepath.Join(filepath.Dir(filename), "/testdata")
envIsolator.Setenv("NVD_DEFINITIONS_DIR", defsDir)
t.Setenv("NVD_DEFINITIONS_DIR", defsDir)

prevBoltPath := nvdtoolscache.BoltPath
defer func() {
Expand Down Expand Up @@ -160,12 +156,9 @@ func TestLatestLanguageFeatureVersion(t *testing.T) {
}

func TestAddLanguageVulns(t *testing.T) {
envIsolator := testutils.NewEnvIsolator(t)
defer envIsolator.RestoreAll()

_, filename, _, _ := runtime.Caller(0)
defsDir := filepath.Join(filepath.Dir(filename), "/testdata")
envIsolator.Setenv("NVD_DEFINITIONS_DIR", defsDir)
t.Setenv("NVD_DEFINITIONS_DIR", defsDir)

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

envIsolator := testutils.NewEnvIsolator(t)
defer envIsolator.RestoreAll()

_, filename, _, _ := runtime.Caller(0)
defsDir := filepath.Join(filepath.Dir(filename), "/testdata")
envIsolator.Setenv("NVD_DEFINITIONS_DIR", defsDir)
t.Setenv("NVD_DEFINITIONS_DIR", defsDir)

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

envIsolator := testutils.NewEnvIsolator(t)
defer envIsolator.RestoreAll()

_, filename, _, _ := runtime.Caller(0)
defsDir := filepath.Join(filepath.Dir(filename), "/testdata")
envIsolator.Setenv("NVD_DEFINITIONS_DIR", defsDir)
t.Setenv("NVD_DEFINITIONS_DIR", defsDir)

prevBoltPath := nvdtoolscache.BoltPath
defer func() {
Expand Down
9 changes: 2 additions & 7 deletions api/v1/models_rhelv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
v1 "github.com/stackrox/scanner/generated/scanner/api/v1"
"github.com/stackrox/scanner/pkg/archop"
"github.com/stackrox/scanner/pkg/env"
"github.com/stackrox/scanner/pkg/testutils"
"github.com/stackrox/scanner/pkg/types"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -53,9 +52,7 @@ func newMockRHELv2Datastore() *mockRHELv2Datastore {
}

func TestLayerFromDatabaseModelRHELv2(t *testing.T) {
envIsolator := testutils.NewEnvIsolator(t)
defer envIsolator.RestoreAll()
envIsolator.Setenv(env.LanguageVulns.EnvVar(), "false")
t.Setenv(env.LanguageVulns.EnvVar(), "false")

now := time.Now()
db := newMockRHELv2Datastore()
Expand Down Expand Up @@ -220,9 +217,7 @@ func TestLayerFromDatabaseModelRHELv2(t *testing.T) {
}

func TestComponentsFromDatabaseModelRHELv2(t *testing.T) {
envIsolator := testutils.NewEnvIsolator(t)
defer envIsolator.RestoreAll()
envIsolator.Setenv(env.LanguageVulns.EnvVar(), "false")
t.Setenv(env.LanguageVulns.EnvVar(), "false")

db := newMockRHELv2Datastore()
db.layers["layer1"] = []*database.RHELv2Layer{
Expand Down
13 changes: 3 additions & 10 deletions api/v1/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
v1 "github.com/stackrox/scanner/generated/scanner/api/v1"
"github.com/stackrox/scanner/pkg/component"
"github.com/stackrox/scanner/pkg/env"
"github.com/stackrox/scanner/pkg/testutils"
"github.com/stretchr/testify/assert"

// Register the CPE validators.
Expand All @@ -20,9 +19,7 @@ import (
)

func TestLatestUbuntuFeatureVersion(t *testing.T) {
envIsolator := testutils.NewEnvIsolator(t)
envIsolator.Setenv(env.LanguageVulns.EnvVar(), "false")
defer envIsolator.RestoreAll()
t.Setenv(env.LanguageVulns.EnvVar(), "false")

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

func TestLatestCentOSFeatureVersion(t *testing.T) {
envIsolator := testutils.NewEnvIsolator(t)
envIsolator.Setenv(env.LanguageVulns.EnvVar(), "false")
defer envIsolator.RestoreAll()
t.Setenv(env.LanguageVulns.EnvVar(), "false")

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

func TestNotesNoLanguageVulns(t *testing.T) {
envIsolator := testutils.NewEnvIsolator(t)
envIsolator.Setenv(env.LanguageVulns.EnvVar(), "false")
defer envIsolator.RestoreAll()
t.Setenv(env.LanguageVulns.EnvVar(), "false")

dbLayer := database.Layer{
Name: "example",
Expand Down
6 changes: 1 addition & 5 deletions pkg/repo2cpe/mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ import (
"runtime"
"testing"

"github.com/stackrox/scanner/pkg/testutils"
"github.com/stretchr/testify/assert"
)

func TestMapping(t *testing.T) {
envIsolator := testutils.NewEnvIsolator(t)
defer envIsolator.RestoreAll()

_, filename, _, _ := runtime.Caller(0)
cpesDir := filepath.Join(filepath.Dir(filename), "/testdata")
envIsolator.Setenv("REPO_TO_CPE_DIR", cpesDir)
t.Setenv("REPO_TO_CPE_DIR", cpesDir)

repos := []string{
"3scale-amp-2-rpms-for-rhel-8-x86_64-debug-rpms",
Expand Down
5 changes: 1 addition & 4 deletions pkg/rhelv2/rpm/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/stackrox/scanner/pkg/analyzer"
"github.com/stackrox/scanner/pkg/tarutil"
"github.com/stackrox/scanner/pkg/testutils"
"github.com/stretchr/testify/require"
)

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

envIsolator := testutils.NewEnvIsolator(b)
cpesDir := filepath.Join(filepath.Dir(filename), "/testdata")
envIsolator.Setenv("REPO_TO_CPE_DIR", cpesDir)
defer envIsolator.RestoreAll()
b.Setenv("REPO_TO_CPE_DIR", cpesDir)

filemap := tarutil.CreateNewLayerFiles(map[string]analyzer.FileData{
"var/lib/rpm/Packages": {Contents: d},
Expand Down
5 changes: 1 addition & 4 deletions pkg/rhelv2/rpm/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/stackrox/scanner/pkg/analyzer"
"github.com/stackrox/scanner/pkg/features"
"github.com/stackrox/scanner/pkg/tarutil"
"github.com/stackrox/scanner/pkg/testutils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -277,9 +276,7 @@ func Test_listFeatures(t *testing.T) {

// Run test.
t.Run(tt.name, func(t *testing.T) {
envIsolator := testutils.NewEnvIsolator(t)
defer envIsolator.RestoreAll()
envIsolator.Setenv("REPO_TO_CPE_DIR", filepath.Join(testDirectory, "/testdata"))
t.Setenv("REPO_TO_CPE_DIR", filepath.Join(testDirectory, "/testdata"))
tt.args.layerFiles = tarutil.CreateNewLayerFiles(tt.files)

// Functions call.
Expand Down
69 changes: 0 additions & 69 deletions pkg/testutils/env_isolator.go

This file was deleted.