@@ -46,6 +46,7 @@ func (s *server) Run(ctx context.Context, task *TestTask) (reply *HelloReply, er
46
46
for key , val := range oldEnv {
47
47
os .Setenv (key , val )
48
48
}
49
+ fmt .Println (reply , err )
49
50
}()
50
51
51
52
switch task .Kind {
@@ -82,6 +83,7 @@ func (s *server) Run(ctx context.Context, task *TestTask) (reply *HelloReply, er
82
83
83
84
if targetTestcase != nil {
84
85
parentCases := findParentTestCases (targetTestcase , suite )
86
+ fmt .Printf ("find %d parent cases\n " , len (parentCases ))
85
87
suite .Items = append (parentCases , * targetTestcase )
86
88
} else {
87
89
err = fmt .Errorf ("cannot found testcase %s" , task .CaseName )
@@ -101,6 +103,8 @@ func (s *server) Run(ctx context.Context, task *TestTask) (reply *HelloReply, er
101
103
suite .API = result
102
104
suite .API = strings .TrimSuffix (suite .API , "/" )
103
105
} else {
106
+ reply .Error = err .Error ()
107
+ err = nil
104
108
return
105
109
}
106
110
@@ -138,28 +142,71 @@ func findParentTestCases(testcase *testing.TestCase, suite *testing.TestSuite) (
138
142
reg , matchErr := regexp .Compile (`.*\{\{.*\.\w*.*}\}.*` )
139
143
targetReg , targetErr := regexp .Compile (`\.\w*` )
140
144
145
+ expectNames := new (UniqueSlice [string ])
141
146
if matchErr == nil && targetErr == nil {
142
- expectName := ""
147
+ var expectName string
143
148
for _ , val := range testcase .Request .Header {
144
149
if matched := reg .MatchString (val ); matched {
145
150
expectName = targetReg .FindString (val )
146
151
expectName = strings .TrimPrefix (expectName , "." )
147
- break
152
+ expectNames . Push ( expectName )
148
153
}
149
154
}
150
155
151
- if expectName == "" {
152
- if mached := reg .MatchString (testcase .Request .API ); mached {
153
- expectName = targetReg .FindString (testcase .Request .API )
156
+ if mached := reg .MatchString (testcase .Request .API ); mached {
157
+ // remove {{ and }}
158
+ if left , leftErr := regexp .Compile (`.*\{\{` ); leftErr == nil {
159
+ api := left .ReplaceAllString (testcase .Request .API , "" )
160
+
161
+ expectName = targetReg .FindString (api )
154
162
expectName = strings .TrimPrefix (expectName , "." )
163
+ expectNames .Push (expectName )
155
164
}
156
165
}
157
166
167
+ fmt .Println ("expect test case names" , expectNames .GetAll ())
158
168
for _ , item := range suite .Items {
159
- if item .Name == expectName {
169
+ if expectNames . Exist ( item .Name ) {
160
170
testcases = append (testcases , item )
161
171
}
162
172
}
163
173
}
164
174
return
165
175
}
176
+
177
+ // UniqueSlice represents an unique slice
178
+ type UniqueSlice [T comparable ] struct {
179
+ data []T
180
+ }
181
+
182
+ // Push pushes an item if it's not exist
183
+ func (s * UniqueSlice [T ]) Push (item T ) * UniqueSlice [T ] {
184
+ if s .data == nil {
185
+ s .data = []T {item }
186
+ } else {
187
+ for _ , it := range s .data {
188
+ if it == item {
189
+ return s
190
+ }
191
+ }
192
+ s .data = append (s .data , item )
193
+ }
194
+ return s
195
+ }
196
+
197
+ // Exist checks if the item exist, return true it exists
198
+ func (s * UniqueSlice [T ]) Exist (item T ) bool {
199
+ if s .data != nil {
200
+ for _ , it := range s .data {
201
+ if it == item {
202
+ return true
203
+ }
204
+ }
205
+ }
206
+ return false
207
+ }
208
+
209
+ // GetAll returns all the items
210
+ func (s * UniqueSlice [T ]) GetAll () []T {
211
+ return s .data
212
+ }
0 commit comments