Skip to content

Commit 92d9cc9

Browse files
CI improvements and fix deprecations (#235)
* update test matrix, drop 1.18 and 1.19, adds 1.23 Signed-off-by: Pedro Tanaka <[email protected]> * Update golangci and fix deprecation problems Signed-off-by: Pedro Tanaka <[email protected]> * update golanglint-ci to latest Signed-off-by: Pedro Tanaka <[email protected]> * fixing test Signed-off-by: Pedro Tanaka <[email protected]> --------- Signed-off-by: Pedro Tanaka <[email protected]>
1 parent 5720ada commit 92d9cc9

File tree

7 files changed

+38
-37
lines changed

7 files changed

+38
-37
lines changed

.github/workflows/go.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: golangci-lint
2222
uses: golangci/golangci-lint-action@v5
2323
with:
24-
version: v1.55.2
24+
version: v1.61.0
2525

2626
mod-tidy:
2727
name: Go Mod Tidy
@@ -57,10 +57,10 @@ jobs:
5757
strategy:
5858
matrix:
5959
go-version:
60-
- 1.18.x # EOL: 01 Feb 2023
61-
- 1.19.x # EOL: 08 Aug 2023
62-
- 1.20.x
63-
- 1.21.x
60+
- 1.20.x # EOL: 06 Feb 2024
61+
- 1.21.x # EOL: 13 Aug 2024
62+
- 1.22.x
63+
- 1.23.x
6464

6565
steps:
6666
- name: Checkout

.golangci.yml

+14-9
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
run:
44
timeout: 5m
55

6-
skip-files:
7-
- ".*_mock\\.go$"
8-
- "\\.pb\\.go$"
9-
106
output:
11-
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
12-
format: colored-line-number
7+
formats:
8+
- format: colored-line-number
9+
path: stdout
1310

1411
linters:
1512
enable:
@@ -21,13 +18,15 @@ linters:
2118
- gosec
2219
- govet
2320
- lll
24-
- megacheck
2521
- misspell
2622
- nakedret
2723
- prealloc
2824
- stylecheck
2925
- unconvert
3026
- unparam
27+
- gosimple
28+
- staticcheck
29+
- unused
3130

3231
linters-settings:
3332
dupl:
@@ -45,8 +44,14 @@ linters-settings:
4544
line-length: 140
4645
maligned:
4746
suggest-new: true
48-
47+
gosec:
48+
excludes:
49+
- G115
4950
issues:
51+
exclude-files:
52+
- ".*_mock\\.go$"
53+
- "\\.pb\\.go$"
54+
5055
exclude-rules:
5156
- path: _test\.go
5257
linters:
@@ -64,4 +69,4 @@ issues:
6469

6570
- linters:
6671
- lll
67-
source: "^//go:generate "
72+
source: "^//go:generate "

logrusbugsnag/bugsnag_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package logrusbugsnag
33
import (
44
"bytes"
55
"errors"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"sync"
99
"testing"
@@ -25,15 +25,15 @@ type nilRoundTripper struct{}
2525

2626
func (rt *nilRoundTripper) RoundTrip(_ *http.Request) (*http.Response, error) {
2727
return &http.Response{
28-
Body: ioutil.NopCloser(bytes.NewReader(nil)),
28+
Body: io.NopCloser(bytes.NewReader(nil)),
2929
StatusCode: http.StatusOK,
3030
}, nil
3131
}
3232

3333
func setup(record bool) {
3434
testOnce.Do(func() {
3535
l := logrus.New()
36-
l.Out = ioutil.Discard
36+
l.Out = io.Discard
3737

3838
bugsnag.Configure(bugsnag.Configuration{
3939
APIKey: testAPIKey,
@@ -57,7 +57,7 @@ func BenchmarkHook_Fire(b *testing.B) {
5757
setup(false)
5858

5959
l := logrus.New()
60-
l.Out = ioutil.Discard
60+
l.Out = io.Discard
6161

6262
hook, err := NewBugsnagHook(nil)
6363
assert.NoError(b, err)
@@ -89,7 +89,7 @@ func TestNewBugsnagHook(t *testing.T) {
8989
setup(true)
9090

9191
l := logrus.New()
92-
l.Out = ioutil.Discard
92+
l.Out = io.Discard
9393

9494
hook, err := NewBugsnagHook(nil)
9595
assert.NoError(t, err)

profiler/ui.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package profiler
33
import (
44
"context"
55
"errors"
6-
"io/ioutil"
76
"net/http"
87
"net/http/httptest"
98
httppprof "net/http/pprof"
@@ -19,7 +18,7 @@ func pprofUIHandler(w http.ResponseWriter, r *http.Request) {
1918
ctx := r.Context()
2019
vars := mux.Vars(r)
2120

22-
f, err := ioutil.TempFile("", "pprof.*.pb")
21+
f, err := os.CreateTemp("", "pprof.*.pb")
2322
if err != nil {
2423
log(ctx, err).Error("error creating temporary file")
2524
http.Error(w, err.Error(), http.StatusInternalServerError)

shell/shell_test.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import (
55
"context"
66
"fmt"
77
"io"
8-
"io/ioutil"
9-
"path/filepath"
108
"sync"
119
"syscall"
1210
"testing"
1311
"time"
1412

1513
"github.com/stretchr/testify/assert"
14+
"github.com/stretchr/testify/require"
1615
)
1716

1817
func ExampleSupervisor_Wait() {
@@ -25,7 +24,7 @@ func ExampleSupervisor_Wait() {
2524
stdin.Write([]byte("foo"))
2625
stdin.Close()
2726

28-
output, _ := ioutil.ReadAll(stdout)
27+
output, _ := io.ReadAll(stdout)
2928

3029
// Must call Wait _after_ interacting with pipes
3130
cmd.Wait()
@@ -142,7 +141,7 @@ func TestCommandRunPipe(t *testing.T) {
142141
assert.NotEqual(t, 0, c.Process.Pid) // But the process exists
143142

144143
// Calling ReadAll will wait for the pipe to close, so all the output is there.
145-
output, err := ioutil.ReadAll(pipe)
144+
output, err := io.ReadAll(pipe)
146145
assert.NoError(t, err)
147146
assert.Equal(t, []byte("foo"), output)
148147

@@ -172,21 +171,20 @@ func TestCommandRunWaitPipeFails(t *testing.T) {
172171
assert.True(t, c.ProcessState.Exited())
173172

174173
// Calling ReadAll will wait for the pipe to close, so all the output is there.
175-
_, err = ioutil.ReadAll(pipe)
174+
_, err = io.ReadAll(pipe)
176175
assert.Error(t, err, "read |0: file already closed")
177176
}
178177

179178
func TestCommandWithWorkingDir(t *testing.T) {
179+
tempDir := t.TempDir()
180180
ctx := context.Background()
181181
stdout, _, err := NewBuilder(ctx, "pwd").
182-
WithWorkingDir("/tmp").
182+
WithWorkingDir(tempDir).
183183
Prepare().
184184
RunAndGetOutput()
185185

186-
assert.NoError(t, err)
187-
expected, err := filepath.EvalSymlinks("/tmp")
188-
assert.NoError(t, err)
189-
assert.Equal(t, []byte(expected+"\n"), stdout)
186+
require.NoError(t, err)
187+
assert.Equal(t, []byte(tempDir+"\n"), stdout)
190188
}
191189

192190
func TestCommandEnvDoesNotEval(t *testing.T) {

srvutil/metrics_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"bytes"
66
"context"
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"net"
1010
"net/http"
1111
"net/http/httptest"
@@ -72,7 +72,7 @@ func TestRequestMetricsMiddleware(t *testing.T) {
7272
res, err := http.DefaultClient.Do(req)
7373
assert.NoError(t, err)
7474
assert.Equal(t, http.StatusOK, res.StatusCode)
75-
body, err := ioutil.ReadAll(res.Body)
75+
body, err := io.ReadAll(res.Body)
7676
assert.NoError(t, err)
7777
assert.Equal(t, "hello world", string(body))
7878

srvutil/server_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"errors"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"net/http"
98
"os"
109
"strings"
@@ -73,7 +72,7 @@ func TestNewServer(t *testing.T) {
7372
res, err := http.Get(u)
7473
assert.NoError(t, err)
7574
assert.Equal(t, http.StatusOK, res.StatusCode)
76-
body, err := ioutil.ReadAll(res.Body)
75+
body, err := io.ReadAll(res.Body)
7776
assert.NoError(t, err)
7877
assert.Equal(t, "great success", string(body))
7978

@@ -136,7 +135,7 @@ func TestNewServerFromFactory(t *testing.T) {
136135
res, err := http.Get(u)
137136
assert.NoError(t, err)
138137
assert.Equal(t, http.StatusOK, res.StatusCode)
139-
body, err := ioutil.ReadAll(res.Body)
138+
body, err := io.ReadAll(res.Body)
140139
assert.NoError(t, err)
141140
assert.Equal(t, "great success", string(body))
142141

@@ -214,7 +213,7 @@ func TestStoppableKeepaliveListener_Accept(t *testing.T) {
214213
res, err := http.Get(u) // This will block on tb.Dying()
215214
assert.NoError(t, err)
216215
assert.Equal(t, http.StatusOK, res.StatusCode)
217-
body, err := ioutil.ReadAll(res.Body)
216+
body, err := io.ReadAll(res.Body)
218217
assert.NoError(t, err)
219218
assert.Equal(t, "great success", string(body))
220219
close(done)

0 commit comments

Comments
 (0)