@@ -46,6 +46,7 @@ func (s *server) Run(ctx context.Context, task *TestTask) (reply *HelloReply, er
4646 for key , val := range oldEnv {
4747 os .Setenv (key , val )
4848 }
49+ fmt .Println (reply , err )
4950 }()
5051
5152 switch task .Kind {
@@ -82,6 +83,7 @@ func (s *server) Run(ctx context.Context, task *TestTask) (reply *HelloReply, er
8283
8384 if targetTestcase != nil {
8485 parentCases := findParentTestCases (targetTestcase , suite )
86+ fmt .Printf ("find %d parent cases\n " , len (parentCases ))
8587 suite .Items = append (parentCases , * targetTestcase )
8688 } else {
8789 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
101103 suite .API = result
102104 suite .API = strings .TrimSuffix (suite .API , "/" )
103105 } else {
106+ reply .Error = err .Error ()
107+ err = nil
104108 return
105109 }
106110
@@ -138,28 +142,71 @@ func findParentTestCases(testcase *testing.TestCase, suite *testing.TestSuite) (
138142 reg , matchErr := regexp .Compile (`.*\{\{.*\.\w*.*}\}.*` )
139143 targetReg , targetErr := regexp .Compile (`\.\w*` )
140144
145+ expectNames := new (UniqueSlice [string ])
141146 if matchErr == nil && targetErr == nil {
142- expectName := ""
147+ var expectName string
143148 for _ , val := range testcase .Request .Header {
144149 if matched := reg .MatchString (val ); matched {
145150 expectName = targetReg .FindString (val )
146151 expectName = strings .TrimPrefix (expectName , "." )
147- break
152+ expectNames . Push ( expectName )
148153 }
149154 }
150155
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 )
154162 expectName = strings .TrimPrefix (expectName , "." )
163+ expectNames .Push (expectName )
155164 }
156165 }
157166
167+ fmt .Println ("expect test case names" , expectNames .GetAll ())
158168 for _ , item := range suite .Items {
159- if item .Name == expectName {
169+ if expectNames . Exist ( item .Name ) {
160170 testcases = append (testcases , item )
161171 }
162172 }
163173 }
164174 return
165175}
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