Skip to content

Commit

Permalink
UPSTREAM: <carry>: Change annotation mechanics to allow injecting tes…
Browse files Browse the repository at this point in the history
…tMaps and filter out tests
  • Loading branch information
soltysh authored and bertinatto committed Apr 11, 2023
1 parent ab1d3ba commit 8c06b8f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions openshift-hack/e2e/annotate/annotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import (
var reHasSig = regexp.MustCompile(`\[sig-[\w-]+\]`)

// Run generates tests annotations for the targeted package.
func Run() {
// It accepts testMaps which defines labeling rules and filter
// function to remove elements based on test name and their labels.
func Run(testMaps map[string][]string, filter func(name string) bool) {
var errors []string

if len(os.Args) != 2 && len(os.Args) != 3 {
Expand All @@ -25,7 +27,7 @@ func Run() {
}
filename := os.Args[len(os.Args)-1]

generator := newGenerator()
generator := newGenerator(testMaps)
ginkgo.GetSuite().BuildTree()
ginkgo.GetSuite().WalkTests(generator.generateRename)
if len(generator.errors) > 0 {
Expand Down Expand Up @@ -68,8 +70,11 @@ func Run() {
}

var pairs []string
for from, to := range generator.output {
pairs = append(pairs, fmt.Sprintf("%q:\n%q,", from, to))
for testName, labels := range generator.output {
if filter(fmt.Sprintf("%s%s", testName, labels)) {
continue
}
pairs = append(pairs, fmt.Sprintf("%q:\n%q,", testName, labels))
}
sort.Strings(pairs)
contents := fmt.Sprintf(`
Expand Down Expand Up @@ -105,12 +110,12 @@ func init() {
}
}

func newGenerator() *ginkgoTestRenamer {
func newGenerator(testMaps map[string][]string) *ginkgoTestRenamer {
var allLabels []string
matches := make(map[string]*regexp.Regexp)
stringMatches := make(map[string][]string)

for label, items := range TestMaps {
for label, items := range testMaps {
sort.Strings(items)
allLabels = append(allLabels, label)
var remain []string
Expand Down
2 changes: 1 addition & 1 deletion openshift-hack/e2e/annotate/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import (
)

func main() {
annotate.Run()
annotate.Run(annotate.TestMaps, func(name string) bool { return false })
}
2 changes: 1 addition & 1 deletion openshift-hack/e2e/annotate/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestStockRules(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
testRenamer := newGenerator()
testRenamer := newGenerator(TestMaps)
testNode := &testNode{
text: test.testName,
}
Expand Down

0 comments on commit 8c06b8f

Please sign in to comment.