Skip to content

Commit aaee1b4

Browse files
authored
Merge pull request #2 from fastbill/change-linter
change linter
2 parents 1b27aa7 + d4e904b commit aaee1b4

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

.golangci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
linters:
2+
enable:
3+
- gocyclo
4+
- golint
5+
- dupl
6+
- interfacer
7+
- unconvert
8+
- goconst
9+
- gosec
10+
- bodyclose
11+
12+
run:
13+
deadline: 10m
14+
15+
issues:
16+
exclude-rules:
17+
- path: _test\.go
18+
linters:
19+
- dupl
20+
- goconst
21+
- gosec

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ language: go
33
go:
44
- 1.11.x
55

6-
before_install:
6+
install:
77
- go get -u github.com/golang/dep/cmd/dep
88
- dep ensure
9-
- go get -u gopkg.in/alecthomas/gometalinter.v2
10-
- gometalinter.v2 --install
9+
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.17.1
1110

1211
script:
1312
- go test -race -cover ./...
14-
- gometalinter.v2 --vendor --deadline=300s ./...
13+
- ./bin/golangci-lint run
1514

1615
notifications:
1716
email: false

request_test.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ func TestGetClient(t *testing.T) {
3939
w.WriteHeader(http.StatusSeeOther)
4040
}))
4141
stdClient := http.Client{}
42-
_, err := stdClient.Get(ts.URL)
42+
r, err := stdClient.Get(ts.URL)
4343
assert.Error(t, err)
44+
r.Body.Close()
4445

4546
client := GetClient()
4647
res, err := client.Get(ts.URL)
4748
assert.Equal(t, "/////", res.Header.Get("Location"))
49+
res.Body.Close()
4850
assert.NoError(t, err)
4951
})
5052
}
@@ -61,7 +63,8 @@ func TestDoSuccessful(t *testing.T) {
6163
body, _ := ioutil.ReadAll(r.Body)
6264
assert.Equal(t, `{"requestValue":"someValueIn"}`+"\n", string(body))
6365
assert.Equal(t, r.Method, "POST")
64-
w.Write([]byte(`{"responseValue":"someValueOut"}`))
66+
_, err := w.Write([]byte(`{"responseValue":"someValueOut"}`))
67+
assert.NoError(t, err)
6568
}))
6669
defer ts.Close()
6770

@@ -100,7 +103,8 @@ func TestDoSuccessful(t *testing.T) {
100103
t.Run("no request body", func(t *testing.T) {
101104
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
102105
assert.Equal(t, r.Method, "POST")
103-
w.Write([]byte(`{"responseValue":"someValueOut"}`))
106+
_, err := w.Write([]byte(`{"responseValue":"someValueOut"}`))
107+
assert.NoError(t, err)
104108
}))
105109
defer ts.Close()
106110

@@ -157,7 +161,8 @@ func TestDoSuccessful(t *testing.T) {
157161
body, _ := ioutil.ReadAll(r.Body)
158162
assert.Equal(t, `{"requestValue":"someValueIn"}`, string(body))
159163
assert.Equal(t, r.Method, "POST")
160-
w.Write([]byte(`{"responseValue":"someValueOut"}`))
164+
_, err := w.Write([]byte(`{"responseValue":"someValueOut"}`))
165+
assert.NoError(t, err)
161166
}))
162167
defer ts.Close()
163168

@@ -231,7 +236,8 @@ func TestDoHTTPErrors(t *testing.T) {
231236
t.Run("non 2xx response with body", func(t *testing.T) {
232237
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
233238
w.WriteHeader(http.StatusBadRequest)
234-
w.Write([]byte("some error message"))
239+
_, err := w.Write([]byte("some error message"))
240+
assert.NoError(t, err)
235241
}))
236242
defer ts.Close()
237243

@@ -278,7 +284,8 @@ func TestDoOtherErrors(t *testing.T) {
278284
func TestGet(t *testing.T) {
279285
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
280286
assert.Equal(t, r.Method, "GET")
281-
w.Write([]byte(`{"responseValue":"someValueOut"}`))
287+
_, err := w.Write([]byte(`{"responseValue":"someValueOut"}`))
288+
assert.NoError(t, err)
282289
}))
283290
defer ts.Close()
284291

@@ -293,7 +300,8 @@ func TestPost(t *testing.T) {
293300
body, _ := ioutil.ReadAll(r.Body)
294301
assert.Equal(t, `{"requestValue":"someValueIn"}`+"\n", string(body))
295302
assert.Equal(t, r.Method, "POST")
296-
w.Write([]byte(`{"responseValue":"someValueOut"}`))
303+
_, err := w.Write([]byte(`{"responseValue":"someValueOut"}`))
304+
assert.NoError(t, err)
297305
}))
298306
defer ts.Close()
299307

@@ -307,7 +315,10 @@ func ExampleDo() {
307315
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
308316
body, _ := ioutil.ReadAll(r.Body)
309317
fmt.Println(string(body))
310-
w.Write([]byte(`{"responseValue":"someValueOut"}`))
318+
_, err := w.Write([]byte(`{"responseValue":"someValueOut"}`))
319+
if err != nil {
320+
panic(err)
321+
}
311322
}))
312323
defer ts.Close()
313324

0 commit comments

Comments
 (0)