@@ -2,16 +2,21 @@ package e2e
2
2
3
3
import (
4
4
"bufio"
5
+ "bytes"
5
6
"context"
6
7
"fmt"
7
8
"path/filepath"
9
+ "regexp"
8
10
"strings"
9
11
10
12
"github.com/aws/eks-anywhere/pkg/executables"
11
13
"github.com/aws/eks-anywhere/pkg/types"
14
+ e2etest "github.com/aws/eks-anywhere/test/e2e"
12
15
)
13
16
14
- func listTests (regex string , testsToSkip []string ) (tests , skippedTests []string , err error ) {
17
+ // regex will filter out the tests that match the regex, but it does't see subtests.
18
+ // TestsToSelect and testsToSkip will filter out all test cases including subtests.
19
+ func listTests (regex string , testsToSelect []string , testsToSkip []string ) (tests , skippedTests []string , err error ) {
15
20
e := executables .NewExecutable (filepath .Join ("bin" , e2eBinary ))
16
21
ctx := context .Background ()
17
22
testResponse , err := e .Execute (ctx , "-test.list" , regex )
@@ -21,16 +26,26 @@ func listTests(regex string, testsToSkip []string) (tests, skippedTests []string
21
26
22
27
skipLookup := types .SliceToLookup (testsToSkip )
23
28
scanner := bufio .NewScanner (& testResponse )
24
- for scanner .Scan () {
25
- line := scanner .Text ()
26
- if skipLookup .IsPresent (line ) {
27
- skippedTests = append (skippedTests , line )
29
+ rawTestList := processTestListOutput (testResponse )
30
+
31
+ for _ , t := range rawTestList {
32
+ selected := len (testsToSelect ) == 0
33
+ for _ , s := range testsToSelect {
34
+ re := regexp .MustCompile (s )
35
+ if re .MatchString (t ) {
36
+ selected = true
37
+ break
38
+ }
39
+ }
40
+ if ! selected {
28
41
continue
29
42
}
30
-
31
- if strings . HasPrefix ( line , "Test" ) {
32
- tests = append ( tests , line )
43
+ if skipLookup . IsPresent ( t ) {
44
+ skippedTests = append ( skippedTests , t )
45
+ continue
33
46
}
47
+
48
+ tests = append (tests , t )
34
49
}
35
50
36
51
if err := scanner .Err (); err != nil {
@@ -39,3 +54,31 @@ func listTests(regex string, testsToSkip []string) (tests, skippedTests []string
39
54
40
55
return tests , skippedTests , nil
41
56
}
57
+
58
+ // parse the output of -test.list, and add subtests
59
+ func processTestListOutput (b bytes.Buffer ) (tests []string ) {
60
+ s := bufio .NewScanner (& b )
61
+ for s .Scan () {
62
+ line := s .Text ()
63
+ if ! strings .HasPrefix (line , "Test" ) {
64
+ continue
65
+ }
66
+
67
+ if ! strings .HasSuffix (line , "Suite" ) {
68
+ tests = append (tests , line )
69
+ continue
70
+ }
71
+
72
+ if strings .HasSuffix (line , "Suite" ) {
73
+ for k , s := range e2etest .Suites {
74
+ if strings .HasSuffix (line , k ) {
75
+ for _ , st := range s {
76
+ tests = append (tests , line + "/" + st .GetName ())
77
+ }
78
+ break
79
+ }
80
+ }
81
+ }
82
+ }
83
+ return tests
84
+ }
0 commit comments