@@ -2,16 +2,19 @@ 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
+ func listTests (regex string , testsToSelect [] string , testsToSkip []string ) (tests , skippedTests []string , err error ) {
15
18
e := executables .NewExecutable (filepath .Join ("bin" , e2eBinary ))
16
19
ctx := context .Background ()
17
20
testResponse , err := e .Execute (ctx , "-test.list" , regex )
@@ -21,16 +24,26 @@ func listTests(regex string, testsToSkip []string) (tests, skippedTests []string
21
24
22
25
skipLookup := types .SliceToLookup (testsToSkip )
23
26
scanner := bufio .NewScanner (& testResponse )
24
- for scanner .Scan () {
25
- line := scanner .Text ()
26
- if skipLookup .IsPresent (line ) {
27
- skippedTests = append (skippedTests , line )
27
+ rawTestList := processTestListOutput (testResponse )
28
+
29
+ for _ , t := range rawTestList {
30
+ selected := len (testsToSelect ) == 0
31
+ for _ , s := range testsToSelect {
32
+ re := regexp .MustCompile (s )
33
+ if re .MatchString (t ) {
34
+ selected = true
35
+ break
36
+ }
37
+ }
38
+ if ! selected {
28
39
continue
29
40
}
30
-
31
- if strings . HasPrefix ( line , "Test" ) {
32
- tests = append ( tests , line )
41
+ if skipLookup . IsPresent ( t ) {
42
+ skippedTests = append ( skippedTests , t )
43
+ continue
33
44
}
45
+
46
+ tests = append (tests , t )
34
47
}
35
48
36
49
if err := scanner .Err (); err != nil {
@@ -39,3 +52,31 @@ func listTests(regex string, testsToSkip []string) (tests, skippedTests []string
39
52
40
53
return tests , skippedTests , nil
41
54
}
55
+
56
+ // parse the output of -test.list, and add subtests
57
+ func processTestListOutput (b bytes.Buffer ) (tests []string ) {
58
+ s := bufio .NewScanner (& b )
59
+ for s .Scan () {
60
+ line := s .Text ()
61
+ if ! strings .HasPrefix (line , "Test" ) {
62
+ continue
63
+ }
64
+
65
+ if ! strings .HasSuffix (line , "Suite" ) {
66
+ tests = append (tests , line )
67
+ continue
68
+ }
69
+
70
+ if strings .HasSuffix (line , "Suite" ) {
71
+ for k , s := range e2etest .Suites {
72
+ if strings .HasSuffix (line , k ) {
73
+ for _ , st := range s {
74
+ tests = append (tests , line + "/" + st .GetName ())
75
+ }
76
+ break
77
+ }
78
+ }
79
+ }
80
+ }
81
+ return tests
82
+ }
0 commit comments