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 b6f7ff8..6337b96 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 9cbb61e..e4b6356 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 fec181d..856f432 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 300c13f..63b0cf0 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 66088a9..dc85e3b 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...), ) diff --git a/transcoder.go b/transcoder.go index 52e85ab..d7c702b 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 { diff --git a/vanguard_test.go b/vanguard_test.go index f42a5f2..345a19b 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, @@ -904,6 +904,7 @@ func runRPCTestCase[Client any]( if streamMsg.out != nil && streamMsg.out.err != nil { expectedErr = streamMsg.out.err expectServerDone = streamMsg.out.msg == nil + expectServerCancel = true break } } @@ -919,21 +920,18 @@ 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: - if serverInvoked && serverErr != nil { + } else if serverInvoked { + assert.Error(t, serverErr) + 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). - if connect.CodeOf(serverErr) != connect.CodeOf(expectedErr) && !errors.Is(serverErr, context.Canceled) { - assert.Equal(t, connect.CodeCanceled, connect.CodeOf(serverErr)) - } + assert.Equal(t, connect.CodeCanceled, connect.CodeOf(serverErr)) + } else { + assert.Equal(t, expectedErr.Code(), 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 {