@@ -32,6 +32,7 @@ type runOption struct {
32
32
reporter runner.TestReporter
33
33
reportWriter runner.ReportResultWriter
34
34
report string
35
+ reportIgnore bool
35
36
}
36
37
37
38
func newDefaultRunOption () * runOption {
@@ -71,14 +72,22 @@ See also https://github.com/LinuxSuRen/api-testing/tree/master/sample`,
71
72
flags .Int64VarP (& opt .thread , "thread" , "" , 1 , "Threads of the execution" )
72
73
flags .Int32VarP (& opt .qps , "qps" , "" , 5 , "QPS" )
73
74
flags .Int32VarP (& opt .burst , "burst" , "" , 5 , "burst" )
74
- flags .StringVarP (& opt .report , "report" , "" , "" , "The type of target report" )
75
+ flags .StringVarP (& opt .report , "report" , "" , "" , "The type of target report. Supported: markdown, md, discard, std " )
75
76
return
76
77
}
77
78
78
79
func (o * runOption ) preRunE (cmd * cobra.Command , args []string ) (err error ) {
80
+ writer := cmd .OutOrStdout ()
81
+
79
82
switch o .report {
80
83
case "markdown" , "md" :
81
- o .reportWriter = runner .NewMarkdownResultWriter (cmd .OutOrStdout ())
84
+ o .reportWriter = runner .NewMarkdownResultWriter (writer )
85
+ case "discard" :
86
+ o .reportWriter = runner .NewDiscardResultWriter ()
87
+ case "" , "std" :
88
+ o .reportWriter = runner .NewResultWriter (writer )
89
+ default :
90
+ err = fmt .Errorf ("not supported report type: '%s'" , o .report )
82
91
}
83
92
return
84
93
}
@@ -97,17 +106,18 @@ func (o *runOption) runE(cmd *cobra.Command, args []string) (err error) {
97
106
for i := range files {
98
107
item := files [i ]
99
108
if err = o .runSuiteWithDuration (item ); err != nil {
100
- return
109
+ break
101
110
}
102
111
}
103
112
}
104
113
105
114
// print the report
106
- if err == nil {
107
- var results []runner.ReportResult
108
- if results , err = o .reporter .ExportAllReportResults (); err == nil {
109
- err = o .reportWriter .Output (results )
115
+ if results , reportErr := o .reporter .ExportAllReportResults (); reportErr == nil {
116
+ if reportErr = o .reportWriter .Output (results ); reportErr != nil {
117
+ cmd .Println ("failed to Output all reports" , reportErr )
110
118
}
119
+ } else {
120
+ cmd .Println ("failed to export all reports" , reportErr )
111
121
}
112
122
return
113
123
}
@@ -205,6 +215,7 @@ func (o *runOption) runSuite(suite string, dataContext map[string]interface{}, c
205
215
simpleRunner := runner .NewSimpleTestCaseRunner ()
206
216
simpleRunner .WithTestReporter (o .reporter )
207
217
if output , err = simpleRunner .RunTestCase (& testCase , dataContext , ctxWithTimeout ); err != nil && ! o .requestIgnoreError {
218
+ err = fmt .Errorf ("failed to run '%s', %v" , testCase .Name , err )
208
219
return
209
220
} else {
210
221
err = nil
0 commit comments