Skip to content

Commit

Permalink
e2e: regex test filter (#1117)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Wozniak <[email protected]>
  • Loading branch information
wozniakjan authored Aug 26, 2024
1 parent 30b956b commit 2601d92
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ test: fmt vet test-certs
e2e-test:
go run -tags e2e ./tests/run-all.go

e2e-test-setup:
ONLY_SETUP=true go run -tags e2e ./tests/run-all.go

e2e-test-local:
SKIP_SETUP=true go run -tags e2e ./tests/run-all.go

Expand Down
55 changes: 35 additions & 20 deletions tests/run-all.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"sync"
"time"
Expand All @@ -37,6 +38,7 @@ type TestResult struct {
func main() {
ctx := context.Background()
skipSetup := os.Getenv("SKIP_SETUP") == "true"
onlySetup := os.Getenv("ONLY_SETUP") == "true"
//
// Install KEDA HTTP Add-on
//
Expand All @@ -50,27 +52,29 @@ func main() {
}
}

//
// Execute tests
//
testResults := executeTestCases(ctx)

//
// Uninstall KEDA
//
if !skipSetup {
passed := uninstallKeda(ctx)
if !passed {
os.Exit(1)
if !onlySetup {
//
// Execute tests
//
testResults := executeTestCases(ctx)

//
// Uninstall KEDA
//
if !skipSetup {
passed := uninstallKeda(ctx)
if !passed {
os.Exit(1)
}
}
}

//
// Generate execution outcome
//
exitCode := evaluateExecution(testResults)
//
// Generate execution outcome
//
exitCode := evaluateExecution(testResults)

os.Exit(exitCode)
os.Exit(exitCode)
}
}

func executeTest(ctx context.Context, file string, timeout string, tries int) TestResult {
Expand Down Expand Up @@ -102,14 +106,25 @@ func executeTest(ctx context.Context, file string, timeout string, tries int) Te
func getTestFiles() []string {
testFiles := []string{}

err := filepath.Walk("tests",
e2eRegex := os.Getenv("E2E_TEST_REGEX")
if e2eRegex == "" {
e2eRegex = ".*"
}
regex, err := regexp.Compile(e2eRegex)
if err != nil {
fmt.Printf("Error compiling regex: %s\n", err)
os.Exit(1)
}

err = filepath.Walk("tests",
func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

if strings.Contains(path, "checks") &&
strings.HasSuffix(info.Name(), "_test.go") {
strings.HasSuffix(info.Name(), "_test.go") &&
regex.MatchString(info.Name()) {
testFiles = append(testFiles, path)
}
return nil
Expand Down

0 comments on commit 2601d92

Please sign in to comment.