Skip to content

Commit 93021d2

Browse files
authored
chore: enable testifylint linter (#769)
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 0e65177 commit 93021d2

File tree

20 files changed

+351
-342
lines changed

20 files changed

+351
-342
lines changed

.golangci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@ linters:
99
- errcheck
1010
- errorlint
1111
- misspell
12+
- testifylint
1213

1314
settings:
1415
errcheck:
1516
exclude-functions:
1617
- (github.com/go-kit/log.Logger).Log
1718

19+
testifylint:
20+
disable:
21+
- go-require
22+
enable-all: true
23+
suite-extra-assert-call:
24+
mode: "require"
25+
1826
exclusions:
1927
presets:
2028
- comments

interceptors/auth/auth_test.go

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/grpc-ecosystem/go-grpc-middleware/v2/metadata"
1414
"github.com/grpc-ecosystem/go-grpc-middleware/v2/testing/testpb"
1515
"github.com/stretchr/testify/assert"
16-
"github.com/stretchr/testify/require"
1716
"github.com/stretchr/testify/suite"
1817
"golang.org/x/oauth2"
1918
"google.golang.org/grpc"
@@ -89,60 +88,60 @@ type AuthTestSuite struct {
8988

9089
func (s *AuthTestSuite) TestUnary_NoAuth() {
9190
_, err := s.Client.Ping(s.SimpleCtx(), testpb.GoodPing)
92-
assert.Error(s.T(), err, "there must be an error")
93-
assert.Equal(s.T(), codes.Unauthenticated, status.Code(err), "must error with unauthenticated")
91+
s.Require().Error(err, "there must be an error")
92+
s.Assert().Equal(codes.Unauthenticated, status.Code(err), "must error with unauthenticated")
9493
}
9594

9695
func (s *AuthTestSuite) TestUnary_BadAuth() {
9796
_, err := s.Client.Ping(ctxWithToken(s.SimpleCtx(), "bearer", "bad_token"), testpb.GoodPing)
98-
assert.Error(s.T(), err, "there must be an error")
99-
assert.Equal(s.T(), codes.PermissionDenied, status.Code(err), "must error with permission denied")
97+
s.Require().Error(err, "there must be an error")
98+
s.Assert().Equal(codes.PermissionDenied, status.Code(err), "must error with permission denied")
10099
}
101100

102101
func (s *AuthTestSuite) TestUnary_PassesAuth() {
103102
_, err := s.Client.Ping(ctxWithToken(s.SimpleCtx(), "bearer", commonAuthToken), testpb.GoodPing)
104-
require.NoError(s.T(), err, "no error must occur")
103+
s.Require().NoError(err, "no error must occur")
105104
}
106105

107106
func (s *AuthTestSuite) TestUnary_PassesWithPerRpcCredentials() {
108107
grpcCreds := oauth.TokenSource{TokenSource: &fakeOAuth2TokenSource{accessToken: commonAuthToken}}
109108
client := s.NewClient(grpc.WithPerRPCCredentials(grpcCreds))
110109
_, err := client.Ping(s.SimpleCtx(), testpb.GoodPing)
111-
require.NoError(s.T(), err, "no error must occur")
110+
s.Require().NoError(err, "no error must occur")
112111
}
113112

114113
func (s *AuthTestSuite) TestStream_NoAuth() {
115114
stream, err := s.Client.PingList(s.SimpleCtx(), testpb.GoodPingList)
116-
require.NoError(s.T(), err, "should not fail on establishing the stream")
115+
s.Require().NoError(err, "should not fail on establishing the stream")
117116
_, err = stream.Recv()
118-
assert.Error(s.T(), err, "there must be an error")
119-
assert.Equal(s.T(), codes.Unauthenticated, status.Code(err), "must error with unauthenticated")
117+
s.Require().Error(err, "there must be an error")
118+
s.Assert().Equal(codes.Unauthenticated, status.Code(err), "must error with unauthenticated")
120119
}
121120

122121
func (s *AuthTestSuite) TestStream_BadAuth() {
123122
stream, err := s.Client.PingList(ctxWithToken(s.SimpleCtx(), "bearer", "bad_token"), testpb.GoodPingList)
124-
require.NoError(s.T(), err, "should not fail on establishing the stream")
123+
s.Require().NoError(err, "should not fail on establishing the stream")
125124
_, err = stream.Recv()
126-
assert.Error(s.T(), err, "there must be an error")
127-
assert.Equal(s.T(), codes.PermissionDenied, status.Code(err), "must error with permission denied")
125+
s.Require().Error(err, "there must be an error")
126+
s.Assert().Equal(codes.PermissionDenied, status.Code(err), "must error with permission denied")
128127
}
129128

130129
func (s *AuthTestSuite) TestStream_PassesAuth() {
131130
stream, err := s.Client.PingList(ctxWithToken(s.SimpleCtx(), "Bearer", commonAuthToken), testpb.GoodPingList)
132-
require.NoError(s.T(), err, "should not fail on establishing the stream")
131+
s.Require().NoError(err, "should not fail on establishing the stream")
133132
pong, err := stream.Recv()
134-
require.NoError(s.T(), err, "no error must occur")
135-
require.NotNil(s.T(), pong, "pong must not be nil")
133+
s.Require().NoError(err, "no error must occur")
134+
s.Require().NotNil(pong, "pong must not be nil")
136135
}
137136

138137
func (s *AuthTestSuite) TestStream_PassesWithPerRpcCredentials() {
139138
grpcCreds := oauth.TokenSource{TokenSource: &fakeOAuth2TokenSource{accessToken: commonAuthToken}}
140139
client := s.NewClient(grpc.WithPerRPCCredentials(grpcCreds))
141140
stream, err := client.PingList(s.SimpleCtx(), testpb.GoodPingList)
142-
require.NoError(s.T(), err, "should not fail on establishing the stream")
141+
s.Require().NoError(err, "should not fail on establishing the stream")
143142
pong, err := stream.Recv()
144-
require.NoError(s.T(), err, "no error must occur")
145-
require.NotNil(s.T(), pong, "pong must not be nil")
143+
s.Require().NoError(err, "no error must occur")
144+
s.Require().NotNil(pong, "pong must not be nil")
146145
}
147146

148147
type authOverrideTestService struct {
@@ -175,15 +174,15 @@ type AuthOverrideTestSuite struct {
175174

176175
func (s *AuthOverrideTestSuite) TestUnary_PassesAuth() {
177176
_, err := s.Client.Ping(ctxWithToken(s.SimpleCtx(), "bearer", overrideAuthToken), testpb.GoodPing)
178-
require.NoError(s.T(), err, "no error must occur")
177+
s.Require().NoError(err, "no error must occur")
179178
}
180179

181180
func (s *AuthOverrideTestSuite) TestStream_PassesAuth() {
182181
stream, err := s.Client.PingList(ctxWithToken(s.SimpleCtx(), "Bearer", overrideAuthToken), testpb.GoodPingList)
183-
require.NoError(s.T(), err, "should not fail on establishing the stream")
182+
s.Require().NoError(err, "should not fail on establishing the stream")
184183
pong, err := stream.Recv()
185-
require.NoError(s.T(), err, "no error must occur")
186-
require.NotNil(s.T(), pong, "pong must not be nil")
184+
s.Require().NoError(err, "no error must occur")
185+
s.Require().NotNil(pong, "pong must not be nil")
187186
}
188187

189188
// fakeOAuth2TokenSource implements a fake oauth2.TokenSource for the purpose of credentials test.

interceptors/auth/metadata_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/grpc-ecosystem/go-grpc-middleware/v2/metadata"
1111
"github.com/stretchr/testify/assert"
12+
"github.com/stretchr/testify/require"
1213
"google.golang.org/grpc/codes"
1314
grpcMetadata "google.golang.org/grpc/metadata"
1415
"google.golang.org/grpc/status"
@@ -66,7 +67,7 @@ func TestAuthFromMD(t *testing.T) {
6667
if run.errCode != codes.OK {
6768
assert.Equal(t, run.errCode, status.Code(err), run.msg)
6869
} else {
69-
assert.NoError(t, err, run.msg)
70+
require.NoError(t, err, run.msg)
7071
}
7172
assert.Equal(t, run.value, out, run.msg)
7273
}

interceptors/client_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (s *ClientInterceptorTestSuite) SetupSuite() {
149149
s.mock = &mockReportable{}
150150

151151
s.serverListener, err = net.Listen("tcp", "127.0.0.1:0")
152-
require.NoError(s.T(), err, "must be able to allocate a port for serverListener")
152+
s.Require().NoError(err, "must be able to allocate a port for serverListener")
153153

154154
s.server = grpc.NewServer()
155155
testpb.RegisterTestServiceServer(s.server, &testpb.TestPingService{})
@@ -166,7 +166,7 @@ func (s *ClientInterceptorTestSuite) SetupSuite() {
166166
grpc.WithUnaryInterceptor(UnaryClientInterceptor(s.mock)),
167167
grpc.WithStreamInterceptor(StreamClientInterceptor(s.mock)),
168168
)
169-
require.NoError(s.T(), err, "must not error on client Dial")
169+
s.Require().NoError(err, "must not error on client Dial")
170170
s.testClient = testpb.NewTestServiceClient(s.clientConn)
171171
}
172172

@@ -200,7 +200,7 @@ func (s *ClientInterceptorTestSuite) TearDownTest() {
200200

201201
func (s *ClientInterceptorTestSuite) TestUnaryReporting() {
202202
_, err := s.testClient.PingEmpty(s.ctx, &testpb.PingEmptyRequest{}) // should return with code=OK
203-
require.NoError(s.T(), err)
203+
s.Require().NoError(err)
204204
s.mock.Equal(s.T(), []*mockReport{{
205205
CallMeta: CallMeta{Typ: Unary, Service: testpb.TestServiceFullName, Method: "PingEmpty"},
206206
postCalls: []error{nil},
@@ -210,7 +210,7 @@ func (s *ClientInterceptorTestSuite) TestUnaryReporting() {
210210
s.mock.reports = s.mock.reports[:0] // Reset.
211211

212212
_, err = s.testClient.PingError(s.ctx, &testpb.PingErrorRequest{ErrorCodeReturned: uint32(codes.FailedPrecondition)}) // should return with code=FailedPrecondition
213-
require.Error(s.T(), err)
213+
s.Require().Error(err)
214214
s.mock.Equal(s.T(), []*mockReport{{
215215
CallMeta: CallMeta{Typ: Unary, Service: testpb.TestServiceFullName, Method: "PingError"},
216216
postCalls: []error{status.Error(codes.FailedPrecondition, "Userspace error")},
@@ -221,7 +221,7 @@ func (s *ClientInterceptorTestSuite) TestUnaryReporting() {
221221

222222
func (s *ClientInterceptorTestSuite) TestStartedListReporting() {
223223
_, err := s.testClient.PingList(s.ctx, &testpb.PingListRequest{})
224-
require.NoError(s.T(), err)
224+
s.Require().NoError(err)
225225

226226
// Even without reading, we should get initial mockReport.
227227
s.mock.Equal(s.T(), []*mockReport{{
@@ -230,7 +230,7 @@ func (s *ClientInterceptorTestSuite) TestStartedListReporting() {
230230
}})
231231

232232
_, err = s.testClient.PingList(s.ctx, &testpb.PingListRequest{ErrorCodeReturned: uint32(codes.FailedPrecondition)})
233-
require.NoError(s.T(), err, "PingList must not fail immediately")
233+
s.Require().NoError(err, "PingList must not fail immediately")
234234

235235
// Even without reading, we should get initial mockReport.
236236
s.mock.Equal(s.T(), []*mockReport{{
@@ -244,7 +244,7 @@ func (s *ClientInterceptorTestSuite) TestStartedListReporting() {
244244

245245
func (s *ClientInterceptorTestSuite) TestListReporting() {
246246
ss, err := s.testClient.PingList(s.ctx, &testpb.PingListRequest{})
247-
require.NoError(s.T(), err)
247+
s.Require().NoError(err)
248248

249249
// Do a read, just for kicks.
250250
count := 0
@@ -253,10 +253,10 @@ func (s *ClientInterceptorTestSuite) TestListReporting() {
253253
if errors.Is(err, io.EOF) {
254254
break
255255
}
256-
require.NoError(s.T(), err, "reading pingList shouldn't fail")
256+
s.Require().NoError(err, "reading pingList shouldn't fail")
257257
count++
258258
}
259-
require.EqualValues(s.T(), testpb.ListResponseCount, count, "Number of received msg on the wire must match")
259+
s.Require().Equal(testpb.ListResponseCount, count, "Number of received msg on the wire must match")
260260

261261
s.mock.Equal(s.T(), []*mockReport{{
262262
CallMeta: CallMeta{Typ: ServerStream, Service: testpb.TestServiceFullName, Method: "PingList"},
@@ -267,19 +267,19 @@ func (s *ClientInterceptorTestSuite) TestListReporting() {
267267
s.mock.reports = s.mock.reports[:0] // Reset.
268268

269269
ss, err = s.testClient.PingList(s.ctx, &testpb.PingListRequest{ErrorCodeReturned: uint32(codes.FailedPrecondition)})
270-
require.NoError(s.T(), err, "PingList must not fail immediately")
270+
s.Require().NoError(err, "PingList must not fail immediately")
271271

272272
// Do a read, just to propagate errors.
273273
_, err = ss.Recv()
274-
require.Error(s.T(), err)
274+
s.Require().Error(err)
275275
st, _ := status.FromError(err)
276-
require.Equal(s.T(), codes.FailedPrecondition, st.Code(), "Recv must return FailedPrecondition, otherwise the test is wrong")
276+
s.Require().Equal(codes.FailedPrecondition, st.Code(), "Recv must return FailedPrecondition, otherwise the test is wrong")
277277

278278
// Next same.
279279
_, err = ss.Recv()
280-
require.Error(s.T(), err)
280+
s.Require().Error(err)
281281
st, _ = status.FromError(err)
282-
require.Equal(s.T(), codes.FailedPrecondition, st.Code(), "Recv must return FailedPrecondition, otherwise the test is wrong")
282+
s.Require().Equal(codes.FailedPrecondition, st.Code(), "Recv must return FailedPrecondition, otherwise the test is wrong")
283283

284284
s.mock.Equal(s.T(), []*mockReport{{
285285
CallMeta: CallMeta{Typ: ServerStream, Service: testpb.TestServiceFullName, Method: "PingList"},
@@ -291,7 +291,7 @@ func (s *ClientInterceptorTestSuite) TestListReporting() {
291291

292292
func (s *ClientInterceptorTestSuite) TestBiStreamingReporting() {
293293
ss, err := s.testClient.PingStream(s.ctx)
294-
require.NoError(s.T(), err)
294+
s.Require().NoError(err)
295295

296296
wg := sync.WaitGroup{}
297297
defer func() {
@@ -316,13 +316,13 @@ func (s *ClientInterceptorTestSuite) TestBiStreamingReporting() {
316316
}
317317
}()
318318
for i := 0; i < 100; i++ {
319-
require.NoError(s.T(), ss.Send(&testpb.PingStreamRequest{}), "sending shouldn't fail")
319+
s.Require().NoError(ss.Send(&testpb.PingStreamRequest{}), "sending shouldn't fail")
320320
}
321321

322-
require.NoError(s.T(), ss.CloseSend())
322+
s.Require().NoError(ss.CloseSend())
323323
wg.Wait()
324324

325-
require.EqualValues(s.T(), 100, count, "Number of received msg on the wire must match")
325+
s.Require().Equal(100, count, "Number of received msg on the wire must match")
326326
s.mock.Equal(s.T(), []*mockReport{{
327327
CallMeta: CallMeta{Typ: BidiStream, Service: testpb.TestServiceFullName, Method: "PingStream"},
328328
postCalls: []error{nil},
@@ -333,18 +333,18 @@ func (s *ClientInterceptorTestSuite) TestBiStreamingReporting() {
333333

334334
func (s *ClientInterceptorTestSuite) TestClientStream() {
335335
ss, err := s.testClient.PingClientStream(s.ctx)
336-
require.NoError(s.T(), err)
336+
s.Require().NoError(err)
337337

338338
defer func() {
339339
_, _ = ss.CloseAndRecv()
340340
}()
341341

342342
for i := 0; i < 100; i++ {
343-
require.NoError(s.T(), ss.Send(&testpb.PingClientStreamRequest{}), "sending shouldn't fail")
343+
s.Require().NoError(ss.Send(&testpb.PingClientStreamRequest{}), "sending shouldn't fail")
344344
}
345345

346346
_, err = ss.CloseAndRecv()
347-
require.NoError(s.T(), err)
347+
s.Require().NoError(err)
348348

349349
s.mock.Equal(s.T(), []*mockReport{{
350350
CallMeta: CallMeta{Typ: ClientStream, Service: testpb.TestServiceFullName, Method: "PingClientStream"},

0 commit comments

Comments
 (0)