Skip to content

Commit 01f9948

Browse files
committed
protovalidate: refactor repetitive subtests
The info struct is shared between all these subtests - there's no need to clutter up each test by redefining it. Signed-off-by: Akshay Shah <[email protected]>
1 parent 7da22cf commit 01f9948

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

interceptors/protovalidate/protovalidate_test.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,15 @@ func TestUnaryServerInterceptor(t *testing.T) {
3131
handler := func(ctx context.Context, req any) (any, error) {
3232
return "good", nil
3333
}
34+
info := &grpc.UnaryServerInfo{FullMethod: "FakeMethod"}
3435

3536
t.Run("valid_email", func(t *testing.T) {
36-
info := &grpc.UnaryServerInfo{
37-
FullMethod: "FakeMethod",
38-
}
39-
4037
resp, err := interceptor(context.TODO(), testvalidate.GoodUnaryRequest, info, handler)
4138
assert.Nil(t, err)
4239
assert.Equal(t, resp, "good")
4340
})
4441

4542
t.Run("invalid_email", func(t *testing.T) {
46-
info := &grpc.UnaryServerInfo{
47-
FullMethod: "FakeMethod",
48-
}
49-
5043
_, err = interceptor(context.TODO(), testvalidate.BadUnaryRequest, info, handler)
5144
assert.Error(t, err)
5245
assert.Equal(t, codes.InvalidArgument, status.Code(err))
@@ -57,10 +50,6 @@ func TestUnaryServerInterceptor(t *testing.T) {
5750
)
5851

5952
t.Run("invalid_email_ignored", func(t *testing.T) {
60-
info := &grpc.UnaryServerInfo{
61-
FullMethod: "FakeMethod",
62-
}
63-
6453
resp, err := interceptor(context.TODO(), testvalidate.BadUnaryRequest, info, handler)
6554
assert.Nil(t, err)
6655
assert.Equal(t, resp, "good")

0 commit comments

Comments
 (0)