Skip to content

Commit c1356e5

Browse files
committed
fix the unit tests
1 parent b0943d7 commit c1356e5

File tree

1 file changed

+52
-50
lines changed

1 file changed

+52
-50
lines changed

pkg/runner/runner.go

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,58 +17,58 @@ limitations under the License.
1717
package runner
1818

1919
import (
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
3030
type 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
4343
type ResponseRecord interface {
44-
GetResponseRecord() SimpleResponse
44+
GetResponseRecord() SimpleResponse
4545
}
4646

4747
// SimpleResponse represents a simple response
4848
type 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

5555
func (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.
6565
func 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.
7979
type 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

8888
func (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
9393
func (r *UnimplementedRunner) WithOutputWriter(writer io.Writer) {
94-
r.writer = writer
94+
r.writer = writer
9595
}
9696

9797
// WithWriteLevel sets the level writer
9898
func (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
105105
func (r *UnimplementedRunner) WithTestReporter(reporter TestReporter) {
106-
r.testReporter = reporter
106+
r.testReporter = reporter
107107
}
108108

109109
// WithExecer sets the execer
110110
func (r *UnimplementedRunner) WithExecer(execer fakeruntime.Execer) {
111-
r.execer = execer
111+
r.execer = execer
112112
}
113113

114114
// WithSecure sets the secure option.
115115
func (r *UnimplementedRunner) WithSecure(secure *testing.Secure) {
116-
r.Secure = secure
116+
r.Secure = secure
117117
}
118118

119119
func (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

124124
func (r *UnimplementedRunner) WithAPISuggestLimit(int) {
125-
// empty implement
125+
// empty implement
126126
}
127127

128128
func (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

Comments
 (0)