-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
259 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package flags | ||
|
||
import ( | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
// EnvironmentFlags contains information for specifying multiple environments. | ||
type EnvironmentFlags struct { | ||
Environments []string | ||
} | ||
|
||
func NewEnvironmentFlags() *EnvironmentFlags { | ||
return &EnvironmentFlags{ | ||
Environments: []string{}, | ||
} | ||
} | ||
|
||
func (f *EnvironmentFlags) BindFlags(fs *pflag.FlagSet) { | ||
fs.StringSliceVar(&f.Environments, | ||
"env", | ||
f.Environments, | ||
"specify one or more environments (use --env multiple times for more than one)") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package ginkgofilter | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
|
||
"k8s.io/apimachinery/pkg/util/sets" | ||
|
||
"github.com/openshift-eng/openshift-tests-extension/pkg/ginkgo" | ||
) | ||
|
||
// FilterTestCases filters test cases based on the environment flags | ||
func FilterTestCases(testCases []*ginkgo.TestCase, envFlags sets.Set[string]) []*ginkgo.TestCase { | ||
var filtered []*ginkgo.TestCase | ||
|
||
testCaseLoop: | ||
for _, testCase := range testCases { | ||
testHasInclude := false | ||
annotations := extractAnnotations(testCase.Name) | ||
|
||
for _, a := range annotations { | ||
la := strings.ToLower(a) | ||
|
||
if strings.HasPrefix(strings.ToLower(a), "skipped:") { | ||
condition := strings.TrimPrefix(la, "skipped:") | ||
if envFlags.Has(condition) { | ||
continue testCaseLoop // skip this test | ||
} | ||
} | ||
|
||
if strings.HasPrefix(strings.ToLower(a), "include:") { | ||
testHasInclude = true | ||
condition := strings.TrimPrefix(la, "include:") | ||
if envFlags.Has(condition) { | ||
filtered = append(filtered, testCase) // include this test for sure | ||
break | ||
} | ||
} | ||
} | ||
if !testHasInclude { | ||
filtered = append(filtered, testCase) | ||
} | ||
} | ||
|
||
return filtered | ||
} | ||
|
||
func extractAnnotations(testName string) []string { | ||
// Define a regex to match all text within square brackets but exclude the brackets themselves | ||
re := regexp.MustCompile(`\[(.*?)\]`) | ||
matches := re.FindAllStringSubmatch(testName, -1) | ||
|
||
var annotations []string | ||
for _, match := range matches { | ||
if len(match) > 1 { | ||
annotations = append(annotations, match[1]) | ||
} | ||
} | ||
return annotations | ||
} |
Oops, something went wrong.