diff --git a/.golangci.yaml b/.golangci.yaml index 601da6e..a7d01f1 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,7 +1,7 @@ # See https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml run: tests: true - deadline: 5m + timeout: 5m linters-settings: errcheck: @@ -13,16 +13,16 @@ linters-settings: threshold: 100 misspell: locale: US - unused: - check-exported: false unparam: check-exported: true linters: enable-all: true disable: + - copyloopvar - deadcode - depguard + - execinquery - exhaustivestruct - exhaustruct - forbidigo @@ -32,10 +32,12 @@ linters: - golint - gomnd - ifshort + - intrange - interfacer - ireturn - lll - maligned + - mnd - nolintlint # https://github.com/golangci/golangci-lint/issues/3063 - nonamedreturns - nosnakecase @@ -50,11 +52,14 @@ linters: - wrapcheck issues: + max-issues-per-linter: 200 + max-same-issues: 50 exclude-use-default: false exclude-rules: - linters: - containedctx - dupl + - err113 - funlen - goconst - goerr113 diff --git a/Makefile b/Makefile index 089e658..94ae99b 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ MODULE_NAME = grpcmock VENDOR_DIR = vendor -GOLANGCI_LINT_VERSION ?= v1.55.2 +GOLANGCI_LINT_VERSION ?= v1.58.0 GO ?= go GOLANGCI_LINT ?= $(shell go env GOPATH)/bin/golangci-lint-$(GOLANGCI_LINT_VERSION) diff --git a/client.go b/client.go index a95917f..d961a42 100644 --- a/client.go +++ b/client.go @@ -153,7 +153,11 @@ func prepInvoke(ctx context.Context, method string, opts ...InvokeOption) (conte ctx, dialOpts, callOpts := invokeOptions(ctx, opts...) - conn, err := grpc.DialContext(ctx, addr, dialOpts...) + if addr == "" { + addr = "passthrough://" + } + + conn, err := grpc.NewClient(addr, dialOpts...) if err != nil { return ctx, nil, "", nil, err } @@ -169,7 +173,7 @@ func parseMethod(method string) (string, string, error) { addr := methodRegex.ReplaceAllString(method, "") method = strings.Replace(method, addr, "", 1) - method = fmt.Sprintf("/%s", strings.TrimLeft(method, "/")) + method = "/" + strings.TrimLeft(method, "/") return addr, method, nil } @@ -187,6 +191,8 @@ func invokeOptions(ctx context.Context, opts ...InvokeOption) (context.Context, ctx = metadata.NewOutgoingContext(ctx, metadata.New(cfg.header)) } + // cfg.dialOpts = append([]grpc.DialOption{withDefaultScheme("passthrough")}, cfg.dialOpts...) + return ctx, cfg.dialOpts, cfg.callOpts } diff --git a/client_test.go b/client_test.go index e30202a..836cd68 100644 --- a/client_test.go +++ b/client_test.go @@ -3,7 +3,6 @@ package grpcmock_test import ( "context" "errors" - "fmt" "io" "net" "testing" @@ -67,7 +66,7 @@ func TestInvokeUnary_Unimplemented(t *testing.T) { defer srv.Stop() go func() { - _ = srv.Serve(l) // nolint: errcheck + _ = srv.Serve(l) //nolint: errcheck }() err := grpcmock.InvokeUnary(context.Background(), "grpctest.ItemService/GetItem", nil, nil, @@ -433,7 +432,7 @@ func TestInvokeBidirectionalStream_Success(t *testing.T) { return err } - msg.Name = fmt.Sprintf("Modified %s", msg.GetName()) + msg.Name = "Modified " + msg.GetName() if err := srv.SendMsg(msg); err != nil { return err @@ -540,7 +539,7 @@ func TestRecvAll(t *testing.T) { s.On("RecvMsg", &grpctest.Item{}).Once(). Run(func(args mock.Arguments) { - out := args.Get(0).(*grpctest.Item) // nolint: errcheck + out := args.Get(0).(*grpctest.Item) //nolint: errcheck proto.Merge(out, i) }). @@ -739,7 +738,7 @@ func TestSendAndRecvAll_Success(t *testing.T) { mockStream: xmock.MockClientStream(func(s *xmock.ClientStream) { s.On("RecvMsg", mock.Anything).Once(). Run(func(args mock.Arguments) { - out := args.Get(0).(*grpctest.Item) // nolint: errcheck + out := args.Get(0).(*grpctest.Item) //nolint: errcheck *out = grpctest.Item{Id: 42, Name: "Modified"} }). diff --git a/go.mod b/go.mod index 05153c3..33b016c 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( go.nhat.io/aferomock v0.4.0 go.nhat.io/matcher/v2 v2.0.0 go.nhat.io/wait v0.1.0 - google.golang.org/grpc v1.63.2 + google.golang.org/grpc v1.64.0 google.golang.org/protobuf v1.34.1 ) @@ -27,10 +27,10 @@ require ( github.com/stretchr/objx v0.5.2 // indirect github.com/yudai/gojsondiff v1.0.0 // indirect github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect - golang.org/x/net v0.21.0 // indirect - golang.org/x/sys v0.17.0 // indirect - golang.org/x/text v0.14.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index ffacc1e..abfc708 100644 --- a/go.sum +++ b/go.sum @@ -110,8 +110,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= -golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -126,12 +126,12 @@ golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= @@ -150,15 +150,15 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 h1:Zy9XzmMEflZ/MAaA7vNcoebnRAld7FsPW1EeBB7V0m8= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= -google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= -google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= +google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= +google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/helper.go b/helper.go index e1e61f7..990ebe5 100644 --- a/helper.go +++ b/helper.go @@ -1,14 +1,13 @@ package grpcmock import ( - "fmt" "strings" "google.golang.org/grpc" ) func methodName(v string) string { - return fmt.Sprintf("/%s", strings.TrimLeft(v, "/")) + return "/" + strings.TrimLeft(v, "/") } func serviceSorter(services []*grpc.ServiceDesc) ([]*grpc.ServiceDesc, func(i, j int) bool) { diff --git a/invoker/invoker_test.go b/invoker/invoker_test.go index ab13c57..73fb80a 100644 --- a/invoker/invoker_test.go +++ b/invoker/invoker_test.go @@ -3,7 +3,6 @@ package invoker_test import ( "context" "errors" - "fmt" "io" "testing" "time" @@ -32,7 +31,7 @@ func TestInvoker_Invoke_Unary_Unimplemented(t *testing.T) { defer srv.Stop() go func() { - _ = srv.Serve(l) // nolint: errcheck + _ = srv.Serve(l) //nolint: errcheck }() err := invoker.New(getItemMethod(), @@ -234,7 +233,7 @@ func TestInvoker_Invoke_BidirectionalStream_Success(t *testing.T) { return err } - msg.Name = fmt.Sprintf("Modified %s", msg.GetName()) + msg.Name = "Modified " + msg.GetName() if err := srv.SendMsg(msg); err != nil { return err diff --git a/matcher/header.go b/matcher/header.go index 7cd3a70..f24ac16 100644 --- a/matcher/header.go +++ b/matcher/header.go @@ -28,7 +28,7 @@ func (m HeaderMatcher) Match(ctx context.Context) error { } if !matched { - return fmt.Errorf("header %q with value %q expected, %q received", h, m.Expected(), value) // nolint: goerr113 + return fmt.Errorf("header %q with value %q expected, %q received", h, m.Expected(), value) //nolint: goerr113 } } diff --git a/mock.go b/mock.go index 34ce1bc..a481e54 100644 --- a/mock.go +++ b/mock.go @@ -35,7 +35,7 @@ func MockServer(opts ...ServerOption) ServerMocker { t.Cleanup(func() { assert.NoError(t, s.ExpectationsWereMet()) - _ = s.Close() // nolint: errcheck + _ = s.Close() //nolint: errcheck }) return s @@ -48,7 +48,7 @@ func MockServerWithBufConn(opts ...ServerOption) ServerMockerWithContextDialer { buf := bufconn.Listen(1024 * 1024) opts = append(opts, WithListener(buf)) - return MockServer(opts...)(t), func(ctx context.Context, s string) (net.Conn, error) { + return MockServer(opts...)(t), func(context.Context, string) (net.Conn, error) { return buf.Dial() } } diff --git a/mock_example_test.go b/mock_example_test.go index 71042fe..a436653 100644 --- a/mock_example_test.go +++ b/mock_example_test.go @@ -38,7 +38,7 @@ func ExampleMockServer() { // Call the service. out := &grpctest.Item{} - method := fmt.Sprintf("%s/grpctest.ItemService/GetItem", srv.Address()) + method := srv.Address() + "/grpctest.ItemService/GetItem" err := grpcmock.InvokeUnary(context.Background(), method, &grpctest.GetItemRequest{Id: 41}, out, grpcmock.WithInsecure(), diff --git a/planner/error.go b/planner/error.go index 24018dd..d355fea 100644 --- a/planner/error.go +++ b/planner/error.go @@ -72,7 +72,7 @@ func NewError(ctx context.Context, expected Expectation, req service.Method, in if in != nil { in, err := value.Marshal(in) if err != nil { - in = fmt.Sprintf("could not read request payload: %s", err.Error()) + in = "could not read request payload: " + err.Error() } actualPayload = in diff --git a/planner/matcher_test.go b/planner/matcher_test.go index 0849657..133e3ea 100644 --- a/planner/matcher_test.go +++ b/planner/matcher_test.go @@ -709,7 +709,7 @@ func mockCreateItemsStreamer() func(t *testing.T) *streamer.ClientStreamer { return test.MockCreateItemsStreamer(func(s *xmock.ServerStream) { s.On("RecvMsg", &grpctest.Item{}).Once(). Run(func(args mock.Arguments) { - item := args.Get(0).(*grpctest.Item) // nolint: errcheck + item := args.Get(0).(*grpctest.Item) //nolint: errcheck proto.Merge(item, test.DefaultItem()) }). diff --git a/request/client_stream.go b/request/client_stream.go index 9385947..e5cfe3e 100644 --- a/request/client_stream.go +++ b/request/client_stream.go @@ -259,7 +259,7 @@ func (r *ClientStreamRequest) handle(ctx context.Context, in any, out any) error return status.Error(r.statusCode, r.statusMessage) } - stream := in.(*streamer.ClientStreamer) // nolint: errcheck + stream := in.(*streamer.ClientStreamer) //nolint: errcheck resp, err := r.run(ctx, stream) if err != nil { diff --git a/request/unary.go b/request/unary.go index cffe3bc..93943c7 100644 --- a/request/unary.go +++ b/request/unary.go @@ -60,7 +60,7 @@ func NewUnaryRequest(locker sync.Locker, svc *service.Method) *UnaryRequest { fs: afero.NewOsFs(), }, - run: func(ctx context.Context, in any) (any, error) { + run: func(context.Context, any) (any, error) { return nil, status.Error(codes.Unimplemented, "not implemented") }, } diff --git a/resources/docs/SERVER.md b/resources/docs/SERVER.md index a52ffac..8b58fd7 100644 --- a/resources/docs/SERVER.md +++ b/resources/docs/SERVER.md @@ -73,7 +73,7 @@ func TestServer(t *testing.T) { ) // Close the server on exit. - defer s.Close(context.Background()) // nolint: errcheck + defer s.Close(context.Background()) //nolint: errcheck // Call the server and assertions. } diff --git a/server.go b/server.go index 463a8a9..7330660 100644 --- a/server.go +++ b/server.go @@ -90,7 +90,7 @@ func (s *Server) WithPlanner(p planner.Planner) *Server { defer s.mu.Unlock() if !s.planner.IsEmpty() { - panic(errors.New("could not change planner: planner is not empty")) // nolint: goerr113 + panic(errors.New("could not change planner: planner is not empty")) //nolint: goerr113 } s.planner = p @@ -238,7 +238,7 @@ func (s *Server) ExpectationsWereMet() error { return nil } - // nolint:goerr113 + //nolint:goerr113 return errors.New(sb.String()) } @@ -272,7 +272,7 @@ func (s *Server) Serve() { go func(l net.Listener) { //goland:noinspection GoUnhandledErrorResult - defer closeListener() // nolint: errcheck + defer closeListener() //nolint: errcheck must.NotFail(srv.Serve(l)) }(s.listener) @@ -470,7 +470,7 @@ func newStreamHandler( out any ) - // nolint: exhaustive + //nolint: exhaustive switch svc.MethodType { case service.TypeServerStream: in = xreflect.New(svc.Input) diff --git a/server_example_test.go b/server_example_test.go index 014fd4f..fd34a17 100644 --- a/server_example_test.go +++ b/server_example_test.go @@ -26,7 +26,7 @@ import ( func ExampleServer_WithPlanner() { buf := bufconn.Listen(1024 * 1024) - defer buf.Close() // nolint: errcheck + defer buf.Close() //nolint: errcheck srv := grpcmock.NewServer( grpcmock.RegisterService(grpctest.RegisterItemServiceServer), @@ -48,7 +48,7 @@ func ExampleServer_WithPlanner() { }, ) - defer srv.Close() // nolint: errcheck + defer srv.Close() //nolint: errcheck // Call the service. err := grpcmock.InvokeUnary(context.Background(), @@ -65,7 +65,7 @@ func ExampleServer_WithPlanner() { func ExampleServer_firstMatch_planner() { buf := bufconn.Listen(1024 * 1024) - defer buf.Close() // nolint: errcheck + defer buf.Close() //nolint: errcheck srv := grpcmock.NewServer( grpcmock.RegisterService(grpctest.RegisterItemServiceServer), @@ -86,7 +86,7 @@ func ExampleServer_firstMatch_planner() { }, ) - defer srv.Close() // nolint: errcheck + defer srv.Close() //nolint: errcheck // Call the service. ids := []int32{1, 2, 3} @@ -143,7 +143,7 @@ func ExampleServer_firstMatch_planner() { func ExampleNewServer_unaryMethod() { buf := bufconn.Listen(1024 * 1024) - defer buf.Close() // nolint: errcheck + defer buf.Close() //nolint: errcheck srv := grpcmock.NewServer( grpcmock.RegisterService(grpctest.RegisterItemServiceServer), @@ -159,7 +159,7 @@ func ExampleNewServer_unaryMethod() { }, ) - defer srv.Close() // nolint: errcheck + defer srv.Close() //nolint: errcheck // Call the service. out := &grpctest.Item{} @@ -198,7 +198,7 @@ func ExampleNewServer_withPort() { }, ) - defer srv.Close() // nolint: errcheck + defer srv.Close() //nolint: errcheck // Call the service. out := &grpctest.Item{} @@ -223,7 +223,7 @@ func ExampleNewServer_withPort() { func ExampleNewServer_unaryMethod_customHandler() { buf := bufconn.Listen(1024 * 1024) - defer buf.Close() // nolint: errcheck + defer buf.Close() //nolint: errcheck srv := grpcmock.NewServer( grpcmock.RegisterService(grpctest.RegisterItemServiceServer), @@ -232,7 +232,7 @@ func ExampleNewServer_unaryMethod_customHandler() { s.ExpectUnary("grpctest.ItemService/GetItem"). WithPayload(&grpctest.GetItemRequest{Id: 42}). Run(func(ctx context.Context, in any) (any, error) { - req := in.(*grpctest.GetItemRequest) // nolint: errcheck + req := in.(*grpctest.GetItemRequest) //nolint: errcheck var locale string @@ -252,7 +252,7 @@ func ExampleNewServer_unaryMethod_customHandler() { }, ) - defer srv.Close() // nolint: errcheck + defer srv.Close() //nolint: errcheck // Call the service. out := &grpctest.Item{} @@ -279,7 +279,7 @@ func ExampleNewServer_unaryMethod_customHandler() { func ExampleNewServer_clientStreamMethod() { buf := bufconn.Listen(1024 * 1024) - defer buf.Close() // nolint: errcheck + defer buf.Close() //nolint: errcheck srv := grpcmock.NewServer( grpcmock.RegisterService(grpctest.RegisterItemServiceServer), @@ -294,7 +294,7 @@ func ExampleNewServer_clientStreamMethod() { }, ) - defer srv.Close() // nolint: errcheck + defer srv.Close() //nolint: errcheck // Call the service. out := &grpctest.CreateItemsResponse{} @@ -323,7 +323,7 @@ func ExampleNewServer_clientStreamMethod() { func ExampleNewServer_clientStreamMethod_customHandler() { buf := bufconn.Listen(1024 * 1024) - defer buf.Close() // nolint: errcheck + defer buf.Close() //nolint: errcheck srv := grpcmock.NewServer( grpcmock.RegisterService(grpctest.RegisterItemServiceServer), @@ -351,7 +351,7 @@ func ExampleNewServer_clientStreamMethod_customHandler() { }, ) - defer srv.Close() // nolint: errcheck + defer srv.Close() //nolint: errcheck // Call the service. out := &grpctest.CreateItemsResponse{} @@ -381,7 +381,7 @@ func ExampleNewServer_clientStreamMethod_customHandler() { func ExampleNewServer_serverStreamMethod() { buf := bufconn.Listen(1024 * 1024) - defer buf.Close() // nolint: errcheck + defer buf.Close() //nolint: errcheck srv := grpcmock.NewServer( grpcmock.RegisterService(grpctest.RegisterItemServiceServer), @@ -395,7 +395,7 @@ func ExampleNewServer_serverStreamMethod() { }, ) - defer srv.Close() // nolint: errcheck + defer srv.Close() //nolint: errcheck // Call the service. out := make([]*grpctest.Item, 0) @@ -428,7 +428,7 @@ func ExampleNewServer_serverStreamMethod() { func ExampleNewServer_serverStreamMethod_customHandler() { buf := bufconn.Listen(1024 * 1024) - defer buf.Close() // nolint: errcheck + defer buf.Close() //nolint: errcheck srv := grpcmock.NewServer( grpcmock.RegisterService(grpctest.RegisterItemServiceServer), @@ -436,15 +436,15 @@ func ExampleNewServer_serverStreamMethod_customHandler() { func(s *grpcmock.Server) { s.ExpectServerStream("grpctest.ItemService/ListItems"). Run(func(_ context.Context, _ any, s grpc.ServerStream) error { - _ = s.SendMsg(&grpctest.Item{Id: 41, Name: "Item #41"}) // nolint: errcheck - _ = s.SendMsg(&grpctest.Item{Id: 42, Name: "Item #42"}) // nolint: errcheck + _ = s.SendMsg(&grpctest.Item{Id: 41, Name: "Item #41"}) //nolint: errcheck + _ = s.SendMsg(&grpctest.Item{Id: 42, Name: "Item #42"}) //nolint: errcheck return nil }) }, ) - defer srv.Close() // nolint: errcheck + defer srv.Close() //nolint: errcheck // Call the service. out := make([]*grpctest.Item, 0) @@ -477,7 +477,7 @@ func ExampleNewServer_serverStreamMethod_customHandler() { func ExampleNewServer_serverStreamMethod_customStreamBehaviors() { buf := bufconn.Listen(1024 * 1024) - defer buf.Close() // nolint: errcheck + defer buf.Close() //nolint: errcheck srv := grpcmock.NewServer( grpcmock.RegisterService(grpctest.RegisterItemServiceServer), @@ -490,7 +490,7 @@ func ExampleNewServer_serverStreamMethod_customStreamBehaviors() { }, ) - defer srv.Close() // nolint: errcheck + defer srv.Close() //nolint: errcheck // Call the service. out := make([]*grpctest.Item, 0) @@ -512,14 +512,14 @@ func ExampleNewServer_serverStreamMethod_customStreamBehaviors() { func ExampleNewServer_bidirectionalStreamMethod() { buf := bufconn.Listen(1024 * 1024) - defer buf.Close() // nolint: errcheck + defer buf.Close() //nolint: errcheck srv := grpcmock.NewServer( grpcmock.RegisterService(grpctest.RegisterItemServiceServer), grpcmock.WithListener(buf), func(s *grpcmock.Server) { s.ExpectBidirectionalStream("grpctest.ItemService/TransformItems"). - Run(func(ctx context.Context, s grpc.ServerStream) error { + Run(func(_ context.Context, s grpc.ServerStream) error { for { item := &grpctest.Item{} err := s.RecvMsg(item) @@ -542,7 +542,7 @@ func ExampleNewServer_bidirectionalStreamMethod() { }, ) - defer srv.Close() // nolint: errcheck + defer srv.Close() //nolint: errcheck // Call the service. in := []*grpctest.Item{ @@ -585,7 +585,7 @@ func ExampleNewServer_bidirectionalStreamMethod() { func ExampleRegisterService() { buf := bufconn.Listen(1024 * 1024) - defer buf.Close() // nolint: errcheck + defer buf.Close() //nolint: errcheck srv := grpcmock.NewServer( grpcmock.RegisterService(grpctest.RegisterItemServiceServer), @@ -601,7 +601,7 @@ func ExampleRegisterService() { }, ) - defer srv.Close() // nolint: errcheck + defer srv.Close() //nolint: errcheck // Call the service. out := &grpctest.Item{} @@ -627,7 +627,7 @@ func ExampleRegisterService() { func ExampleRegisterServiceFromInstance() { buf := bufconn.Listen(1024 * 1024) - defer buf.Close() // nolint: errcheck + defer buf.Close() //nolint: errcheck srv := grpcmock.NewServer( grpcmock.RegisterServiceFromInstance("grpctest.ItemService", (*grpctest.ItemServiceServer)(nil)), @@ -643,7 +643,7 @@ func ExampleRegisterServiceFromInstance() { }, ) - defer srv.Close() // nolint: errcheck + defer srv.Close() //nolint: errcheck // Call the service. out := &grpctest.Item{} @@ -669,7 +669,7 @@ func ExampleRegisterServiceFromInstance() { func ExampleRegisterServiceFromMethods() { buf := bufconn.Listen(1024 * 1024) - defer buf.Close() // nolint: errcheck + defer buf.Close() //nolint: errcheck srv := grpcmock.NewServer( grpcmock.RegisterServiceFromMethods(service.Method{ @@ -691,7 +691,7 @@ func ExampleRegisterServiceFromMethods() { }, ) - defer srv.Close() // nolint: errcheck + defer srv.Close() //nolint: errcheck // Call the service. out := &grpctest.Item{} diff --git a/server_expectation_bidirectional_stream_internal_test.go b/server_expectation_bidirectional_stream_internal_test.go index 1000f7e..da52bf2 100644 --- a/server_expectation_bidirectional_stream_internal_test.go +++ b/server_expectation_bidirectional_stream_internal_test.go @@ -223,7 +223,7 @@ func TestBidirectionalStreamExpectation_Run_Success(t *testing.T) { t.Parallel() r := newTransformItemsRequest() - r.Run(func(ctx context.Context, s grpc.ServerStream) error { + r.Run(func(_ context.Context, s grpc.ServerStream) error { for { item := &grpctest.Item{} err := s.RecvMsg(item) diff --git a/server_expectation_client_stream.go b/server_expectation_client_stream.go index 0eb8676..93dfbea 100644 --- a/server_expectation_client_stream.go +++ b/server_expectation_client_stream.go @@ -299,7 +299,7 @@ func (e *clientStreamExpectation) Handle(ctx context.Context, in any, out any) e return status.Error(e.statusCode, e.statusMessage) } - stream := in.(*streamer.ClientStreamer) // nolint: errcheck + stream := in.(*streamer.ClientStreamer) //nolint: errcheck resp, err := e.run(ctx, stream) if err != nil { diff --git a/server_expectation_server_stream_internal_test.go b/server_expectation_server_stream_internal_test.go index a6bb439..dc0b8c0 100644 --- a/server_expectation_server_stream_internal_test.go +++ b/server_expectation_server_stream_internal_test.go @@ -725,8 +725,8 @@ func TestServerStreamExpectation_Run(t *testing.T) { r := newListItemsRequest() r.Run(func(_ context.Context, _ any, s grpc.ServerStream) error { - _ = s.SendMsg(&grpctest.Item{Id: 41, Name: "Item #41"}) // nolint: errcheck - _ = s.SendMsg(&grpctest.Item{Id: 42, Name: "Item #42"}) // nolint: errcheck + _ = s.SendMsg(&grpctest.Item{Id: 41, Name: "Item #41"}) //nolint: errcheck + _ = s.SendMsg(&grpctest.Item{Id: 42, Name: "Item #42"}) //nolint: errcheck return nil }) @@ -845,7 +845,7 @@ func TestServerStreamExpectation_WaitTime_ContextTimeout(t *testing.T) { err := r.Handle(ctx, nil, nil) endTime := time.Now() - assert.GreaterOrEqual(t, endTime.Sub(startTime), expectedDuration) + assert.InDelta(t, expectedDuration.Milliseconds(), endTime.Sub(startTime).Milliseconds(), float64(time.Millisecond)) assert.Error(t, err) assert.EqualError(t, err, `rpc error: code = Internal desc = context deadline exceeded`) } diff --git a/server_expectation_unary.go b/server_expectation_unary.go index 4949ded..662ed38 100644 --- a/server_expectation_unary.go +++ b/server_expectation_unary.go @@ -392,7 +392,7 @@ func newUnaryExpectation(svc *service.Method) *unaryExpectation { waiter: wait.NoWait, serviceDesc: svc, }, - run: func(ctx context.Context, in any) (any, error) { + run: func(context.Context, any) (any, error) { return nil, status.Error(codes.Unimplemented, "not implemented") }, } diff --git a/server_internal_test.go b/server_internal_test.go index e418097..8a0ad9a 100644 --- a/server_internal_test.go +++ b/server_internal_test.go @@ -73,16 +73,16 @@ func TestCloseGRPCServer_Error(t *testing.T) { srv, _ := buildGRPCServer(s.services, s.handleRequest, s.serverOpts...) go func() { - defer buf.Close() // nolint: errcheck + defer buf.Close() //nolint: errcheck - _ = srv.Serve(buf) // nolint: errcheck + _ = srv.Serve(buf) //nolint: errcheck }() go func() { // Wait until server is up. time.Sleep(time.Millisecond * 20) - // nolint: errcheck + //nolint: errcheck _ = InvokeUnary(context.Background(), "grpctest.ItemService/GetItem", &grpctest.GetItemRequest{Id: 42}, &grpctest.Item{}, @@ -154,7 +154,7 @@ func TestNewUnaryHandler(t *testing.T) { scenario: "handle success", decode: decodeNoError, handle: func(_ context.Context, _ service.Method, _ any, out any) error { - item := out.(*grpctest.Item) // nolint: errcheck + item := out.(*grpctest.Item) //nolint: errcheck item.Id = 42 return nil diff --git a/server_test.go b/server_test.go index bd6b631..16c576b 100644 --- a/server_test.go +++ b/server_test.go @@ -181,7 +181,7 @@ func TestServer_ExpectUnary_Success(t *testing.T) { } } - p := in.(*grpctest.GetItemRequest) // nolint: errcheck + p := in.(*grpctest.GetItemRequest) //nolint: errcheck result := testSrv.BuildItem(). WithID(p.GetId()). @@ -551,7 +551,7 @@ func TestServer_ExpectBidirectionalStream_Success(t *testing.T) { _, d := mockItemServiceServer(t, func(s *grpcmock.Server) { s.ExpectBidirectionalStream(grpcTestServiceTransformItems). WithHeader(`locale`, `en-US`). - Run(func(ctx context.Context, s grpc.ServerStream) error { + Run(func(_ context.Context, s grpc.ServerStream) error { for { item := &grpctest.Item{} err := s.RecvMsg(item) @@ -701,7 +701,7 @@ func TestFindServerMethod(t *testing.T) { }{ { scenario: "not found", - mockServer: func(s *grpcmock.Server) {}, + mockServer: func(*grpcmock.Server) {}, }, { scenario: "found", diff --git a/stream/bidirectional_test.go b/stream/bidirectional_test.go index 89caac7..e6d8ef0 100644 --- a/stream/bidirectional_test.go +++ b/stream/bidirectional_test.go @@ -112,7 +112,7 @@ func TestSendAndRecvAll_Success_ClientStream(t *testing.T) { mockStream: xmock.MockClientStream(func(s *xmock.ClientStream) { s.On("RecvMsg", mock.Anything).Once(). Run(func(args mock.Arguments) { - out := args.Get(0).(*grpctest.Item) // nolint: errcheck + out := args.Get(0).(*grpctest.Item) //nolint: errcheck *out = grpctest.Item{Id: 42, Name: "Modified"} }). @@ -180,7 +180,7 @@ func TestSendAndRecvAll_Success_ServerStream(t *testing.T) { mockStream: xmock.MockServerStream(func(s *xmock.ServerStream) { s.On("RecvMsg", mock.Anything).Once(). Run(func(args mock.Arguments) { - out := args.Get(0).(*grpctest.Item) // nolint: errcheck + out := args.Get(0).(*grpctest.Item) //nolint: errcheck *out = grpctest.Item{Id: 42, Name: "Modified"} }). diff --git a/stream/receiever_test.go b/stream/receiever_test.go index 3a87f1c..5843710 100644 --- a/stream/receiever_test.go +++ b/stream/receiever_test.go @@ -25,7 +25,7 @@ func TestRecvAll(t *testing.T) { s.On("RecvMsg", &grpctest.Item{}).Once(). Run(func(args mock.Arguments) { - out := args.Get(0).(*grpctest.Item) // nolint: errcheck + out := args.Get(0).(*grpctest.Item) //nolint: errcheck proto.Merge(out, i) }). diff --git a/stream/tee_test.go b/stream/tee_test.go index ca4d23c..3ecc88f 100644 --- a/stream/tee_test.go +++ b/stream/tee_test.go @@ -47,7 +47,7 @@ func TestTeeReceiver_RecvMsg(t *testing.T) { mockReceiver: xmock.MockServerStream(func(s *xmock.ServerStream) { s.On("RecvMsg", &grpctest.Item{}). Run(func(args mock.Arguments) { - out := args.Get(0).(*grpctest.Item) // nolint: errcheck + out := args.Get(0).(*grpctest.Item) //nolint: errcheck out.Id = 42 }). Return(nil) diff --git a/streamer/client_test.go b/streamer/client_test.go index ab07b34..482b99d 100644 --- a/streamer/client_test.go +++ b/streamer/client_test.go @@ -34,7 +34,7 @@ func TestTeeClientStreamer(t *testing.T) { s.On("RecvMsg", &grpctest.Item{}). Once(). Run(func(args mock.Arguments) { - msg := args.Get(0).(*grpctest.Item) // nolint: errcheck + msg := args.Get(0).(*grpctest.Item) //nolint: errcheck msg.Id = 42 }). Return(nil) @@ -100,7 +100,7 @@ func TestClientStreamerPayload(t *testing.T) { mockStream: xmock.MockServerStream(func(s *xmock.ServerStream) { s.On("RecvMsg", &grpctest.Item{}).Once(). Run(func(args mock.Arguments) { - msg := args.Get(0).(*grpctest.Item) // nolint: errcheck + msg := args.Get(0).(*grpctest.Item) //nolint: errcheck msg.Id = 42 }). Return(nil) diff --git a/test/client_stream.go b/test/client_stream.go index 979c034..3cfefd4 100644 --- a/test/client_stream.go +++ b/test/client_stream.go @@ -34,7 +34,7 @@ func MockStreamRecvItemSuccess(i *grpctest.Item) func(s *xmock.ServerStream) { return func(s *xmock.ServerStream) { s.On("RecvMsg", &grpctest.Item{}).Once(). Run(func(args mock.Arguments) { - item := args.Get(0).(*grpctest.Item) // nolint: errcheck + item := args.Get(0).(*grpctest.Item) //nolint: errcheck proto.Merge(item, i) }). diff --git a/test/service.go b/test/service.go index 229cdbc..0a3a044 100644 --- a/test/service.go +++ b/test/service.go @@ -86,9 +86,9 @@ func StartServer(t *testing.T, opts ...ServiceOption) func(context.Context, stri srv := NewServer(opts...) go func() { - defer l.Close() // nolint: errcheck + defer l.Close() //nolint: errcheck - _ = srv.Serve(l) // nolint: errcheck + _ = srv.Serve(l) //nolint: errcheck }() t.Cleanup(func() { diff --git a/value/value_test.go b/value/value_test.go index 1f70fa1..65c785f 100644 --- a/value/value_test.go +++ b/value/value_test.go @@ -109,7 +109,7 @@ func TestMarshal(t *testing.T) { s.On("RecvMsg", &grpctest.Item{}). Once(). Run(func(args mock.Arguments) { - msg := args.Get(0).(*grpctest.Item) // nolint: errcheck + msg := args.Get(0).(*grpctest.Item) //nolint: errcheck msg.Id = 42 }). Return(nil)