Skip to content

Commit dc21346

Browse files
committed
test: use golangci-lint v2.0.2
Signed-off-by: Maxime Soulé <[email protected]>
1 parent 8cdfbf1 commit dc21346

10 files changed

Lines changed: 93 additions & 76 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ jobs:
1111
test:
1212
strategy:
1313
matrix:
14-
go-version: [1.16.x, 1.17.x, 1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x, tip]
14+
go-version: [1.16.x, 1.17.x, 1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x, 1.23.x, tip]
1515
full-tests: [false]
1616
include:
17-
- go-version: 1.23.x
17+
- go-version: 1.24.x
1818
full-tests: true
1919

2020
runs-on: ubuntu-latest
2121

2222
steps:
2323
- name: Setup go
2424
run: |
25-
curl -sL https://raw.githubusercontent.com/maxatome/install-go/v3.6/install-go.pl |
25+
curl -sL https://raw.githubusercontent.com/maxatome/install-go/v3.7/install-go.pl |
2626
perl - ${{ matrix.go-version }} $HOME/go
2727
2828
- name: Checkout code
@@ -32,24 +32,8 @@ jobs:
3232
if: matrix.full-tests
3333
run: |
3434
curl -sL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh |
35-
sh -s -- -b $HOME/go/bin v1.61.0
36-
$HOME/go/bin/golangci-lint run --max-issues-per-linter 0 \
37-
--max-same-issues 0 \
38-
--exclude="unused-parameter: parameter '[^']+' seems to be unused, consider removing or renaming it as _" \
39-
-E asciicheck \
40-
-E bidichk \
41-
-E durationcheck \
42-
-E exportloopref \
43-
-E gocritic \
44-
-E godot \
45-
-E goimports \
46-
-E govet \
47-
-E misspell \
48-
-E prealloc \
49-
-E revive \
50-
-E unconvert \
51-
-E whitespace \
52-
./...
35+
sh -s -- -b $HOME/go/bin v2.0.2
36+
$HOME/go/bin/golangci-lint run
5337
5438
- name: Testing
5539
continue-on-error: ${{ matrix.go-version == 'tip' }}

.golangci.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
version: "2"
2+
issues:
3+
max-issues-per-linter: 0
4+
max-same-issues: 0
5+
linters:
6+
default: none
7+
enable:
8+
- asasalint
9+
- asciicheck
10+
- bidichk
11+
- dupl
12+
- durationcheck
13+
- errcheck
14+
- exhaustive
15+
- gocritic
16+
- godot
17+
- govet
18+
- importas
19+
- ineffassign
20+
- misspell
21+
- prealloc
22+
- revive
23+
- staticcheck
24+
- testableexamples
25+
- unconvert
26+
- unused
27+
- wastedassign
28+
- whitespace
29+
settings:
30+
staticcheck:
31+
checks:
32+
- all
33+
- -ST1012
34+
- -ST1000
35+
revive:
36+
rules:
37+
- name: unused-parameter
38+
disabled: true
39+
formatters:
40+
enable:
41+
- gci
42+
- goimports
43+
settings:
44+
gci:
45+
sections:
46+
- standard
47+
- default
48+
- localmodule
49+
custom-order: true

file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package httpmock
22

33
import (
44
"fmt"
5-
"io/ioutil" //nolint: staticcheck
5+
"os"
66
)
77

88
// File is a file name. The contents of this file is loaded on demand
@@ -32,7 +32,7 @@ func (f File) MarshalJSON() ([]byte, error) {
3232
}
3333

3434
func (f File) bytes() ([]byte, error) {
35-
return ioutil.ReadFile(string(f))
35+
return os.ReadFile(string(f))
3636
}
3737

3838
// Bytes returns the content of file as a []byte. If an error occurs

file_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ var _ json.Marshaler = httpmock.File("test.json")
1515
func TestFile(t *testing.T) {
1616
assert := td.Assert(t)
1717

18-
dir, cleanup := tmpDir(assert)
19-
defer cleanup()
18+
dir := assert.TempDir()
2019

2120
assert.Run("Valid JSON file", func(assert *td.T) {
2221
okFile := filepath.Join(dir, "ok.json")

match.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"fmt"
66
"io"
7-
"io/ioutil" //nolint: staticcheck
87
"net/http"
98
"runtime"
109
"strings"
@@ -227,7 +226,7 @@ func BodyContainsBytes(subslice []byte) Matcher {
227226
return NewMatcher("",
228227
func(req *http.Request) bool {
229228
rearmBody(req)
230-
b, err := ioutil.ReadAll(req.Body)
229+
b, err := io.ReadAll(req.Body)
231230
return err == nil && bytes.Contains(b, subslice)
232231
})
233232
}
@@ -247,7 +246,7 @@ func BodyContainsString(substr string) Matcher {
247246
return NewMatcher("",
248247
func(req *http.Request) bool {
249248
rearmBody(req)
250-
b, err := ioutil.ReadAll(req.Body)
249+
b, err := io.ReadAll(req.Body)
251250
return err == nil && bytes.Contains(b, []byte(substr))
252251
})
253252
}
@@ -500,8 +499,8 @@ func (b *bodyCopyOnRead) rearm() {
500499

501500
func (b *bodyCopyOnRead) copy() {
502501
if _, ok := b.body.(buffer); !ok && b.body != nil && b.body != http.NoBody {
503-
buf, _ := ioutil.ReadAll(b.body)
504-
b.body.Close()
502+
buf, _ := io.ReadAll(b.body)
503+
b.body.Close() //nolint: errcheck
505504
b.body = buffer{bytes.NewReader(buf)}
506505
}
507506
}

match_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"errors"
66
"fmt"
77
"io"
8-
"io/ioutil" //nolint: staticcheck
98
"net/http"
109
"reflect"
1110
"strings"
@@ -300,7 +299,7 @@ func TestMatchResponders_add_remove(t *testing.T) {
300299

301300
func TestMatchResponders_findMatchResponder(t *testing.T) {
302301
newReq := func() *http.Request {
303-
req, _ := http.NewRequest("GET", "/foo", ioutil.NopCloser(bytes.NewReader([]byte(`BODY`))))
302+
req, _ := http.NewRequest("GET", "/foo", io.NopCloser(bytes.NewReader([]byte(`BODY`))))
304303
req.Header.Set("X-Foo", "bar")
305304
return req
306305
}
@@ -353,7 +352,7 @@ func TestMatchResponders_findMatchResponder(t *testing.T) {
353352

354353
mrBody1 := httpmock.NewMatchResponder(
355354
httpmock.NewMatcher("body-FOO", func(req *http.Request) bool {
356-
b, err := ioutil.ReadAll(req.Body)
355+
b, err := io.ReadAll(req.Body)
357356
return err == nil && bytes.Equal(b, []byte("FOO"))
358357
}),
359358
resp)
@@ -364,7 +363,7 @@ func TestMatchResponders_findMatchResponder(t *testing.T) {
364363

365364
mrBody2 := httpmock.NewMatchResponder(
366365
httpmock.NewMatcher("body-BODY", func(req *http.Request) bool {
367-
b, err := ioutil.ReadAll(req.Body)
366+
b, err := io.ReadAll(req.Body)
368367
return err == nil && bytes.Equal(b, []byte("BODY"))
369368
}),
370369
resp)
@@ -374,7 +373,7 @@ func TestMatchResponders_findMatchResponder(t *testing.T) {
374373
assert.Cmp(mrs.FindMatchResponder(req), &mrBody2)
375374

376375
// The request body should still be readable
377-
b, err := ioutil.ReadAll(req.Body)
376+
b, err := io.ReadAll(req.Body)
378377
assert.CmpNoError(err)
379378
assert.String(b, "BODY")
380379
}
@@ -401,7 +400,7 @@ func TestMatchRouteKey(t *testing.T) {
401400

402401
func TestBodyCopyOnRead(t *testing.T) {
403402
t.Run("non-nil body", func(t *testing.T) {
404-
body := ioutil.NopCloser(bytes.NewReader([]byte(`BODY`)))
403+
body := io.NopCloser(bytes.NewReader([]byte(`BODY`)))
405404

406405
bc := httpmock.NewBodyCopyOnRead(body)
407406

response.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ func NewBytesResponder(status int, body []byte) Responder {
576576
// To pass the content of an existing file as body use [File] as in:
577577
//
578578
// httpmock.NewJsonResponse(200, httpmock.File("body.json"))
579-
func NewJsonResponse(status int, body any) (*http.Response, error) { //nolint: revive
579+
func NewJsonResponse(status int, body any) (*http.Response, error) { //nolint: revive,staticcheck
580580
encoded, err := json.Marshal(body)
581581
if err != nil {
582582
return nil, err
@@ -604,7 +604,7 @@ func NewJsonResponse(status int, body any) (*http.Response, error) { //nolint: r
604604
// To pass the content of an existing file as body use [File] as in:
605605
//
606606
// httpmock.NewJsonResponseOrPanic(200, httpmock.File("body.json"))
607-
func NewJsonResponseOrPanic(status int, body any) *http.Response { //nolint: revive
607+
func NewJsonResponseOrPanic(status int, body any) *http.Response { //nolint: revive,staticcheck
608608
response, err := NewJsonResponse(status, body)
609609
if err != nil {
610610
panic(err)
@@ -618,7 +618,7 @@ func NewJsonResponseOrPanic(status int, body any) *http.Response { //nolint: rev
618618
// To pass the content of an existing file as body use [File] as in:
619619
//
620620
// httpmock.NewJsonResponder(200, httpmock.File("body.json"))
621-
func NewJsonResponder(status int, body any) (Responder, error) { //nolint: revive
621+
func NewJsonResponder(status int, body any) (Responder, error) { //nolint: revive,staticcheck
622622
resp, err := NewJsonResponse(status, body)
623623
if err != nil {
624624
return nil, err
@@ -642,7 +642,7 @@ func NewJsonResponder(status int, body any) (Responder, error) { //nolint: reviv
642642
// To pass the content of an existing file as body use [File] as in:
643643
//
644644
// httpmock.NewJsonResponderOrPanic(200, httpmock.File("body.json"))
645-
func NewJsonResponderOrPanic(status int, body any) Responder { //nolint: revive
645+
func NewJsonResponderOrPanic(status int, body any) Responder { //nolint: revive,staticcheck
646646
responder, err := NewJsonResponder(status, body)
647647
if err != nil {
648648
panic(err)
@@ -657,7 +657,7 @@ func NewJsonResponderOrPanic(status int, body any) Responder { //nolint: revive
657657
// To pass the content of an existing file as body use [File] as in:
658658
//
659659
// httpmock.NewXmlResponse(200, httpmock.File("body.xml"))
660-
func NewXmlResponse(status int, body any) (*http.Response, error) { //nolint: revive
660+
func NewXmlResponse(status int, body any) (*http.Response, error) { //nolint: revive,staticcheck
661661
var (
662662
encoded []byte
663663
err error
@@ -681,7 +681,7 @@ func NewXmlResponse(status int, body any) (*http.Response, error) { //nolint: re
681681
// To pass the content of an existing file as body use [File] as in:
682682
//
683683
// httpmock.NewXmlResponder(200, httpmock.File("body.xml"))
684-
func NewXmlResponder(status int, body any) (Responder, error) { //nolint: revive
684+
func NewXmlResponder(status int, body any) (Responder, error) { //nolint: revive,staticcheck
685685
resp, err := NewXmlResponse(status, body)
686686
if err != nil {
687687
return nil, err
@@ -705,7 +705,7 @@ func NewXmlResponder(status int, body any) (Responder, error) { //nolint: revive
705705
// To pass the content of an existing file as body use [File] as in:
706706
//
707707
// httpmock.NewXmlResponderOrPanic(200, httpmock.File("body.xml"))
708-
func NewXmlResponderOrPanic(status int, body any) Responder { //nolint: revive
708+
func NewXmlResponderOrPanic(status int, body any) Responder { //nolint: revive,staticcheck
709709
responder, err := NewXmlResponder(status, body)
710710
if err != nil {
711711
panic(err)
@@ -759,7 +759,7 @@ func (d *dummyReadCloser) setup() {
759759
case io.ReadCloser:
760760
var buf bytes.Buffer
761761
io.Copy(&buf, body) //nolint: errcheck
762-
body.Close()
762+
body.Close() //nolint: errcheck
763763
d.body = bytes.NewReader(buf.Bytes())
764764
}
765765
}

response_test.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"errors"
66
"fmt"
77
"io"
8-
"io/ioutil" //nolint: staticcheck
98
"net/http"
109
"path/filepath"
1110
"strconv"
@@ -137,7 +136,7 @@ func TestNewStringResponse(t *testing.T) {
137136
)
138137
response := httpmock.NewStringResponse(status, body)
139138

140-
data, err := ioutil.ReadAll(response.Body)
139+
data, err := io.ReadAll(response.Body)
141140
require.CmpNoError(err)
142141

143142
assert.String(data, body)
@@ -153,7 +152,7 @@ func TestNewBytesResponse(t *testing.T) {
153152
)
154153
response := httpmock.NewBytesResponse(status, []byte(body))
155154

156-
data, err := ioutil.ReadAll(response.Body)
155+
data, err := io.ReadAll(response.Body)
157156
require.CmpNoError(err)
158157

159158
assert.String(data, body)
@@ -167,8 +166,7 @@ func TestNewJsonResponse(t *testing.T) {
167166
Hello string `json:"hello"`
168167
}
169168

170-
dir, cleanup := tmpDir(assert)
171-
defer cleanup()
169+
dir := assert.TempDir()
172170
fileName := filepath.Join(dir, "ok.json")
173171
writeFile(assert, fileName, []byte(`{ "test": true }`))
174172

@@ -203,8 +201,7 @@ func TestNewJsonResponseOrPanic(t *testing.T) {
203201
Hello string `json:"hello"`
204202
}
205203

206-
dir, cleanup := tmpDir(assert)
207-
defer cleanup()
204+
dir := assert.TempDir()
208205
fileName := filepath.Join(dir, "ok.json")
209206
writeFile(assert, fileName, []byte(`{ "test": true }`))
210207

@@ -261,8 +258,7 @@ func TestNewJsonResponder(t *testing.T) {
261258
})
262259

263260
assert.Run("OK file", func(assert *td.T) {
264-
dir, cleanup := tmpDir(assert)
265-
defer cleanup()
261+
dir := assert.TempDir()
266262
fileName := filepath.Join(dir, "ok.json")
267263
writeFile(assert, fileName, []byte(`{ "foo" : 42 }`))
268264

@@ -308,8 +304,7 @@ func TestNewXmlResponse(t *testing.T) {
308304
}
309305
expectedBody := string(b)
310306

311-
dir, cleanup := tmpDir(assert)
312-
defer cleanup()
307+
dir := assert.TempDir()
313308
fileName := filepath.Join(dir, "ok.xml")
314309
writeFile(assert, fileName, b)
315310

@@ -354,8 +349,7 @@ func TestNewXmlResponder(t *testing.T) {
354349
})
355350

356351
assert.Run("OK file", func(assert *td.T) {
357-
dir, cleanup := tmpDir(assert)
358-
defer cleanup()
352+
dir := assert.TempDir()
359353
fileName := filepath.Join(dir, "ok.xml")
360354
writeFile(assert, fileName, b)
361355

@@ -568,7 +562,7 @@ func TestResponder_Then(t *testing.T) {
568562
if !assert.CmpNoError(err, "Responder call") {
569563
return
570564
}
571-
b, err := ioutil.ReadAll(resp.Body)
565+
b, err := io.ReadAll(resp.Body)
572566
if !assert.CmpNoError(err, "Read response") {
573567
return
574568
}
@@ -673,7 +667,7 @@ func TestResponder_SetContentLength(t *testing.T) {
673667
name: "custom without Len",
674668
r: func(req *http.Request) (*http.Response, error) {
675669
return &http.Response{
676-
Body: ioutil.NopCloser(strings.NewReader("BODY")),
670+
Body: io.NopCloser(strings.NewReader("BODY")),
677671
StatusCode: 200,
678672
ContentLength: -1,
679673
}, nil
@@ -803,7 +797,7 @@ func TestParallelResponder(t *testing.T) {
803797
go func() {
804798
defer wg.Done()
805799
resp, _ := r(req)
806-
b, err := ioutil.ReadAll(resp.Body)
800+
b, err := io.ReadAll(resp.Body)
807801
td.CmpNoError(t, err, "resp #%d", ir)
808802
td.CmpLen(t, b, 4000, "resp #%d", ir)
809803
td.CmpHasPrefix(t, b, "ABC-", "resp #%d", ir)

0 commit comments

Comments
 (0)