Skip to content

Commit

Permalink
Update E2E testCases usage (#907)
Browse files Browse the repository at this point in the history
  • Loading branch information
RTann authored Sep 8, 2022
1 parent 18fe825 commit 8778a9d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion e2etests/grpc_full_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestGRPCGetImageVulnerabilities(t *testing.T) {
conn := connectToScanner(t)
client := v1.NewImageScanServiceClient(conn)

for _, testCase := range getEnabledTestCases() {
for _, testCase := range testCases {
imgComponentsResp, err := client.GetImageComponents(context.Background(), &v1.GetImageComponentsRequest{
Image: testCase.image,
Registry: &v1.RegistryData{
Expand Down
2 changes: 1 addition & 1 deletion e2etests/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestGRPCGetImageComponents(t *testing.T) {
conn := connectToScanner(t)
client := v1.NewImageScanServiceClient(conn)

for _, testCase := range getEnabledTestCases() {
for _, testCase := range testCases {
t.Run(testCase.image, func(t *testing.T) {
imgComponentsResp, err := client.GetImageComponents(context.Background(), &v1.GetImageComponentsRequest{
Image: testCase.image,
Expand Down
2 changes: 1 addition & 1 deletion e2etests/sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func verifyImageHasExpectedFeatures(t *testing.T, client *client.Clairify, test
func TestImageSanity(t *testing.T) {
cli := client.New(getScannerHTTPEndpoint(), true)

for _, testCase := range getEnabledTestCases() {
for _, testCase := range testCases {
t.Run(testCase.image, func(t *testing.T) {
verifyImageHasExpectedFeatures(t, cli, testCase, &types.ImageRequest{Image: testCase.image, Registry: testCase.registry, UncertifiedRHELScan: testCase.uncertifiedRHEL})
})
Expand Down
33 changes: 13 additions & 20 deletions e2etests/testcase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package e2etests

import (
"os"
"sync"

apiV1 "github.com/stackrox/scanner/api/v1"
v1 "github.com/stackrox/scanner/generated/scanner/api/v1"
Expand All @@ -29,11 +28,21 @@ type testCase struct {
requiredFeatureFlag features.FeatureFlag
}

var once sync.Once
func init() {
enabledCases := testCases[:0]
for _, tc := range testCases {
// Filter out test cases that depend on disabled feature flags.
if tc.requiredFeatureFlag != nil && !tc.requiredFeatureFlag.Enabled() {
continue
}
enabledCases = append(enabledCases, tc)
}
testCases = enabledCases
}

// testCases defines all the E2E test cases.
// testCases should not be used directly;
// instead, users should call getEnabledTestCases().
// Not all defined test cases will be available for use.
// Cases which rely on a disabled feature flag are filtered out.
var testCases = []testCase{
{
image: "ubuntu:16.04",
Expand Down Expand Up @@ -3460,19 +3469,3 @@ For more details about the security issue(s), including the impact, a CVSS score
},
},
}

// getEnabledTestCases returns the enabled test cases from the list of defined test cases.
func getEnabledTestCases() []testCase {
once.Do(func() {
cases := testCases[:0]
for _, tc := range testCases {
// We filter out test cases that depend on feature flags that are disabled.
if tc.requiredFeatureFlag != nil && !tc.requiredFeatureFlag.Enabled() {
continue
}
cases = append(cases, tc)
}
testCases = cases
})
return testCases
}

0 comments on commit 8778a9d

Please sign in to comment.