Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.

Commit d1b7c04

Browse files
committed
x
1 parent 11d0800 commit d1b7c04

File tree

6 files changed

+58
-63
lines changed

6 files changed

+58
-63
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
httptest
22
=============
33

4-
[![Build Status](https://travis-ci.org/qiniu/httptest.svg?branch=master)](https://travis-ci.org/qiniu/httptest) [![GoDoc](https://godoc.org/github.com/qiniu/httptest?status.svg)](https://godoc.org/github.com/qiniu/httptest)
4+
[![Build Status](https://travis-ci.org/qiniu/httptest.svg?branch=master)](https://travis-ci.org/qiniu/httptest) [![GoDoc](https://godoc.org/github.com/qiniu/httptest?status.svg)](https://godoc.org/github.com/qiniu/httptest) [![Go Report Card](https://goreportcard.com/badge/github.com/qiniu/httptest)](https://goreportcard.com/report/github.com/qiniu/httptest)
55

66
[![Qiniu Logo](http://open.qiniudn.com/logo.png)](http://www.qiniu.com/)
77

assert_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ func TestVar(t *testing.T) {
2222
}
2323

2424
// ---------------------------------------------------------------------------
25-

context.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ func NewRequest(ctx *Context, method, url string) *Request {
5050
ctx.DeleteVar("resp")
5151

5252
p := &Request{
53-
ctx: ctx,
53+
ctx: ctx,
5454
method: method,
55-
url: url,
55+
url: url,
5656
header: make(http.Header),
5757
}
5858
ctx.Log(" ====>", method, url)
@@ -145,9 +145,9 @@ func (p *Request) Ret(code int) (resp *Response) {
145145
resp1, err := p.send()
146146
resp = newResponse(p, resp1, err)
147147
p.ctx.MatchVar("resp", map[string]interface{}{
148-
"body": resp.BodyObj,
148+
"body": resp.BodyObj,
149149
"header": resp.Header,
150-
"code": float64(resp.StatusCode),
150+
"code": float64(resp.StatusCode),
151151
})
152152
return resp.matchCode(code)
153153
}
@@ -159,10 +159,10 @@ type TestingT interface {
159159
Log(args ...interface{})
160160
}
161161

162-
type NilTestingT struct {}
162+
type NilTestingT struct{}
163163

164164
func (p NilTestingT) Fatal(args ...interface{}) {}
165-
func (p NilTestingT) Log(args ...interface{}) {}
165+
func (p NilTestingT) Log(args ...interface{}) {}
166166

167167
// ---------------------------------------------------------------------------
168168

@@ -180,10 +180,10 @@ func New(t TestingT) *Context {
180180

181181
auths := make(map[string]TransportComposer)
182182
p := &Context{
183-
TestingT: t,
184-
auths: auths,
185-
transport: http.DefaultTransport,
186-
DefaultHeader: make(http.Header),
183+
TestingT: t,
184+
auths: auths,
185+
transport: http.DefaultTransport,
186+
DefaultHeader: make(http.Header),
187187
MatchResponseError: matchRespError,
188188
}
189189
p.initHostsMgr()
@@ -219,4 +219,3 @@ func (p *Context) Requestf(method, format string, v ...interface{}) *Request {
219219
}
220220

221221
// ---------------------------------------------------------------------------
222-

exec/multicase_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,3 @@ func TestParseCases(t *testing.T) {
6969
}
7070

7171
// ---------------------------------------------------------------------------
72-

host.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (p *hostsMgr) hostOf(url string) (host string, url2 string, ok bool) {
3535
return
3636
}
3737

38-
host = url[istart:istart+n]
38+
host = url[istart : istart+n]
3939
portal, ok := p.hostToPortals[host]
4040
if ok {
4141
url2 = url[:istart] + portal + url[istart+n:]
@@ -59,4 +59,3 @@ func (p *hostsMgr) SetHost(host string, portal string) {
5959
}
6060

6161
// ---------------------------------------------------------------------------
62-

response_test.go

+46-47
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package httptest
22

33
import (
44
"encoding/json"
5-
"testing"
65
"net/http"
6+
"testing"
77
)
88

99
// ---------------------------------------------------------------------------
@@ -30,23 +30,23 @@ func TestMatchHeader(t *testing.T) {
3030
cases := []caseMatchHeader{
3131
{
3232
expected: http.Header{"a": {"a1"}, "b": {"b1", "b2"}},
33-
real: http.Header{"c": {"c1"}, "a": {"a1"}, "b": {"b1", "b2"}, "d": {"d1"}},
34-
ok: true,
33+
real: http.Header{"c": {"c1"}, "a": {"a1"}, "b": {"b1", "b2"}, "d": {"d1"}},
34+
ok: true,
3535
},
3636
{
3737
expected: http.Header{"a": {"a1"}, "b": {"b1", "b2"}},
38-
real: http.Header{"c": {"c1"}, "a": {"a1"}, "b": {"b1"}, "d": {"d1"}},
39-
message: "unmatched response header: b",
38+
real: http.Header{"c": {"c1"}, "a": {"a1"}, "b": {"b1"}, "d": {"d1"}},
39+
message: "unmatched response header: b",
4040
},
4141
{
4242
expected: http.Header{"a": {"a1"}, "b": {"b1", "b2"}},
43-
real: http.Header{"c": {"c1"}, "a": {"a1"}, "d": {"d1"}},
44-
message: "unmatched response header: b",
43+
real: http.Header{"c": {"c1"}, "a": {"a1"}, "d": {"d1"}},
44+
message: "unmatched response header: b",
4545
},
4646
{
4747
expected: http.Header{},
48-
real: http.Header{"c": {"c1"}, "a": {"a1"}, "d": {"d1"}},
49-
ok: true,
48+
real: http.Header{"c": {"c1"}, "a": {"a1"}, "d": {"d1"}},
49+
ok: true,
5050
},
5151
}
5252
for _, c := range cases {
@@ -72,73 +72,73 @@ func TestMatchBody(t *testing.T) {
7272

7373
cases := []caseMatchBody{
7474
{
75-
expBody: ``,
76-
expBodyType: "application/json",
77-
respBody: ``,
75+
expBody: ``,
76+
expBodyType: "application/json",
77+
respBody: ``,
7878
respBodyType: "application/json",
79-
ok: true,
79+
ok: true,
8080
},
8181
{
82-
expBody: `abc`,
83-
expBodyType: "",
84-
respBody: `abc`,
82+
expBody: `abc`,
83+
expBodyType: "",
84+
respBody: `abc`,
8585
respBodyType: "application/json",
86-
ok: true,
86+
ok: true,
8787
},
8888
{
89-
expBody: `abc`,
90-
expBodyType: "application/text",
91-
respBody: `abc`,
89+
expBody: `abc`,
90+
expBodyType: "application/text",
91+
respBody: `abc`,
9292
respBodyType: "application/text",
93-
ok: true,
93+
ok: true,
9494
},
9595
{
96-
expBody: `abc`,
97-
expBodyType: "application/text",
98-
respBody: `abc`,
96+
expBody: `abc`,
97+
expBodyType: "application/text",
98+
respBody: `abc`,
9999
respBodyType: "application/json",
100-
message: "unmatched Content-Type",
100+
message: "unmatched Content-Type",
101101
},
102102
{
103-
expBody: `{}`,
104-
expBodyType: "application/json",
105-
respBody: `{ }`,
103+
expBody: `{}`,
104+
expBodyType: "application/json",
105+
respBody: `{ }`,
106106
respBodyType: "application/json",
107-
ok: true,
107+
ok: true,
108108
},
109109
{
110-
expBody: `{}`,
111-
expBodyType: "application/json",
112-
respBody: `{"aaa": "123"}`,
110+
expBody: `{}`,
111+
expBodyType: "application/json",
112+
respBody: `{"aaa": "123"}`,
113113
respBodyType: "application/json",
114-
ok: true,
114+
ok: true,
115115
},
116116
{
117-
expBody: `{"a": "a1", "b": ["b1", "b2"]}`,
118-
expBodyType: "application/json",
119-
respBody: `{"c": 1, "a": "a1", "b": ["b1", "b2"], "d": 2.0}`,
117+
expBody: `{"a": "a1", "b": ["b1", "b2"]}`,
118+
expBodyType: "application/json",
119+
respBody: `{"c": 1, "a": "a1", "b": ["b1", "b2"], "d": 2.0}`,
120120
respBodyType: "application/json",
121-
ok: true,
121+
ok: true,
122122
},
123123
{
124-
expBody: `{"a": "a1", "b": ["b1", "b2"]}`,
125-
expBodyType: "application/json",
126-
respBody: `{"c": 1, "a": "a1", "d": 2.0}`,
124+
expBody: `{"a": "a1", "b": ["b1", "b2"]}`,
125+
expBodyType: "application/json",
126+
respBody: `{"c": 1, "a": "a1", "d": 2.0}`,
127127
respBodyType: "application/json",
128-
message: "unmatched json response body - field b",
128+
message: "unmatched json response body - field b",
129129
},
130130
{
131-
expBody: `{"a": "a1", "b": ["b1", "b2"]}`,
132-
expBodyType: "application/json",
133-
respBody: `{"c": 1, "a": "a1", "b": [1], "d": 2.0}`,
131+
expBody: `{"a": "a1", "b": ["b1", "b2"]}`,
132+
expBodyType: "application/json",
133+
respBody: `{"c": 1, "a": "a1", "b": [1], "d": 2.0}`,
134134
respBodyType: "application/json",
135-
message: "unmatched json response body - field b",
135+
message: "unmatched json response body - field b",
136136
},
137137
}
138138
for _, c := range cases {
139139
resp := &Response{
140140
RawBody: []byte(c.respBody),
141-
Header: make(http.Header),
141+
Header: make(http.Header),
142142
}
143143
if c.respBodyType != "" {
144144
resp.BodyType = c.respBodyType
@@ -157,4 +157,3 @@ func TestMatchBody(t *testing.T) {
157157
}
158158

159159
// ---------------------------------------------------------------------------
160-

0 commit comments

Comments
 (0)