@@ -17,58 +17,58 @@ limitations under the License.
1717package runner
1818
1919import (
20- "context"
21- "fmt"
22- "io"
23- "strings"
20+ "context"
21+ "fmt"
22+ "io"
23+ "strings"
2424
25- "github.com/linuxsuren/api-testing/pkg/testing"
26- fakeruntime "github.com/linuxsuren/go-fake-runtime"
25+ "github.com/linuxsuren/api-testing/pkg/testing"
26+ fakeruntime "github.com/linuxsuren/go-fake-runtime"
2727)
2828
2929// TestCaseRunner represents a test case runner
3030type TestCaseRunner interface {
31- RunTestCase (testcase * testing.TestCase , dataContext interface {}, ctx context.Context ) (output interface {}, err error )
32- GetSuggestedAPIs (suite * testing.TestSuite , api string ) ([]* testing.TestCase , error )
33- WithSecure (secure * testing.Secure )
34- WithOutputWriter (io.Writer )
35- WithWriteLevel (level string )
36- WithTestReporter (TestReporter )
37- WithExecer (fakeruntime.Execer )
38- WithSuite (* testing.TestSuite )
39- WithAPISuggestLimit (int )
31+ RunTestCase (testcase * testing.TestCase , dataContext interface {}, ctx context.Context ) (output interface {}, err error )
32+ GetSuggestedAPIs (suite * testing.TestSuite , api string ) ([]* testing.TestCase , error )
33+ WithSecure (secure * testing.Secure )
34+ WithOutputWriter (io.Writer )
35+ WithWriteLevel (level string )
36+ WithTestReporter (TestReporter )
37+ WithExecer (fakeruntime.Execer )
38+ WithSuite (* testing.TestSuite )
39+ WithAPISuggestLimit (int )
4040}
4141
4242// HTTPResponseRecord represents a http response record
4343type ResponseRecord interface {
44- GetResponseRecord () SimpleResponse
44+ GetResponseRecord () SimpleResponse
4545}
4646
4747// SimpleResponse represents a simple response
4848type SimpleResponse struct {
49- Header map [string ]string
50- Body string
51- RawBody []byte
52- StatusCode int
49+ Header map [string ]string
50+ Body string
51+ RawBody []byte
52+ StatusCode int
5353}
5454
5555func (s SimpleResponse ) getFileName () string {
56- for k , v := range s .Header {
57- if k == "Content-Disposition" {
58- return strings .TrimSuffix (strings .TrimPrefix (v , `attachment; filename="` ), `"` )
59- }
60- }
61- return ""
56+ for k , v := range s .Header {
57+ if k == "Content-Disposition" {
58+ return strings .TrimSuffix (strings .TrimPrefix (v , `attachment; filename="` ), `"` )
59+ }
60+ }
61+ return ""
6262}
6363
6464// NewDefaultUnimplementedRunner initializes an unimplementedRunner using the default values.
6565func NewDefaultUnimplementedRunner () UnimplementedRunner {
66- return UnimplementedRunner {
67- testReporter : NewDiscardTestReporter (),
68- writer : io .Discard ,
69- log : NewDefaultLevelWriter ("info" , io .Discard ),
70- execer : fakeruntime .NewDefaultExecer (),
71- }
66+ return UnimplementedRunner {
67+ testReporter : NewDiscardTestReporter (),
68+ writer : io .Discard ,
69+ log : NewDefaultLevelWriter ("info" , io .Discard ),
70+ execer : fakeruntime .NewDefaultExecer (),
71+ }
7272}
7373
7474// UnimplementedRunner implements interface TestCaseRunner except method RunTestCase.
@@ -77,54 +77,56 @@ func NewDefaultUnimplementedRunner() UnimplementedRunner {
7777// It is recommended to use NewDefaultUnimplementedRunner to initalize rather than
7878// to fill it manully.
7979type UnimplementedRunner struct {
80- testReporter TestReporter
81- writer io.Writer
82- log LevelWriter
83- execer fakeruntime.Execer
84- Secure * testing.Secure
85- proxy * testing.Proxy
80+ testReporter TestReporter
81+ writer io.Writer
82+ log LevelWriter
83+ execer fakeruntime.Execer
84+ Secure * testing.Secure
85+ proxy * testing.Proxy
8686}
8787
8888func (r * UnimplementedRunner ) RunTestCase (testcase * testing.TestCase , dataContext interface {}, ctx context.Context ) (output interface {}, err error ) {
89- return nil , fmt .Errorf ("unimplemented" )
89+ return nil , fmt .Errorf ("unimplemented" )
9090}
9191
9292// WithOutputWriter sets the io.Writer
9393func (r * UnimplementedRunner ) WithOutputWriter (writer io.Writer ) {
94- r .writer = writer
94+ r .writer = writer
9595}
9696
9797// WithWriteLevel sets the level writer
9898func (r * UnimplementedRunner ) WithWriteLevel (level string ) {
99- if level != "" {
100- r .log = NewDefaultLevelWriter (level , r .writer )
101- }
99+ if level != "" {
100+ r .log = NewDefaultLevelWriter (level , r .writer )
101+ }
102102}
103103
104104// WithTestReporter sets the TestReporter
105105func (r * UnimplementedRunner ) WithTestReporter (reporter TestReporter ) {
106- r .testReporter = reporter
106+ r .testReporter = reporter
107107}
108108
109109// WithExecer sets the execer
110110func (r * UnimplementedRunner ) WithExecer (execer fakeruntime.Execer ) {
111- r .execer = execer
111+ r .execer = execer
112112}
113113
114114// WithSecure sets the secure option.
115115func (r * UnimplementedRunner ) WithSecure (secure * testing.Secure ) {
116- r .Secure = secure
116+ r .Secure = secure
117117}
118118
119119func (r * UnimplementedRunner ) GetSuggestedAPIs (suite * testing.TestSuite , api string ) (result []* testing.TestCase , err error ) {
120- // empty implement
121- return
120+ // empty implement
121+ return
122122}
123123
124124func (r * UnimplementedRunner ) WithAPISuggestLimit (int ) {
125- // empty implement
125+ // empty implement
126126}
127127
128128func (s * UnimplementedRunner ) WithSuite (suite * testing.TestSuite ) {
129- s .proxy = suite .Proxy
129+ if suite != nil {
130+ s .Secure = suite .Spec .Secure
131+ }
130132}
0 commit comments