Skip to content

Commit f32c107

Browse files
committed
Update lint rules, force testify/assert for tests
Use testify's assert package instead of the standard library's testing package.
1 parent dd072ed commit f32c107

28 files changed

+391
-872
lines changed

.golangci.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ linters-settings:
1919
recommendations:
2020
- errors
2121
forbidigo:
22+
analyze-types: true
2223
forbid:
2324
- ^fmt.Print(f|ln)?$
2425
- ^log.(Panic|Fatal|Print)(f|ln)?$
2526
- ^os.Exit$
2627
- ^panic$
2728
- ^print(ln)?$
29+
- p: ^testing.T.(Error|Errorf|Fatal|Fatalf|Fail|FailNow)$
30+
pkg: ^testing$
31+
msg: "use testify/assert instead"
2832
varnamelen:
2933
max-distance: 12
3034
min-name-length: 2
@@ -127,9 +131,12 @@ issues:
127131
exclude-dirs-use-default: false
128132
exclude-rules:
129133
# Allow complex tests and examples, better to be self contained
130-
- path: (examples|main\.go|_test\.go)
134+
- path: (examples|main\.go)
131135
linters:
136+
- gocognit
132137
- forbidigo
138+
- path: _test\.go
139+
linters:
133140
- gocognit
134141

135142
# Allow forbidden identifiers in CLI commands

active_tcp_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func TestActiveTCP(t *testing.T) {
147147
req.NoError(err)
148148
req.NotNil(activeAgent)
149149

150-
passiveAgentConn, activeAgenConn := connect(passiveAgent, activeAgent)
150+
passiveAgentConn, activeAgenConn := connect(t, passiveAgent, activeAgent)
151151
req.NotNil(passiveAgentConn)
152152
req.NotNil(activeAgenConn)
153153

@@ -220,7 +220,7 @@ func TestActiveTCP_NonBlocking(t *testing.T) {
220220
require.NoError(t, aAgent.AddRemoteCandidate(invalidCandidate))
221221
require.NoError(t, bAgent.AddRemoteCandidate(invalidCandidate))
222222

223-
connect(aAgent, bAgent)
223+
connect(t, aAgent, bAgent)
224224

225225
<-isConnected
226226
}
@@ -284,7 +284,7 @@ func TestActiveTCP_Respect_NetworkTypes(t *testing.T) {
284284
require.NoError(t, aAgent.AddRemoteCandidate(invalidCandidate))
285285
require.NoError(t, bAgent.AddRemoteCandidate(invalidCandidate))
286286

287-
connect(aAgent, bAgent)
287+
connect(t, aAgent, bAgent)
288288

289289
<-isConnected
290290
require.NoError(t, tcpListener.Close())

agent_handlers_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/pion/transport/v3/test"
11+
"github.com/stretchr/testify/assert"
1112
)
1213

1314
func TestConnectionStateNotifier(t *testing.T) {
@@ -33,7 +34,7 @@ func TestConnectionStateNotifier(t *testing.T) {
3334
}
3435
select {
3536
case <-updates:
36-
t.Errorf("received more updates than expected")
37+
t.Errorf("received more updates than expected") // nolint
3738
case <-time.After(1 * time.Second):
3839
}
3940
close(done)
@@ -53,14 +54,11 @@ func TestConnectionStateNotifier(t *testing.T) {
5354
done := make(chan struct{})
5455
go func() {
5556
for i := 0; i < 10000; i++ {
56-
x := <-updates
57-
if x != ConnectionState(i) {
58-
t.Errorf("expected %d got %d", x, i)
59-
}
57+
assert.Equal(t, ConnectionState(i), <-updates)
6058
}
6159
select {
6260
case <-updates:
63-
t.Errorf("received more updates than expected")
61+
t.Errorf("received more updates than expected") // nolint
6462
case <-time.After(1 * time.Second):
6563
}
6664
close(done)

0 commit comments

Comments
 (0)