Skip to content

Commit

Permalink
mantle/kola/harness: allow success if all tests are denylisted
Browse files Browse the repository at this point in the history
This will allow us to denylist certain categories of tests and not
have the pipeline fail. See [1] for a real world example of why this
is useful.

[1] coreos/fedora-coreos-config@e983073
  • Loading branch information
Adam0Brien authored and dustymabe committed Jun 7, 2023
1 parent 92822a0 commit 8166991
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions mantle/kola/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,27 @@ func runProvidedTests(testsBank map[string]*register.Test, patterns []string, mu
plog.Fatal(err)
}

// Make sure all given patterns by the user match at least one test
for _, pattern := range patterns {
match, err := patternMatchesTests(pattern, testsBank)
if err != nil {
plog.Fatal(err)
}
if !match {
plog.Fatalf("The user provided pattern didn't match any tests: %s", pattern)
}
}

tests, err := filterTests(testsBank, patterns, pltfrm)
if err != nil {
plog.Fatal(err)
}

if len(tests) == 0 && allTestsDenyListed(tests) {
fmt.Printf("There are no tests to run because all tests are denylisted. Output in %v\n", outputDir)
return nil
}

flight, err := NewFlight(pltfrm)
if err != nil {
plog.Fatalf("Flight failed: %v", err)
Expand Down Expand Up @@ -804,6 +820,7 @@ func runProvidedTests(testsBank map[string]*register.Test, patterns []string, mu
} else {
fmt.Printf("PASS, output in %v\n", outputDir)
}

return suiteErr
}

Expand All @@ -826,6 +843,20 @@ func runProvidedTests(testsBank map[string]*register.Test, patterns []string, mu
return runErr
}

func allTestsDenyListed(tests map[string]*register.Test) bool {
for name := range tests {
isDenylisted, err := testIsDenyListed(name)
if err != nil {
plog.Warningf("Error while checking denylist for test: %s", err)
continue
}
if !isDenylisted {
return false
}
}
return true
}

func allTestsAllowRerunSuccess(testsBank map[string]*register.Test, testsToRerun, rerunSuccessTags []string) bool {
// Always consider the special AllowRerunSuccessTag that is added
// by the test harness in some failure scenarios.
Expand Down Expand Up @@ -1209,6 +1240,18 @@ func testIsDenyListed(testname string) (bool, error) {
return false, nil
}

// Function that returns true if at least one test matches the given pattern
func patternMatchesTests(pattern string, tests map[string]*register.Test) (bool, error) {
for testname := range tests {
if match, err := filepath.Match(pattern, testname); err != nil {
return false, err
} else if match {
return true, nil
}
}
return false, nil
}

// registerTestDir parses one test directory and registers it as a test
func registerTestDir(dir, testprefix string, children []os.DirEntry) error {
var dependencydir string
Expand Down

0 comments on commit 8166991

Please sign in to comment.