From 2601d92888235e696823dcffad19c1c960b7d8b0 Mon Sep 17 00:00:00 2001 From: Jan Wozniak Date: Mon, 26 Aug 2024 19:40:20 +0200 Subject: [PATCH] e2e: regex test filter (#1117) Signed-off-by: Jan Wozniak --- Makefile | 3 +++ tests/run-all.go | 55 ++++++++++++++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 8cc5f5a0..e77fec31 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/tests/run-all.go b/tests/run-all.go index 37799aba..98a2f086 100644 --- a/tests/run-all.go +++ b/tests/run-all.go @@ -11,6 +11,7 @@ import ( "os" "os/exec" "path/filepath" + "regexp" "strings" "sync" "time" @@ -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 // @@ -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 { @@ -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