From 1de4fca0ccf1b44a9aa06349fd4caeb47075cd41 Mon Sep 17 00:00:00 2001 From: Nick Snyder Date: Tue, 26 Dec 2023 16:39:18 -0500 Subject: [PATCH 1/6] Update to connectrpc.com/connect v1.14.0 and google.golang.org/protobuf v1.32.0 --- buf.gen.yaml | 4 +- go.mod | 4 +- go.sum | 7 +- internal/gen/vanguard/test/v1/content.pb.go | 2 +- internal/gen/vanguard/test/v1/library.pb.go | 2 +- internal/gen/vanguard/test/v1/test.pb.go | 2 +- .../test/v1/testv1connect/content.connect.go | 35 ++++++--- .../test/v1/testv1connect/library.connect.go | 75 ++++++++++++++----- 8 files changed, 95 insertions(+), 36 deletions(-) diff --git a/buf.gen.yaml b/buf.gen.yaml index 8e8e7b4..84a2e09 100644 --- a/buf.gen.yaml +++ b/buf.gen.yaml @@ -6,10 +6,10 @@ managed: except: - buf.build/googleapis/googleapis plugins: - - plugin: buf.build/protocolbuffers/go:v1.31.0 + - plugin: buf.build/protocolbuffers/go:v1.32.0 out: internal/gen opt: paths=source_relative - - plugin: buf.build/connectrpc/go:v1.11.0 + - plugin: buf.build/connectrpc/go:v1.14.0 out: internal/gen opt: paths=source_relative # gRPC generated code is used by vanguardgrpc examples diff --git a/go.mod b/go.mod index dd0c5a5..68f3218 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( buf.build/gen/go/connectrpc/eliza/connectrpc/go v1.11.1-20230822171018-8b8b971d6fde.1 buf.build/gen/go/connectrpc/eliza/grpc/go v1.3.0-20230822171018-8b8b971d6fde.1 buf.build/gen/go/connectrpc/eliza/protocolbuffers/go v1.31.0-20230822171018-8b8b971d6fde.1 - connectrpc.com/connect v1.11.1 + connectrpc.com/connect v1.14.0 connectrpc.com/grpcreflect v1.2.0 github.com/google/go-cmp v0.5.9 github.com/stretchr/testify v1.8.4 @@ -15,7 +15,7 @@ require ( google.golang.org/genproto/googleapis/api v0.0.0-20230803162519-f966b187b2e5 google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 google.golang.org/grpc v1.58.3 - google.golang.org/protobuf v1.31.0 + google.golang.org/protobuf v1.32.0 ) require ( diff --git a/go.sum b/go.sum index 77d4390..819f2a0 100644 --- a/go.sum +++ b/go.sum @@ -391,8 +391,8 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= cloud.google.com/go/workflows v1.8.0/go.mod h1:ysGhmEajwZxGn1OhGOGKsTXc5PyxOc0vfKf5Af+to4M= cloud.google.com/go/workflows v1.9.0/go.mod h1:ZGkj1aFIOd9c8Gerkjjq7OW7I5+l6cSvT3ujaO/WwSA= -connectrpc.com/connect v1.11.1 h1:dqRwblixqkVh+OFBOOL1yIf1jS/yP0MSJLijRj29bFg= -connectrpc.com/connect v1.11.1/go.mod h1:3AGaO6RRGMx5IKFfqbe3hvK1NqLosFNP2BxDYTPmNPo= +connectrpc.com/connect v1.14.0 h1:PDS+J7uoz5Oui2VEOMcfz6Qft7opQM9hPiKvtGC01pA= +connectrpc.com/connect v1.14.0/go.mod h1:uoAq5bmhhn43TwhaKdGKN/bZcGtzPW1v+ngDTn5u+8s= connectrpc.com/grpcreflect v1.2.0 h1:Q6og1S7HinmtbEuBvARLNwYmTbhEGRpHDhqrPNlmK+U= connectrpc.com/grpcreflect v1.2.0/go.mod h1:nwSOKmE8nU5u/CidgHtPYk1PFI3U9ignz7iDMxOYkSY= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= @@ -1121,8 +1121,9 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= +google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/internal/gen/vanguard/test/v1/content.pb.go b/internal/gen/vanguard/test/v1/content.pb.go index a84d2c1..b30b5db 100644 --- a/internal/gen/vanguard/test/v1/content.pb.go +++ b/internal/gen/vanguard/test/v1/content.pb.go @@ -14,7 +14,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.32.0 // protoc (unknown) // source: vanguard/test/v1/content.proto diff --git a/internal/gen/vanguard/test/v1/library.pb.go b/internal/gen/vanguard/test/v1/library.pb.go index a973acd..2676691 100644 --- a/internal/gen/vanguard/test/v1/library.pb.go +++ b/internal/gen/vanguard/test/v1/library.pb.go @@ -14,7 +14,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.32.0 // protoc (unknown) // source: vanguard/test/v1/library.proto diff --git a/internal/gen/vanguard/test/v1/test.pb.go b/internal/gen/vanguard/test/v1/test.pb.go index b4ec655..d14c0c7 100644 --- a/internal/gen/vanguard/test/v1/test.pb.go +++ b/internal/gen/vanguard/test/v1/test.pb.go @@ -14,7 +14,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.32.0 // protoc (unknown) // source: vanguard/test/v1/test.proto diff --git a/internal/gen/vanguard/test/v1/testv1connect/content.connect.go b/internal/gen/vanguard/test/v1/testv1connect/content.connect.go index 456b29a..f49e616 100644 --- a/internal/gen/vanguard/test/v1/testv1connect/content.connect.go +++ b/internal/gen/vanguard/test/v1/testv1connect/content.connect.go @@ -34,7 +34,7 @@ import ( // generated with a version of connect newer than the one compiled into your binary. You can fix the // problem by either regenerating this code with an older version of connect or updating the connect // version compiled into your binary. -const _ = connect.IsAtLeastVersion0_1_0 +const _ = connect.IsAtLeastVersion1_13_0 const ( // ContentServiceName is the fully-qualified name of the ContentService service. @@ -60,6 +60,15 @@ const ( ContentServiceSubscribeProcedure = "/vanguard.test.v1.ContentService/Subscribe" ) +// These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. +var ( + contentServiceServiceDescriptor = v1.File_vanguard_test_v1_content_proto.Services().ByName("ContentService") + contentServiceIndexMethodDescriptor = contentServiceServiceDescriptor.Methods().ByName("Index") + contentServiceUploadMethodDescriptor = contentServiceServiceDescriptor.Methods().ByName("Upload") + contentServiceDownloadMethodDescriptor = contentServiceServiceDescriptor.Methods().ByName("Download") + contentServiceSubscribeMethodDescriptor = contentServiceServiceDescriptor.Methods().ByName("Subscribe") +) + // ContentServiceClient is a client for the vanguard.test.v1.ContentService service. type ContentServiceClient interface { // Index returns a html index page at the given path. @@ -85,22 +94,26 @@ func NewContentServiceClient(httpClient connect.HTTPClient, baseURL string, opts index: connect.NewClient[v1.IndexRequest, httpbody.HttpBody]( httpClient, baseURL+ContentServiceIndexProcedure, - opts..., + connect.WithSchema(contentServiceIndexMethodDescriptor), + connect.WithClientOptions(opts...), ), upload: connect.NewClient[v1.UploadRequest, emptypb.Empty]( httpClient, baseURL+ContentServiceUploadProcedure, - opts..., + connect.WithSchema(contentServiceUploadMethodDescriptor), + connect.WithClientOptions(opts...), ), download: connect.NewClient[v1.DownloadRequest, v1.DownloadResponse]( httpClient, baseURL+ContentServiceDownloadProcedure, - opts..., + connect.WithSchema(contentServiceDownloadMethodDescriptor), + connect.WithClientOptions(opts...), ), subscribe: connect.NewClient[v1.SubscribeRequest, v1.SubscribeResponse]( httpClient, baseURL+ContentServiceSubscribeProcedure, - opts..., + connect.WithSchema(contentServiceSubscribeMethodDescriptor), + connect.WithClientOptions(opts...), ), } } @@ -154,22 +167,26 @@ func NewContentServiceHandler(svc ContentServiceHandler, opts ...connect.Handler contentServiceIndexHandler := connect.NewUnaryHandler( ContentServiceIndexProcedure, svc.Index, - opts..., + connect.WithSchema(contentServiceIndexMethodDescriptor), + connect.WithHandlerOptions(opts...), ) contentServiceUploadHandler := connect.NewClientStreamHandler( ContentServiceUploadProcedure, svc.Upload, - opts..., + connect.WithSchema(contentServiceUploadMethodDescriptor), + connect.WithHandlerOptions(opts...), ) contentServiceDownloadHandler := connect.NewServerStreamHandler( ContentServiceDownloadProcedure, svc.Download, - opts..., + connect.WithSchema(contentServiceDownloadMethodDescriptor), + connect.WithHandlerOptions(opts...), ) contentServiceSubscribeHandler := connect.NewBidiStreamHandler( ContentServiceSubscribeProcedure, svc.Subscribe, - opts..., + connect.WithSchema(contentServiceSubscribeMethodDescriptor), + connect.WithHandlerOptions(opts...), ) return "/vanguard.test.v1.ContentService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { diff --git a/internal/gen/vanguard/test/v1/testv1connect/library.connect.go b/internal/gen/vanguard/test/v1/testv1connect/library.connect.go index dc6df69..f1367e1 100644 --- a/internal/gen/vanguard/test/v1/testv1connect/library.connect.go +++ b/internal/gen/vanguard/test/v1/testv1connect/library.connect.go @@ -33,7 +33,7 @@ import ( // generated with a version of connect newer than the one compiled into your binary. You can fix the // problem by either regenerating this code with an older version of connect or updating the connect // version compiled into your binary. -const _ = connect.IsAtLeastVersion1_7_0 +const _ = connect.IsAtLeastVersion1_13_0 const ( // LibraryServiceName is the fully-qualified name of the LibraryService service. @@ -85,6 +85,23 @@ const ( LibraryServiceListCheckoutsProcedure = "/vanguard.test.v1.LibraryService/ListCheckouts" ) +// These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. +var ( + libraryServiceServiceDescriptor = v1.File_vanguard_test_v1_library_proto.Services().ByName("LibraryService") + libraryServiceGetBookMethodDescriptor = libraryServiceServiceDescriptor.Methods().ByName("GetBook") + libraryServiceCreateBookMethodDescriptor = libraryServiceServiceDescriptor.Methods().ByName("CreateBook") + libraryServiceListBooksMethodDescriptor = libraryServiceServiceDescriptor.Methods().ByName("ListBooks") + libraryServiceCreateShelfMethodDescriptor = libraryServiceServiceDescriptor.Methods().ByName("CreateShelf") + libraryServiceUpdateBookMethodDescriptor = libraryServiceServiceDescriptor.Methods().ByName("UpdateBook") + libraryServiceDeleteBookMethodDescriptor = libraryServiceServiceDescriptor.Methods().ByName("DeleteBook") + libraryServiceSearchBooksMethodDescriptor = libraryServiceServiceDescriptor.Methods().ByName("SearchBooks") + libraryServiceMoveBooksMethodDescriptor = libraryServiceServiceDescriptor.Methods().ByName("MoveBooks") + libraryServiceCheckoutBooksMethodDescriptor = libraryServiceServiceDescriptor.Methods().ByName("CheckoutBooks") + libraryServiceReturnBooksMethodDescriptor = libraryServiceServiceDescriptor.Methods().ByName("ReturnBooks") + libraryServiceGetCheckoutMethodDescriptor = libraryServiceServiceDescriptor.Methods().ByName("GetCheckout") + libraryServiceListCheckoutsMethodDescriptor = libraryServiceServiceDescriptor.Methods().ByName("ListCheckouts") +) + // LibraryServiceClient is a client for the vanguard.test.v1.LibraryService service. type LibraryServiceClient interface { // Gets a book. @@ -121,64 +138,76 @@ func NewLibraryServiceClient(httpClient connect.HTTPClient, baseURL string, opts getBook: connect.NewClient[v1.GetBookRequest, v1.Book]( httpClient, baseURL+LibraryServiceGetBookProcedure, + connect.WithSchema(libraryServiceGetBookMethodDescriptor), connect.WithIdempotency(connect.IdempotencyNoSideEffects), connect.WithClientOptions(opts...), ), createBook: connect.NewClient[v1.CreateBookRequest, v1.Book]( httpClient, baseURL+LibraryServiceCreateBookProcedure, - opts..., + connect.WithSchema(libraryServiceCreateBookMethodDescriptor), + connect.WithClientOptions(opts...), ), listBooks: connect.NewClient[v1.ListBooksRequest, v1.ListBooksResponse]( httpClient, baseURL+LibraryServiceListBooksProcedure, - opts..., + connect.WithSchema(libraryServiceListBooksMethodDescriptor), + connect.WithClientOptions(opts...), ), createShelf: connect.NewClient[v1.CreateShelfRequest, v1.Shelf]( httpClient, baseURL+LibraryServiceCreateShelfProcedure, - opts..., + connect.WithSchema(libraryServiceCreateShelfMethodDescriptor), + connect.WithClientOptions(opts...), ), updateBook: connect.NewClient[v1.UpdateBookRequest, v1.Book]( httpClient, baseURL+LibraryServiceUpdateBookProcedure, - opts..., + connect.WithSchema(libraryServiceUpdateBookMethodDescriptor), + connect.WithClientOptions(opts...), ), deleteBook: connect.NewClient[v1.DeleteBookRequest, emptypb.Empty]( httpClient, baseURL+LibraryServiceDeleteBookProcedure, - opts..., + connect.WithSchema(libraryServiceDeleteBookMethodDescriptor), + connect.WithClientOptions(opts...), ), searchBooks: connect.NewClient[v1.SearchBooksRequest, v1.SearchBooksResponse]( httpClient, baseURL+LibraryServiceSearchBooksProcedure, + connect.WithSchema(libraryServiceSearchBooksMethodDescriptor), connect.WithIdempotency(connect.IdempotencyNoSideEffects), connect.WithClientOptions(opts...), ), moveBooks: connect.NewClient[v1.MoveBooksRequest, v1.MoveBooksResponse]( httpClient, baseURL+LibraryServiceMoveBooksProcedure, - opts..., + connect.WithSchema(libraryServiceMoveBooksMethodDescriptor), + connect.WithClientOptions(opts...), ), checkoutBooks: connect.NewClient[v1.CheckoutBooksRequest, v1.Checkout]( httpClient, baseURL+LibraryServiceCheckoutBooksProcedure, - opts..., + connect.WithSchema(libraryServiceCheckoutBooksMethodDescriptor), + connect.WithClientOptions(opts...), ), returnBooks: connect.NewClient[v1.ReturnBooksRequest, emptypb.Empty]( httpClient, baseURL+LibraryServiceReturnBooksProcedure, - opts..., + connect.WithSchema(libraryServiceReturnBooksMethodDescriptor), + connect.WithClientOptions(opts...), ), getCheckout: connect.NewClient[v1.GetCheckoutRequest, v1.Checkout]( httpClient, baseURL+LibraryServiceGetCheckoutProcedure, + connect.WithSchema(libraryServiceGetCheckoutMethodDescriptor), connect.WithIdempotency(connect.IdempotencyNoSideEffects), connect.WithClientOptions(opts...), ), listCheckouts: connect.NewClient[v1.ListCheckoutsRequest, v1.ListCheckoutsResponse]( httpClient, baseURL+LibraryServiceListCheckoutsProcedure, + connect.WithSchema(libraryServiceListCheckoutsMethodDescriptor), connect.WithIdempotency(connect.IdempotencyNoSideEffects), connect.WithClientOptions(opts...), ), @@ -293,64 +322,76 @@ func NewLibraryServiceHandler(svc LibraryServiceHandler, opts ...connect.Handler libraryServiceGetBookHandler := connect.NewUnaryHandler( LibraryServiceGetBookProcedure, svc.GetBook, + connect.WithSchema(libraryServiceGetBookMethodDescriptor), connect.WithIdempotency(connect.IdempotencyNoSideEffects), connect.WithHandlerOptions(opts...), ) libraryServiceCreateBookHandler := connect.NewUnaryHandler( LibraryServiceCreateBookProcedure, svc.CreateBook, - opts..., + connect.WithSchema(libraryServiceCreateBookMethodDescriptor), + connect.WithHandlerOptions(opts...), ) libraryServiceListBooksHandler := connect.NewUnaryHandler( LibraryServiceListBooksProcedure, svc.ListBooks, - opts..., + connect.WithSchema(libraryServiceListBooksMethodDescriptor), + connect.WithHandlerOptions(opts...), ) libraryServiceCreateShelfHandler := connect.NewUnaryHandler( LibraryServiceCreateShelfProcedure, svc.CreateShelf, - opts..., + connect.WithSchema(libraryServiceCreateShelfMethodDescriptor), + connect.WithHandlerOptions(opts...), ) libraryServiceUpdateBookHandler := connect.NewUnaryHandler( LibraryServiceUpdateBookProcedure, svc.UpdateBook, - opts..., + connect.WithSchema(libraryServiceUpdateBookMethodDescriptor), + connect.WithHandlerOptions(opts...), ) libraryServiceDeleteBookHandler := connect.NewUnaryHandler( LibraryServiceDeleteBookProcedure, svc.DeleteBook, - opts..., + connect.WithSchema(libraryServiceDeleteBookMethodDescriptor), + connect.WithHandlerOptions(opts...), ) libraryServiceSearchBooksHandler := connect.NewUnaryHandler( LibraryServiceSearchBooksProcedure, svc.SearchBooks, + connect.WithSchema(libraryServiceSearchBooksMethodDescriptor), connect.WithIdempotency(connect.IdempotencyNoSideEffects), connect.WithHandlerOptions(opts...), ) libraryServiceMoveBooksHandler := connect.NewUnaryHandler( LibraryServiceMoveBooksProcedure, svc.MoveBooks, - opts..., + connect.WithSchema(libraryServiceMoveBooksMethodDescriptor), + connect.WithHandlerOptions(opts...), ) libraryServiceCheckoutBooksHandler := connect.NewUnaryHandler( LibraryServiceCheckoutBooksProcedure, svc.CheckoutBooks, - opts..., + connect.WithSchema(libraryServiceCheckoutBooksMethodDescriptor), + connect.WithHandlerOptions(opts...), ) libraryServiceReturnBooksHandler := connect.NewUnaryHandler( LibraryServiceReturnBooksProcedure, svc.ReturnBooks, - opts..., + connect.WithSchema(libraryServiceReturnBooksMethodDescriptor), + connect.WithHandlerOptions(opts...), ) libraryServiceGetCheckoutHandler := connect.NewUnaryHandler( LibraryServiceGetCheckoutProcedure, svc.GetCheckout, + connect.WithSchema(libraryServiceGetCheckoutMethodDescriptor), connect.WithIdempotency(connect.IdempotencyNoSideEffects), connect.WithHandlerOptions(opts...), ) libraryServiceListCheckoutsHandler := connect.NewUnaryHandler( LibraryServiceListCheckoutsProcedure, svc.ListCheckouts, + connect.WithSchema(libraryServiceListCheckoutsMethodDescriptor), connect.WithIdempotency(connect.IdempotencyNoSideEffects), connect.WithHandlerOptions(opts...), ) From c3dd0142a9c68de91e229b8a2a521e1a2d494c89 Mon Sep 17 00:00:00 2001 From: Edward McFarlane Date: Fri, 29 Dec 2023 10:58:42 +0100 Subject: [PATCH 2/6] Fix assertion for Content-Type on GET requests For GET request Content-Type is not required and is now rejected by connect. --- vanguard_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vanguard_test.go b/vanguard_test.go index 5f2286d..60b5ae8 100644 --- a/vanguard_test.go +++ b/vanguard_test.go @@ -838,7 +838,7 @@ func protocolAssertMiddleware( "Content-Type": {fmt.Sprintf("application/connect+%s", codec)}, "Connect-Content-Encoding": allowedCompression, } - } else { + } else if req.Method == http.MethodPost { wantHdr = map[string][]string{ "Content-Type": {fmt.Sprintf("application/%s", codec)}, "Content-Encoding": allowedCompression, From e6323e09104cd5dfba9cda5e55ef18201df9b1fb Mon Sep 17 00:00:00 2001 From: Edward McFarlane Date: Fri, 29 Dec 2023 12:01:29 +0100 Subject: [PATCH 3/6] Fix WriteTo not trigger Write on zero length With the new Send operation a bytes.Buffer will use the WriteTo method to write the response body. On a zero length payload Write will not be called. Make the body handling more robust by calling Write(nil) to trigger a body write. --- transcoder.go | 1 + 1 file changed, 1 insertion(+) diff --git a/transcoder.go b/transcoder.go index fb7a74e..468fa26 100644 --- a/transcoder.go +++ b/transcoder.go @@ -1249,6 +1249,7 @@ func (w *responseWriter) close() { w.WriteHeader(http.StatusOK) } if w.w != nil { + _, _ = w.w.Write(nil) // trigger any final writes _ = w.w.Close() } if w.endWritten { From 6e6e92b0dd1838046fd919a98f0b77f7727f634d Mon Sep 17 00:00:00 2001 From: Edward McFarlane Date: Fri, 29 Dec 2023 12:36:15 +0100 Subject: [PATCH 4/6] Handle error testing with context cancels Fallback to allow context cancel errors if the server errors. --- vanguard_test.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/vanguard_test.go b/vanguard_test.go index 60b5ae8..2c5d6c8 100644 --- a/vanguard_test.go +++ b/vanguard_test.go @@ -893,12 +893,10 @@ func runRPCTestCase[Client any]( } var expectedErr *connect.Error expectServerDone := true - var expectServerCancel bool for _, streamMsg := range stream.msgs { if streamMsg.in != nil && streamMsg.in.err != nil { expectedErr = streamMsg.in.err expectServerDone = false - expectServerCancel = true break } if streamMsg.out != nil && streamMsg.out.err != nil { @@ -919,10 +917,13 @@ func runRPCTestCase[Client any]( assert.Equal(t, receivedErr.Code(), connect.CodeOf(err)) } // Also check the error observed by the server. - switch { - case expectedErr == nil: + if expectedErr == nil { assert.NoError(t, serverErr) - case expectServerCancel: + } else { + if serverErr == nil { + serverErr = err + } + assert.Error(t, serverErr) if serverInvoked && serverErr != nil { // We expect the server to either have seen the same error or it later // observed a cancel error (since the middleware cancels the request @@ -931,9 +932,6 @@ func runRPCTestCase[Client any]( assert.Equal(t, connect.CodeCanceled, connect.CodeOf(serverErr)) } } - default: - assert.Error(t, serverErr) - assert.Equal(t, expectedErr.Code(), connect.CodeOf(serverErr)) } assert.Subset(t, headers, stream.rspHeader) if stream.err == nil { From 7c03a8f053d406377ee9fc1e6b3f45a1a9719d30 Mon Sep 17 00:00:00 2001 From: Edward McFarlane Date: Fri, 29 Dec 2023 12:49:13 +0100 Subject: [PATCH 5/6] Fix lint for serverErr test --- vanguard_test.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/vanguard_test.go b/vanguard_test.go index 2c5d6c8..f81a1b0 100644 --- a/vanguard_test.go +++ b/vanguard_test.go @@ -919,18 +919,13 @@ func runRPCTestCase[Client any]( // Also check the error observed by the server. if expectedErr == nil { assert.NoError(t, serverErr) - } else { - if serverErr == nil { - serverErr = err - } + } else if serverInvoked { assert.Error(t, serverErr) - if serverInvoked && serverErr != nil { - // We expect the server to either have seen the same error or it later - // observed a cancel error (since the middleware cancels the request - // after it aborts the operation). - if connect.CodeOf(serverErr) != connect.CodeOf(expectedErr) && !errors.Is(serverErr, context.Canceled) { - assert.Equal(t, connect.CodeCanceled, connect.CodeOf(serverErr)) - } + // We expect the server to either have seen the same error or it later + // observed a cancel error (since the middleware cancels the request + // after it aborts the operation). + if connect.CodeOf(serverErr) != connect.CodeOf(expectedErr) && !errors.Is(serverErr, context.Canceled) { + assert.Equal(t, connect.CodeCanceled, connect.CodeOf(serverErr)) } } assert.Subset(t, headers, stream.rspHeader) From 3885bf36d27315f8adf558bae40e8dc4c2357850 Mon Sep 17 00:00:00 2001 From: Edward McFarlane Date: Fri, 5 Jan 2024 20:50:19 +0100 Subject: [PATCH 6/6] Readd expectServerCancel check on message errors --- vanguard_test.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/vanguard_test.go b/vanguard_test.go index f81a1b0..2c6542c 100644 --- a/vanguard_test.go +++ b/vanguard_test.go @@ -893,15 +893,18 @@ func runRPCTestCase[Client any]( } var expectedErr *connect.Error expectServerDone := true + var expectServerCancel bool for _, streamMsg := range stream.msgs { if streamMsg.in != nil && streamMsg.in.err != nil { expectedErr = streamMsg.in.err expectServerDone = false + expectServerCancel = true break } if streamMsg.out != nil && streamMsg.out.err != nil { expectedErr = streamMsg.out.err expectServerDone = streamMsg.out.msg == nil + expectServerCancel = true break } } @@ -921,11 +924,13 @@ func runRPCTestCase[Client any]( assert.NoError(t, serverErr) } else if serverInvoked { assert.Error(t, serverErr) - // We expect the server to either have seen the same error or it later - // observed a cancel error (since the middleware cancels the request - // after it aborts the operation). - if connect.CodeOf(serverErr) != connect.CodeOf(expectedErr) && !errors.Is(serverErr, context.Canceled) { + if expectServerCancel && connect.CodeOf(serverErr) != connect.CodeOf(expectedErr) { + // We expect the server to either have seen the same error or it later + // observed a cancel error (since the middleware cancels the request + // after it aborts the operation). assert.Equal(t, connect.CodeCanceled, connect.CodeOf(serverErr)) + } else { + assert.Equal(t, expectedErr.Code(), connect.CodeOf(serverErr)) } } assert.Subset(t, headers, stream.rspHeader)