@@ -11,10 +11,12 @@ import (
1111 "sync"
1212 "time"
1313
14+ "github.com/linuxsuren/api-testing/pkg/apispec"
1415 "github.com/linuxsuren/api-testing/pkg/limit"
1516 "github.com/linuxsuren/api-testing/pkg/render"
1617 "github.com/linuxsuren/api-testing/pkg/runner"
1718 "github.com/linuxsuren/api-testing/pkg/testing"
19+ "github.com/linuxsuren/api-testing/pkg/util"
1820 "github.com/spf13/cobra"
1921 "golang.org/x/sync/semaphore"
2022)
@@ -35,6 +37,7 @@ type runOption struct {
3537 reportWriter runner.ReportResultWriter
3638 report string
3739 reportIgnore bool
40+ swaggerURL string
3841 level string
3942 caseItems []string
4043}
@@ -69,14 +72,15 @@ See also https://github.com/LinuxSuRen/api-testing/tree/master/sample`,
6972 // set flags
7073 flags := cmd .Flags ()
7174 flags .StringVarP (& opt .pattern , "pattern" , "p" , "test-suite-*.yaml" ,
72- "The file pattern which try to execute the test cases" )
75+ "The file pattern which try to execute the test cases. Brace expansion is supported, such as: test-suite-{1,2}.yaml " )
7376 flags .StringVarP (& opt .level , "level" , "l" , "info" , "Set the output log level" )
7477 flags .DurationVarP (& opt .duration , "duration" , "" , 0 , "Running duration" )
7578 flags .DurationVarP (& opt .requestTimeout , "request-timeout" , "" , time .Minute , "Timeout for per request" )
7679 flags .BoolVarP (& opt .requestIgnoreError , "request-ignore-error" , "" , false , "Indicate if ignore the request error" )
7780 flags .StringVarP (& opt .report , "report" , "" , "" , "The type of target report. Supported: markdown, md, html, discard, std" )
7881 flags .StringVarP (& opt .reportFile , "report-file" , "" , "" , "The file path of the report" )
7982 flags .BoolVarP (& opt .reportIgnore , "report-ignore" , "" , false , "Indicate if ignore the report output" )
83+ flags .StringVarP (& opt .swaggerURL , "swagger-url" , "" , "" , "The URL of swagger" )
8084 flags .Int64VarP (& opt .thread , "thread" , "" , 1 , "Threads of the execution" )
8185 flags .Int32VarP (& opt .qps , "qps" , "" , 5 , "QPS" )
8286 flags .Int32VarP (& opt .burst , "burst" , "" , 5 , "burst" )
@@ -108,12 +112,20 @@ func (o *runOption) preRunE(cmd *cobra.Command, args []string) (err error) {
108112 err = fmt .Errorf ("not supported report type: '%s'" , o .report )
109113 }
110114
115+ if err == nil {
116+ var swaggerAPI apispec.APIConverage
117+ if o .swaggerURL != "" {
118+ if swaggerAPI , err = apispec .ParseURLToSwagger (o .swaggerURL ); err == nil {
119+ o .reportWriter .WithAPIConverage (swaggerAPI )
120+ }
121+ }
122+ }
123+
111124 o .caseItems = args
112125 return
113126}
114127
115128func (o * runOption ) runE (cmd * cobra.Command , args []string ) (err error ) {
116- var files []string
117129 o .startTime = time .Now ()
118130 o .context = cmd .Context ()
119131 o .limiter = limit .NewDefaultRateLimiter (o .qps , o .burst )
@@ -122,12 +134,20 @@ func (o *runOption) runE(cmd *cobra.Command, args []string) (err error) {
122134 o .limiter .Stop ()
123135 }()
124136
125- if files , err = filepath .Glob (o .pattern ); err == nil {
126- for i := range files {
127- item := files [i ]
128- if err = o .runSuiteWithDuration (item ); err != nil {
129- break
130- }
137+ var suites []string
138+ for _ , pattern := range util .Expand (o .pattern ) {
139+ var files []string
140+ if files , err = filepath .Glob (pattern ); err == nil {
141+ suites = append (suites , files ... )
142+ }
143+ }
144+
145+ cmd .Println ("found suites:" , len (suites ))
146+ for i := range suites {
147+ item := suites [i ]
148+ cmd .Println ("run suite:" , item )
149+ if err = o .runSuiteWithDuration (item ); err != nil {
150+ break
131151 }
132152 }
133153
0 commit comments