@@ -23,7 +23,6 @@ const (
23
23
var (
24
24
waitRunDur = flag .Duration ("wait-run" , 3 * time .Second , "wait time between tests" )
25
25
testsFile = flag .String ("i" , "./tests.yml" , "yaml file path contains the tests to run" )
26
- specificTest = flag .String ("t" , "" , "run only a specific test by its name" )
27
26
outputDir = flag .String ("o" , "./" , "directory to save generaged Markdown and CSV files" )
28
27
enableREADMEOutput = flag .Bool ("readme" , false , "to generate a README.md file near the RESULTS.md" )
29
28
spreadsheetID = flag .String ("g-spreadsheet" , "" , "Google Spreadsheet ID to send results" )
35
34
36
35
// server-benchmarks --wait-run=3s -i ./tests.dev.yml -o ./dev -g-spreadsheet $GoogleSpreadsheetID -g-secret client_secret.json
37
36
func main () {
37
+ var specificTests stringSlice
38
+ flag .Var (& specificTests , "t" , "run only specific tests by their names" ) // support multiple -t flags.
38
39
flag .Parse ()
39
40
40
41
if _ , err := os .Stat ("/.dockerenv" ); err == nil || os .IsExist (err ) {
@@ -44,11 +45,7 @@ func main() {
44
45
tests , err := readTests (* testsFile )
45
46
catch (err )
46
47
47
- if specificTestName := strings .ToLower (* specificTest ); specificTestName != "" {
48
- tests = slices .DeleteFunc (tests , func (t * Test ) bool {
49
- return strings .ToLower (t .Name ) != specificTestName
50
- })
51
- }
48
+ tests = filterTests (specificTests , tests ... )
52
49
53
50
// TESTS
54
51
for _ , t := range tests {
@@ -95,6 +92,39 @@ func readTests(filename string) ([]*Test, error) {
95
92
return tests , nil
96
93
}
97
94
95
+ func filterTests (specificTests stringSlice , tests ... * Test ) []* Test {
96
+ testsAndEnvsToKeep := make (map [string ][]string , len (specificTests ))
97
+ for _ , specificTest := range specificTests {
98
+ if specificTestName := strings .ToLower (specificTest ); specificTestName != "" {
99
+ specificTestEnvName := ""
100
+ if dotParts := strings .Split (specificTestName , "." ); len (dotParts ) > 1 {
101
+ specificTestName = strings .Join (dotParts [0 :len (dotParts )- 1 ], "." ) // name all except last dot.
102
+ specificTestEnvName = dotParts [len (dotParts )- 1 ]
103
+ }
104
+ testsAndEnvsToKeep [specificTestName ] = append (testsAndEnvsToKeep [specificTestName ], specificTestEnvName )
105
+ }
106
+ }
107
+
108
+ // Delete all tests and envs that are not in the specificTests list.
109
+ return slices .DeleteFunc (tests , func (t * Test ) bool {
110
+ // keep only the specific test.
111
+ testName := strings .ToLower (t .Name )
112
+ if specificTestEnvNames , ok := testsAndEnvsToKeep [testName ]; ok {
113
+ // keep only the specific test's environment.
114
+ // E.g. -t rest.iris -t rest.iris-private
115
+ if len (specificTestEnvNames ) > 0 {
116
+ t .Envs = slices .DeleteFunc (t .Envs , func (e * TestEnv ) bool {
117
+ return ! slices .Contains (specificTestEnvNames , strings .ToLower (e .GetName ()))
118
+ })
119
+ }
120
+
121
+ return false
122
+ }
123
+
124
+ return true
125
+ })
126
+ }
127
+
98
128
func cleanup () {
99
129
for i , f := range downloadedFiles {
100
130
if err := os .Remove (f ); err != nil && ! errors .Is (err , os .ErrNotExist ) {
0 commit comments