diff --git a/codegen/service/templates/endpoint.go.tpl b/codegen/service/templates/endpoint.go.tpl index 8b4222f1d1..fea81a115b 100644 --- a/codegen/service/templates/endpoint.go.tpl +++ b/codegen/service/templates/endpoint.go.tpl @@ -24,6 +24,6 @@ func (s *{{ .ServiceVarName }}srvc) {{ .VarName }}(ctx context.Context{{ if .Pay {{- end }} {{- end }} {{- end }} - log.Print(ctx, "{{ .ServiceVarName }}.{{ .Name }}") + log.Printf(ctx, "{{ .ServiceVarName }}.{{ .Name }}") return } diff --git a/grpc/codegen/client-no-server-pkgpath.golden b/grpc/codegen/client-no-server-pkgpath.golden index d593940778..56ca0253c8 100644 --- a/grpc/codegen/client-no-server-pkgpath.golden +++ b/grpc/codegen/client-no-server-pkgpath.golden @@ -8,8 +8,8 @@ import ( "google.golang.org/grpc/credentials/insecure" ) -func doGRPC(scheme, host string, timeout int, debug bool) (goa.Endpoint, any, error) { - conn, err := grpc.Dial(host, grpc.WithTransportCredentials(insecure.NewCredentials())) +func doGRPC(_, host string, _ int, _ bool) (goa.Endpoint, any, error) { + conn, err := grpc.NewClient(host, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { fmt.Fprintf(os.Stderr, "could not connect to gRPC server at %s: %v\n", host, err) } diff --git a/grpc/codegen/client-no-server.golden b/grpc/codegen/client-no-server.golden index 8d18d0d9aa..b6a7c341da 100644 --- a/grpc/codegen/client-no-server.golden +++ b/grpc/codegen/client-no-server.golden @@ -8,8 +8,8 @@ import ( "google.golang.org/grpc/credentials/insecure" ) -func doGRPC(scheme, host string, timeout int, debug bool) (goa.Endpoint, any, error) { - conn, err := grpc.Dial(host, grpc.WithTransportCredentials(insecure.NewCredentials())) +func doGRPC(_, host string, _ int, _ bool) (goa.Endpoint, any, error) { + conn, err := grpc.NewClient(host, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { fmt.Fprintf(os.Stderr, "could not connect to gRPC server at %s: %v\n", host, err) } diff --git a/grpc/codegen/client-server-hosting-multiple-services-pkgpath.golden b/grpc/codegen/client-server-hosting-multiple-services-pkgpath.golden index 6a85da9f60..22ea9249b5 100644 --- a/grpc/codegen/client-server-hosting-multiple-services-pkgpath.golden +++ b/grpc/codegen/client-server-hosting-multiple-services-pkgpath.golden @@ -8,8 +8,8 @@ import ( "google.golang.org/grpc/credentials/insecure" ) -func doGRPC(scheme, host string, timeout int, debug bool) (goa.Endpoint, any, error) { - conn, err := grpc.Dial(host, grpc.WithTransportCredentials(insecure.NewCredentials())) +func doGRPC(_, host string, _ int, _ bool) (goa.Endpoint, any, error) { + conn, err := grpc.NewClient(host, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { fmt.Fprintf(os.Stderr, "could not connect to gRPC server at %s: %v\n", host, err) } diff --git a/grpc/codegen/client-server-hosting-multiple-services.golden b/grpc/codegen/client-server-hosting-multiple-services.golden index 910d906213..6956659be3 100644 --- a/grpc/codegen/client-server-hosting-multiple-services.golden +++ b/grpc/codegen/client-server-hosting-multiple-services.golden @@ -8,8 +8,8 @@ import ( "google.golang.org/grpc/credentials/insecure" ) -func doGRPC(scheme, host string, timeout int, debug bool) (goa.Endpoint, any, error) { - conn, err := grpc.Dial(host, grpc.WithTransportCredentials(insecure.NewCredentials())) +func doGRPC(_, host string, _ int, _ bool) (goa.Endpoint, any, error) { + conn, err := grpc.NewClient(host, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { fmt.Fprintf(os.Stderr, "could not connect to gRPC server at %s: %v\n", host, err) } diff --git a/grpc/codegen/client-server-hosting-service-subset-pkgpath.golden b/grpc/codegen/client-server-hosting-service-subset-pkgpath.golden index 6a85da9f60..22ea9249b5 100644 --- a/grpc/codegen/client-server-hosting-service-subset-pkgpath.golden +++ b/grpc/codegen/client-server-hosting-service-subset-pkgpath.golden @@ -8,8 +8,8 @@ import ( "google.golang.org/grpc/credentials/insecure" ) -func doGRPC(scheme, host string, timeout int, debug bool) (goa.Endpoint, any, error) { - conn, err := grpc.Dial(host, grpc.WithTransportCredentials(insecure.NewCredentials())) +func doGRPC(_, host string, _ int, _ bool) (goa.Endpoint, any, error) { + conn, err := grpc.NewClient(host, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { fmt.Fprintf(os.Stderr, "could not connect to gRPC server at %s: %v\n", host, err) } diff --git a/grpc/codegen/client-server-hosting-service-subset.golden b/grpc/codegen/client-server-hosting-service-subset.golden index 910d906213..6956659be3 100644 --- a/grpc/codegen/client-server-hosting-service-subset.golden +++ b/grpc/codegen/client-server-hosting-service-subset.golden @@ -8,8 +8,8 @@ import ( "google.golang.org/grpc/credentials/insecure" ) -func doGRPC(scheme, host string, timeout int, debug bool) (goa.Endpoint, any, error) { - conn, err := grpc.Dial(host, grpc.WithTransportCredentials(insecure.NewCredentials())) +func doGRPC(_, host string, _ int, _ bool) (goa.Endpoint, any, error) { + conn, err := grpc.NewClient(host, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { fmt.Fprintf(os.Stderr, "could not connect to gRPC server at %s: %v\n", host, err) } diff --git a/grpc/codegen/templates/do_grpc_cli.go.tpl b/grpc/codegen/templates/do_grpc_cli.go.tpl index 9095ca6b58..8802e20c69 100644 --- a/grpc/codegen/templates/do_grpc_cli.go.tpl +++ b/grpc/codegen/templates/do_grpc_cli.go.tpl @@ -1,5 +1,5 @@ -func doGRPC(scheme, host string, timeout int, debug bool) (goa.Endpoint, any, error) { - conn, err := grpc.Dial(host, grpc.WithTransportCredentials(insecure.NewCredentials())) +func doGRPC(_, host string, _ int, _ bool) (goa.Endpoint, any, error) { + conn, err := grpc.NewClient(host, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { fmt.Fprintf(os.Stderr, "could not connect to gRPC server at %s: %v\n", host, err) } diff --git a/grpc/middleware/canceler_test.go b/grpc/middleware/canceler_test.go index ff2d8d7637..920b4cf95c 100644 --- a/grpc/middleware/canceler_test.go +++ b/grpc/middleware/canceler_test.go @@ -4,8 +4,10 @@ import ( "context" "testing" - grpcm "goa.design/goa/v3/grpc/middleware" + "github.com/stretchr/testify/assert" "google.golang.org/grpc" + + grpcm "goa.design/goa/v3/grpc/middleware" ) type ( @@ -46,15 +48,11 @@ func TestStreamCanceler(t *testing.T) { for _, c := range cases { t.Run(c.name, func(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) - - go func() { - cancel() - }() - - if err := grpcm.StreamCanceler(ctx)(nil, c.stream, stream, c.handler); err != nil { - if err.Error() != "server is stopping" { - t.Errorf("StreamCanceler error: %v", err) - } + interceptor := grpcm.StreamCanceler(ctx) + cancel() + err := interceptor(nil, c.stream, stream, c.handler) + if err != nil { + assert.ErrorContains(t, err, "server is stopping") } }) }