Skip to content
This repository was archived by the owner on Sep 27, 2020. It is now read-only.

Commit 2d17c35

Browse files
committed
style: adjustment
1 parent f5a9996 commit 2d17c35

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ test:
66
lint:
77
golangci-lint run # -v --enable-all
88

9+
format:
10+
goimports -w $(shell git ls-files | grep ".go$$")
11+
912
# example (for testing)
1013
httpbin:
1114
cd examples/00httpbin && go run ./cmd/httpbin/main.go localhost:8080

integration_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type Input struct {
2222
Values []int
2323
}
2424

25-
func Add(w http.ResponseWriter, req *http.Request) {
25+
func handleAdd(w http.ResponseWriter, req *http.Request) {
2626
var data Input
2727
decoder := json.NewDecoder(req.Body)
2828
if err := decoder.Decode(&data); err != nil {
@@ -44,12 +44,12 @@ func Add(w http.ResponseWriter, req *http.Request) {
4444

4545
func TestHandler(t *testing.T) {
4646
t.Run("plain", func(t *testing.T) {
47-
w := httptest.NewRecorder()
47+
rec := httptest.NewRecorder()
4848
req := httptest.NewRequest("POST", "/", bytes.NewBufferString(`{"values": [1,2,3]}`))
4949
req.Header.Set("Content-Type", "application/json")
5050

51-
Add(w, req)
52-
res := w.Result()
51+
handleAdd(rec, req)
52+
res := rec.Result()
5353

5454
if res.StatusCode != 200 {
5555
b, _ := ioutil.ReadAll(res.Body)
@@ -70,7 +70,7 @@ func TestHandler(t *testing.T) {
7070
})
7171

7272
t.Run("webtest", func(t *testing.T) {
73-
c := webtest.NewClientFromHandler(http.HandlerFunc(Add))
73+
c := webtest.NewClientFromHandler(http.HandlerFunc(handleAdd))
7474
var want interface{}
7575
got, err := c.Post("/",
7676
webtest.WithJSONString(`{"values": [1,2,3]}`),
@@ -91,7 +91,7 @@ func TestHandler(t *testing.T) {
9191
})
9292

9393
t.Run("try", func(t *testing.T) {
94-
c := webtest.NewClientFromHandler(http.HandlerFunc(Add))
94+
c := webtest.NewClientFromHandler(http.HandlerFunc(handleAdd))
9595

9696
var want interface{}
9797
try.It{

readme.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
func TestWithWebtest(t *testing.T) {
30-
c := webtest.NewClientFromHandler(http.HandlerFunc(Add))
30+
c := webtest.NewClientFromHandler(http.HandlerFunc(handleAdd))
3131
var want interface{}
3232
got, err := c.Post("/",
3333
webtest.WithJSON(bytes.NewBufferString(`{"values": [1,2,3]}`)),
@@ -61,7 +61,7 @@ import (
6161

6262

6363
func TestWithTry(t *testing.T) {
64-
c := webtest.NewClientFromHandler(http.HandlerFunc(Add))
64+
c := webtest.NewClientFromHandler(http.HandlerFunc(handleAdd))
6565

6666
var want interface{}
6767
try.It{
@@ -80,7 +80,7 @@ func TestWithTry(t *testing.T) {
8080
If modify response is not needed, it is also ok, when the response does not include *semi-random value* (for example the value of now time).
8181

8282
```go
83-
c := webtest.NewClientFromHandler(http.HandlerFunc(Add))
83+
c := webtest.NewClientFromHandler(http.HandlerFunc(handleAdd))
8484

8585
var want interface{}
8686
try.It{
@@ -108,12 +108,12 @@ import (
108108
)
109109

110110
func TestWithoutWebtest(t *testing.T) {
111-
w := httptest.NewRecorder()
111+
rec := httptest.NewRecorder()
112112
req := httptest.NewRequest("POST", "/", bytes.NewBufferString(`{"values": [1,2,3]}`))
113113
req.Header.Set("Content-Type", "application/json")
114114

115-
Add(w, req)
116-
res := w.Result()
115+
handleAdd(rec, req)
116+
res := rec.Result()
117117

118118
if res.StatusCode != 200 {
119119
b, _ := ioutil.ReadAll(res.Body)

testclient/response.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ type Response interface {
2121

2222
Raw() *http.Response
2323

24-
// Extractor
25-
// }
24+
// Extractor
25+
// }
2626

27-
// // Extractor :
28-
// type Extractor interface {
27+
// // Extractor :
28+
// type Extractor interface {
2929
ParseJSONData(val interface{}) error
3030
JSONData() interface{}
3131

0 commit comments

Comments
 (0)