From b5eaf014c4dea216181193b2e9f5472063a54c9d Mon Sep 17 00:00:00 2001 From: Niclas Thall Date: Thu, 17 Oct 2024 13:50:34 +0200 Subject: [PATCH] feat(sage): bump to v0.326.0 --- .sage/go.mod | 2 +- .sage/go.sum | 4 +- .../book/v1beta1/shipment_service.pb.go | 2 + .../book/v1beta1/shipment_service_cli.pb.go | 2 +- .../book/v1beta1/shipment_service.proto | 2 + .../saga/extend/auth/v1beta1/aiptest.pb.go | 15 ++ .../saga/extend/book/v1beta1/aiptest.pb.go | 21 +++ .../v1beta1/booking_service_aiptest.pb.go | 124 ++++++++++------ .../book/v1beta1/shipment_service.pb.go | 2 + .../v1beta1/shipment_service_aiptest.pb.go | 132 +++++++++++------- ...pment_tracking_event_service_aiptest.pb.go | 92 ++++++++---- 11 files changed, 268 insertions(+), 130 deletions(-) create mode 100644 proto/gen/go/einride/saga/extend/auth/v1beta1/aiptest.pb.go create mode 100644 proto/gen/go/einride/saga/extend/book/v1beta1/aiptest.pb.go diff --git a/.sage/go.mod b/.sage/go.mod index 78df8d9..1894c44 100644 --- a/.sage/go.mod +++ b/.sage/go.mod @@ -2,4 +2,4 @@ module sage go 1.22.4 -require go.einride.tech/sage v0.295.1 +require go.einride.tech/sage v0.326.0 diff --git a/.sage/go.sum b/.sage/go.sum index 58e6072..395071c 100644 --- a/.sage/go.sum +++ b/.sage/go.sum @@ -1,2 +1,2 @@ -go.einride.tech/sage v0.295.1 h1:rJyLp3HOCHTkHCVyN5dTpcEDz2wmpYh/6aynAq4MymE= -go.einride.tech/sage v0.295.1/go.mod h1:EzV5uciFX7/2ho8EKB5K9JghOfXIxlzs694b+Tkl5GQ= +go.einride.tech/sage v0.326.0 h1:79zs6EFUgAhQk5WVillbn2mfVT+I57cpu+CU0XIB8m8= +go.einride.tech/sage v0.326.0/go.mod h1:EzV5uciFX7/2ho8EKB5K9JghOfXIxlzs694b+Tkl5GQ= diff --git a/cmd/saga/gen/einride/saga/extend/book/v1beta1/shipment_service.pb.go b/cmd/saga/gen/einride/saga/extend/book/v1beta1/shipment_service.pb.go index 8ff7e4f..5621b08 100644 --- a/cmd/saga/gen/einride/saga/extend/book/v1beta1/shipment_service.pb.go +++ b/cmd/saga/gen/einride/saga/extend/book/v1beta1/shipment_service.pb.go @@ -431,6 +431,8 @@ type UpdateShipmentRequest struct { // This applies also for empty update mask partial update // For the `FieldMask` definition, see: // https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask + // Disable false positives for required update mask, keep as is. + // (-- api-linter: core::0134::update-mask-optional-behavior=disabled --) UpdateMask *fieldmaskpb.FieldMask `protobuf:"bytes,2,opt,name=update_mask,json=updateMask,proto3" json:"update_mask,omitempty"` } diff --git a/cmd/saga/gen/einride/saga/extend/book/v1beta1/shipment_service_cli.pb.go b/cmd/saga/gen/einride/saga/extend/book/v1beta1/shipment_service_cli.pb.go index 1f77448..feb8c5d 100644 --- a/cmd/saga/gen/einride/saga/extend/book/v1beta1/shipment_service_cli.pb.go +++ b/cmd/saga/gen/einride/saga/extend/book/v1beta1/shipment_service_cli.pb.go @@ -196,7 +196,7 @@ func NewShipmentServiceCommand(config aipcli.Config) *cobra.Command { "einride.saga.extend.book.v1beta1.Unit.weight": " Unit weight\n", "einride.saga.extend.book.v1beta1.Unit.width": " Unit width\n", "einride.saga.extend.book.v1beta1.UpdateShipmentRequest.shipment": " The resource which replaces the current resource.\n", - "einride.saga.extend.book.v1beta1.UpdateShipmentRequest.update_mask": " The update mask applies to the shipment.\n\n Currently, it allows updating with the following:\n * external_reference_id\n * units\n For units you cannot update individual units, so you MUST provide all the other units\n * vehicle\n * vehicle.reference_id\n * vehicle.driver_reference_id\n * vehicle.carrier_reference_id\n * pickup_address\n * pickup_instructions\n * delivery_address\n * delivery_instructions\n * annotations\n * service\n\n The star (*) update mask will update the above listed masks\n This applies also for empty update mask partial update\n For the `FieldMask` definition, see:\n https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask\n", + "einride.saga.extend.book.v1beta1.UpdateShipmentRequest.update_mask": " The update mask applies to the shipment.\n\n Currently, it allows updating with the following:\n * external_reference_id\n * units\n For units you cannot update individual units, so you MUST provide all the other units\n * vehicle\n * vehicle.reference_id\n * vehicle.driver_reference_id\n * vehicle.carrier_reference_id\n * pickup_address\n * pickup_instructions\n * delivery_address\n * delivery_instructions\n * annotations\n * service\n\n The star (*) update mask will update the above listed masks\n This applies also for empty update mask partial update\n For the `FieldMask` definition, see:\n https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask\n Disable false positives for required update mask, keep as is.\n (-- api-linter: core::0134::update-mask-optional-behavior=disabled --)\n", "einride.saga.extend.book.v1beta1.Vehicle.carrier_reference_id": " Carrier reference id\n", "einride.saga.extend.book.v1beta1.Vehicle.driver_reference_id": " Driver reference id\n", "einride.saga.extend.book.v1beta1.Vehicle.reference_id": " Reference id\n", diff --git a/proto/einride/saga/extend/book/v1beta1/shipment_service.proto b/proto/einride/saga/extend/book/v1beta1/shipment_service.proto index b776ea4..fe20dee 100644 --- a/proto/einride/saga/extend/book/v1beta1/shipment_service.proto +++ b/proto/einride/saga/extend/book/v1beta1/shipment_service.proto @@ -348,5 +348,7 @@ message UpdateShipmentRequest { // This applies also for empty update mask partial update // For the `FieldMask` definition, see: // https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask + // Disable false positives for required update mask, keep as is. + // (-- api-linter: core::0134::update-mask-optional-behavior=disabled --) google.protobuf.FieldMask update_mask = 2 [(google.api.field_behavior) = REQUIRED]; } diff --git a/proto/gen/go/einride/saga/extend/auth/v1beta1/aiptest.pb.go b/proto/gen/go/einride/saga/extend/auth/v1beta1/aiptest.pb.go new file mode 100644 index 0000000..1899f1b --- /dev/null +++ b/proto/gen/go/einride/saga/extend/auth/v1beta1/aiptest.pb.go @@ -0,0 +1,15 @@ +// Code generated by protoc-gen-go-aip-test. DO NOT EDIT. + +package authv1beta1 + +import ( + testing "testing" +) + +// ServiceConfigProviders embeds providers for all services. +type ServiceConfigProviders interface { +} + +// TestServices is the main entrypoint for starting the AIP tests for all services. +func TestServices(t *testing.T, s ServiceConfigProviders) { +} diff --git a/proto/gen/go/einride/saga/extend/book/v1beta1/aiptest.pb.go b/proto/gen/go/einride/saga/extend/book/v1beta1/aiptest.pb.go new file mode 100644 index 0000000..6900585 --- /dev/null +++ b/proto/gen/go/einride/saga/extend/book/v1beta1/aiptest.pb.go @@ -0,0 +1,21 @@ +// Code generated by protoc-gen-go-aip-test. DO NOT EDIT. + +package bookv1beta1 + +import ( + testing "testing" +) + +// ServiceConfigProviders embeds providers for all services. +type ServiceConfigProviders interface { + BookingServiceTestSuiteConfigProvider + ShipmentServiceTestSuiteConfigProvider + ShipmentTrackingEventServiceTestSuiteConfigProvider +} + +// TestServices is the main entrypoint for starting the AIP tests for all services. +func TestServices(t *testing.T, s ServiceConfigProviders) { + testBookingService(t, s) + testShipmentService(t, s) + testShipmentTrackingEventService(t, s) +} diff --git a/proto/gen/go/einride/saga/extend/book/v1beta1/booking_service_aiptest.pb.go b/proto/gen/go/einride/saga/extend/book/v1beta1/booking_service_aiptest.pb.go index 93ed4d3..d3351fb 100644 --- a/proto/gen/go/einride/saga/extend/book/v1beta1/booking_service_aiptest.pb.go +++ b/proto/gen/go/einride/saga/extend/book/v1beta1/booking_service_aiptest.pb.go @@ -16,6 +16,34 @@ import ( time "time" ) +// BookingServiceTestSuiteConfigProvider is the interface to implement to decide which resources +// that should be tested and how it's configured. +type BookingServiceTestSuiteConfigProvider interface { + // BookingServiceTour should return a config, or nil, which means that the tests will be skipped. + BookingServiceTour(t *testing.T) *BookingServiceTourTestSuiteConfig +} + +// testBookingService is the main entrypoint for starting the AIP tests. +func testBookingService(t *testing.T, s BookingServiceTestSuiteConfigProvider) { + testBookingServiceTour(t, s) +} + +func testBookingServiceTour(t *testing.T, s BookingServiceTestSuiteConfigProvider) { + t.Run("Tour", func(t *testing.T) { + config := s.BookingServiceTour(t) + if config == nil { + t.Skip("Method BookingServiceTour not implemented") + } + if config.Service == nil { + t.Skip("Method BookingServiceTour.Service() not implemented") + } + if config.Context == nil { + config.Context = func() context.Context { return context.Background() } + } + config.test(t) + }) +} + type BookingServiceTestSuite struct { T *testing.T // Server to test. @@ -24,17 +52,21 @@ type BookingServiceTestSuite struct { func (fx BookingServiceTestSuite) TestTour(ctx context.Context, options BookingServiceTourTestSuiteConfig) { fx.T.Run("Tour", func(t *testing.T) { - options.ctx = ctx - options.service = fx.Server + options.Context = func() context.Context { return ctx } + options.Service = func() BookingServiceServer { return fx.Server } options.test(t) }) } type BookingServiceTourTestSuiteConfig struct { - ctx context.Context - service BookingServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() BookingServiceServer + // Context should return a new context. + // The context will be used for several tests. + Context func() context.Context // The parents to use when creating resources. // At least one parent needs to be set. Depending on methods available on the resource, // more may be required. If insufficient number of parents are @@ -66,7 +98,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testCreate(t *testing.T) { // Method should fail with InvalidArgument if no parent is provided. t.Run("missing parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateTour(fx.ctx, &CreateTourRequest{ + _, err := fx.Service().CreateTour(fx.Context(), &CreateTourRequest{ Parent: "", Tour: fx.Create(fx.nextParent(t, false)), }) @@ -76,7 +108,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testCreate(t *testing.T) { // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateTour(fx.ctx, &CreateTourRequest{ + _, err := fx.Service().CreateTour(fx.Context(), &CreateTourRequest{ Parent: "invalid resource name", Tour: fx.Create(fx.nextParent(t, false)), }) @@ -88,7 +120,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testCreate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateTour(fx.ctx, &CreateTourRequest{ + msg, err := fx.Service().CreateTour(fx.Context(), &CreateTourRequest{ Parent: parent, Tour: fx.Create(parent), }) @@ -102,12 +134,12 @@ func (fx *BookingServiceTourTestSuiteConfig) testCreate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateTour(fx.ctx, &CreateTourRequest{ + msg, err := fx.Service().CreateTour(fx.Context(), &CreateTourRequest{ Parent: parent, Tour: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetTour(fx.ctx, &GetTourRequest{ + persisted, err := fx.Service().GetTour(fx.Context(), &GetTourRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -128,7 +160,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("sender") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTour(fx.ctx, &CreateTourRequest{ + _, err := fx.Service().CreateTour(fx.Context(), &CreateTourRequest{ Parent: parent, Tour: msg, }) @@ -144,7 +176,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("service_type") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTour(fx.ctx, &CreateTourRequest{ + _, err := fx.Service().CreateTour(fx.Context(), &CreateTourRequest{ Parent: parent, Tour: msg, }) @@ -160,7 +192,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("preliminary_shipments") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTour(fx.ctx, &CreateTourRequest{ + _, err := fx.Service().CreateTour(fx.Context(), &CreateTourRequest{ Parent: parent, Tour: msg, }) @@ -176,7 +208,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("stops") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTour(fx.ctx, &CreateTourRequest{ + _, err := fx.Service().CreateTour(fx.Context(), &CreateTourRequest{ Parent: parent, Tour: msg, }) @@ -197,7 +229,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Sender = "invalid resource name" - _, err := fx.service.CreateTour(fx.ctx, &CreateTourRequest{ + _, err := fx.Service().CreateTour(fx.Context(), &CreateTourRequest{ Parent: parent, Tour: msg, }) @@ -212,7 +244,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testGet(t *testing.T) { // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.GetTour(fx.ctx, &GetTourRequest{ + _, err := fx.Service().GetTour(fx.Context(), &GetTourRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -221,7 +253,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testGet(t *testing.T) { // Method should fail with InvalidArgument if the provided name is not valid. t.Run("invalid name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.GetTour(fx.ctx, &GetTourRequest{ + _, err := fx.Service().GetTour(fx.Context(), &GetTourRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -232,7 +264,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetTour(fx.ctx, &GetTourRequest{ + msg, err := fx.Service().GetTour(fx.Context(), &GetTourRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -244,7 +276,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetTour(fx.ctx, &GetTourRequest{ + _, err := fx.Service().GetTour(fx.Context(), &GetTourRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -253,7 +285,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testGet(t *testing.T) { // Method should fail with InvalidArgument if the provided name only contains wildcards ('-') t.Run("only wildcards", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.GetTour(fx.ctx, &GetTourRequest{ + _, err := fx.Service().GetTour(fx.Context(), &GetTourRequest{ Name: "spaces/-/tours/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -269,7 +301,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateTour(fx.ctx, &UpdateTourRequest{ + _, err := fx.Service().UpdateTour(fx.Context(), &UpdateTourRequest{ Tour: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -281,7 +313,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateTour(fx.ctx, &UpdateTourRequest{ + _, err := fx.Service().UpdateTour(fx.Context(), &UpdateTourRequest{ Tour: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -292,7 +324,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateTour(fx.ctx, &UpdateTourRequest{ + updated, err := fx.Service().UpdateTour(fx.Context(), &UpdateTourRequest{ Tour: created, }) assert.NilError(t, err) @@ -304,11 +336,11 @@ func (fx *BookingServiceTourTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateTour(fx.ctx, &UpdateTourRequest{ + updated, err := fx.Service().UpdateTour(fx.Context(), &UpdateTourRequest{ Tour: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetTour(fx.ctx, &GetTourRequest{ + persisted, err := fx.Service().GetTour(fx.Context(), &GetTourRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -321,7 +353,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) created := fx.create(t, parent) originalCreateTime := created.CreateTime - updated, err := fx.service.UpdateTour(fx.ctx, &UpdateTourRequest{ + updated, err := fx.Service().UpdateTour(fx.Context(), &UpdateTourRequest{ Tour: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -340,7 +372,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateTour(fx.ctx, &UpdateTourRequest{ + _, err := fx.Service().UpdateTour(fx.Context(), &UpdateTourRequest{ Tour: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -349,7 +381,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testUpdate(t *testing.T) { // The method should fail with InvalidArgument if the update_mask is invalid. t.Run("invalid update mask", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.UpdateTour(fx.ctx, &UpdateTourRequest{ + _, err := fx.Service().UpdateTour(fx.Context(), &UpdateTourRequest{ Tour: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -373,7 +405,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("sender") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateTour(fx.ctx, &UpdateTourRequest{ + _, err := fx.Service().UpdateTour(fx.Context(), &UpdateTourRequest{ Tour: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -392,7 +424,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("service_type") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateTour(fx.ctx, &UpdateTourRequest{ + _, err := fx.Service().UpdateTour(fx.Context(), &UpdateTourRequest{ Tour: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -411,7 +443,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("preliminary_shipments") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateTour(fx.ctx, &UpdateTourRequest{ + _, err := fx.Service().UpdateTour(fx.Context(), &UpdateTourRequest{ Tour: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -430,7 +462,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("stops") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateTour(fx.ctx, &UpdateTourRequest{ + _, err := fx.Service().UpdateTour(fx.Context(), &UpdateTourRequest{ Tour: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -449,7 +481,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testList(t *testing.T) { // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListTours(fx.ctx, &ListToursRequest{ + _, err := fx.Service().ListTours(fx.Context(), &ListToursRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -459,7 +491,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListTours(fx.ctx, &ListToursRequest{ + _, err := fx.Service().ListTours(fx.Context(), &ListToursRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -470,7 +502,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListTours(fx.ctx, &ListToursRequest{ + _, err := fx.Service().ListTours(fx.Context(), &ListToursRequest{ Parent: parent, PageSize: -10, }) @@ -488,7 +520,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListTours(fx.ctx, &ListToursRequest{ + response, err := fx.Service().ListTours(fx.Context(), &ListToursRequest{ Parent: parent, PageSize: 999, }) @@ -507,7 +539,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testList(t *testing.T) { // If there are no more resources, next_page_token should not be set. t.Run("last page", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListTours(fx.ctx, &ListToursRequest{ + response, err := fx.Service().ListTours(fx.Context(), &ListToursRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -518,7 +550,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testList(t *testing.T) { // If there are more resources, next_page_token should be set. t.Run("more pages", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListTours(fx.ctx, &ListToursRequest{ + response, err := fx.Service().ListTours(fx.Context(), &ListToursRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -532,7 +564,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Tour, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListTours(fx.ctx, &ListToursRequest{ + response, err := fx.Service().ListTours(fx.Context(), &ListToursRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -563,7 +595,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testSearch(t *testing.T) { // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.SearchTours(fx.ctx, &SearchToursRequest{ + _, err := fx.Service().SearchTours(fx.Context(), &SearchToursRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -573,7 +605,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testSearch(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.SearchTours(fx.ctx, &SearchToursRequest{ + _, err := fx.Service().SearchTours(fx.Context(), &SearchToursRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -584,7 +616,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testSearch(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.SearchTours(fx.ctx, &SearchToursRequest{ + _, err := fx.Service().SearchTours(fx.Context(), &SearchToursRequest{ Parent: parent, PageSize: -10, }) @@ -602,7 +634,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testSearch(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.SearchTours(fx.ctx, &SearchToursRequest{ + response, err := fx.Service().SearchTours(fx.Context(), &SearchToursRequest{ Parent: parent, PageSize: 999, }) @@ -621,7 +653,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testSearch(t *testing.T) { // If there are no more resources, next_page_token should not be set. t.Run("last page", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.SearchTours(fx.ctx, &SearchToursRequest{ + response, err := fx.Service().SearchTours(fx.Context(), &SearchToursRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -632,7 +664,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testSearch(t *testing.T) { // If there are more resources, next_page_token should be set. t.Run("more pages", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.SearchTours(fx.ctx, &SearchToursRequest{ + response, err := fx.Service().SearchTours(fx.Context(), &SearchToursRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -646,7 +678,7 @@ func (fx *BookingServiceTourTestSuiteConfig) testSearch(t *testing.T) { msgs := make([]*Tour, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.SearchTours(fx.ctx, &SearchToursRequest{ + response, err := fx.Service().SearchTours(fx.Context(), &SearchToursRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -700,7 +732,7 @@ func (fx *BookingServiceTourTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *BookingServiceTourTestSuiteConfig) create(t *testing.T, parent string) *Tour { t.Helper() - created, err := fx.service.CreateTour(fx.ctx, &CreateTourRequest{ + created, err := fx.Service().CreateTour(fx.Context(), &CreateTourRequest{ Parent: parent, Tour: fx.Create(parent), }) diff --git a/proto/gen/go/einride/saga/extend/book/v1beta1/shipment_service.pb.go b/proto/gen/go/einride/saga/extend/book/v1beta1/shipment_service.pb.go index 641d3b2..b729194 100644 --- a/proto/gen/go/einride/saga/extend/book/v1beta1/shipment_service.pb.go +++ b/proto/gen/go/einride/saga/extend/book/v1beta1/shipment_service.pb.go @@ -431,6 +431,8 @@ type UpdateShipmentRequest struct { // This applies also for empty update mask partial update // For the `FieldMask` definition, see: // https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask + // Disable false positives for required update mask, keep as is. + // (-- api-linter: core::0134::update-mask-optional-behavior=disabled --) UpdateMask *fieldmaskpb.FieldMask `protobuf:"bytes,2,opt,name=update_mask,json=updateMask,proto3" json:"update_mask,omitempty"` } diff --git a/proto/gen/go/einride/saga/extend/book/v1beta1/shipment_service_aiptest.pb.go b/proto/gen/go/einride/saga/extend/book/v1beta1/shipment_service_aiptest.pb.go index c7669f1..a807b07 100644 --- a/proto/gen/go/einride/saga/extend/book/v1beta1/shipment_service_aiptest.pb.go +++ b/proto/gen/go/einride/saga/extend/book/v1beta1/shipment_service_aiptest.pb.go @@ -16,6 +16,34 @@ import ( time "time" ) +// ShipmentServiceTestSuiteConfigProvider is the interface to implement to decide which resources +// that should be tested and how it's configured. +type ShipmentServiceTestSuiteConfigProvider interface { + // ShipmentServiceShipment should return a config, or nil, which means that the tests will be skipped. + ShipmentServiceShipment(t *testing.T) *ShipmentServiceShipmentTestSuiteConfig +} + +// testShipmentService is the main entrypoint for starting the AIP tests. +func testShipmentService(t *testing.T, s ShipmentServiceTestSuiteConfigProvider) { + testShipmentServiceShipment(t, s) +} + +func testShipmentServiceShipment(t *testing.T, s ShipmentServiceTestSuiteConfigProvider) { + t.Run("Shipment", func(t *testing.T) { + config := s.ShipmentServiceShipment(t) + if config == nil { + t.Skip("Method ShipmentServiceShipment not implemented") + } + if config.Service == nil { + t.Skip("Method ShipmentServiceShipment.Service() not implemented") + } + if config.Context == nil { + config.Context = func() context.Context { return context.Background() } + } + config.test(t) + }) +} + type ShipmentServiceTestSuite struct { T *testing.T // Server to test. @@ -24,17 +52,21 @@ type ShipmentServiceTestSuite struct { func (fx ShipmentServiceTestSuite) TestShipment(ctx context.Context, options ShipmentServiceShipmentTestSuiteConfig) { fx.T.Run("Shipment", func(t *testing.T) { - options.ctx = ctx - options.service = fx.Server + options.Context = func() context.Context { return ctx } + options.Service = func() ShipmentServiceServer { return fx.Server } options.test(t) }) } type ShipmentServiceShipmentTestSuiteConfig struct { - ctx context.Context - service ShipmentServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() ShipmentServiceServer + // Context should return a new context. + // The context will be used for several tests. + Context func() context.Context // The parents to use when creating resources. // At least one parent needs to be set. Depending on methods available on the resource, // more may be required. If insufficient number of parents are @@ -65,7 +97,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testCreate(t *testing.T) { // Method should fail with InvalidArgument if no parent is provided. t.Run("missing parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateShipment(fx.ctx, &CreateShipmentRequest{ + _, err := fx.Service().CreateShipment(fx.Context(), &CreateShipmentRequest{ Parent: "", Shipment: fx.Create(fx.nextParent(t, false)), }) @@ -75,7 +107,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testCreate(t *testing.T) { // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateShipment(fx.ctx, &CreateShipmentRequest{ + _, err := fx.Service().CreateShipment(fx.Context(), &CreateShipmentRequest{ Parent: "invalid resource name", Shipment: fx.Create(fx.nextParent(t, false)), }) @@ -87,7 +119,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testCreate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateShipment(fx.ctx, &CreateShipmentRequest{ + msg, err := fx.Service().CreateShipment(fx.Context(), &CreateShipmentRequest{ Parent: parent, Shipment: fx.Create(parent), }) @@ -101,12 +133,12 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testCreate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateShipment(fx.ctx, &CreateShipmentRequest{ + msg, err := fx.Service().CreateShipment(fx.Context(), &CreateShipmentRequest{ Parent: parent, Shipment: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetShipment(fx.ctx, &GetShipmentRequest{ + persisted, err := fx.Service().GetShipment(fx.Context(), &GetShipmentRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -127,7 +159,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("sender") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateShipment(fx.ctx, &CreateShipmentRequest{ + _, err := fx.Service().CreateShipment(fx.Context(), &CreateShipmentRequest{ Parent: parent, Shipment: msg, }) @@ -143,7 +175,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("recipient") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateShipment(fx.ctx, &CreateShipmentRequest{ + _, err := fx.Service().CreateShipment(fx.Context(), &CreateShipmentRequest{ Parent: parent, Shipment: msg, }) @@ -159,7 +191,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("line1") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateShipment(fx.ctx, &CreateShipmentRequest{ + _, err := fx.Service().CreateShipment(fx.Context(), &CreateShipmentRequest{ Parent: parent, Shipment: msg, }) @@ -175,7 +207,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("postal_code") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateShipment(fx.ctx, &CreateShipmentRequest{ + _, err := fx.Service().CreateShipment(fx.Context(), &CreateShipmentRequest{ Parent: parent, Shipment: msg, }) @@ -191,7 +223,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("city") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateShipment(fx.ctx, &CreateShipmentRequest{ + _, err := fx.Service().CreateShipment(fx.Context(), &CreateShipmentRequest{ Parent: parent, Shipment: msg, }) @@ -207,7 +239,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("region_code") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateShipment(fx.ctx, &CreateShipmentRequest{ + _, err := fx.Service().CreateShipment(fx.Context(), &CreateShipmentRequest{ Parent: parent, Shipment: msg, }) @@ -223,7 +255,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("delivery_address") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateShipment(fx.ctx, &CreateShipmentRequest{ + _, err := fx.Service().CreateShipment(fx.Context(), &CreateShipmentRequest{ Parent: parent, Shipment: msg, }) @@ -239,7 +271,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("units") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateShipment(fx.ctx, &CreateShipmentRequest{ + _, err := fx.Service().CreateShipment(fx.Context(), &CreateShipmentRequest{ Parent: parent, Shipment: msg, }) @@ -255,7 +287,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("reference_id") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateShipment(fx.ctx, &CreateShipmentRequest{ + _, err := fx.Service().CreateShipment(fx.Context(), &CreateShipmentRequest{ Parent: parent, Shipment: msg, }) @@ -276,7 +308,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Sender = "invalid resource name" - _, err := fx.service.CreateShipment(fx.ctx, &CreateShipmentRequest{ + _, err := fx.Service().CreateShipment(fx.Context(), &CreateShipmentRequest{ Parent: parent, Shipment: msg, }) @@ -291,7 +323,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Tour = "invalid resource name" - _, err := fx.service.CreateShipment(fx.ctx, &CreateShipmentRequest{ + _, err := fx.Service().CreateShipment(fx.Context(), &CreateShipmentRequest{ Parent: parent, Shipment: msg, }) @@ -306,7 +338,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testGet(t *testing.T) { // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.GetShipment(fx.ctx, &GetShipmentRequest{ + _, err := fx.Service().GetShipment(fx.Context(), &GetShipmentRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -315,7 +347,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testGet(t *testing.T) { // Method should fail with InvalidArgument if the provided name is not valid. t.Run("invalid name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.GetShipment(fx.ctx, &GetShipmentRequest{ + _, err := fx.Service().GetShipment(fx.Context(), &GetShipmentRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -326,7 +358,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetShipment(fx.ctx, &GetShipmentRequest{ + msg, err := fx.Service().GetShipment(fx.Context(), &GetShipmentRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -338,7 +370,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetShipment(fx.ctx, &GetShipmentRequest{ + _, err := fx.Service().GetShipment(fx.Context(), &GetShipmentRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -347,7 +379,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testGet(t *testing.T) { // Method should fail with InvalidArgument if the provided name only contains wildcards ('-') t.Run("only wildcards", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.GetShipment(fx.ctx, &GetShipmentRequest{ + _, err := fx.Service().GetShipment(fx.Context(), &GetShipmentRequest{ Name: "spaces/-/shipments/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -363,7 +395,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateShipment(fx.ctx, &UpdateShipmentRequest{ + _, err := fx.Service().UpdateShipment(fx.Context(), &UpdateShipmentRequest{ Shipment: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -375,7 +407,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateShipment(fx.ctx, &UpdateShipmentRequest{ + _, err := fx.Service().UpdateShipment(fx.Context(), &UpdateShipmentRequest{ Shipment: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -386,7 +418,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateShipment(fx.ctx, &UpdateShipmentRequest{ + updated, err := fx.Service().UpdateShipment(fx.Context(), &UpdateShipmentRequest{ Shipment: created, }) assert.NilError(t, err) @@ -398,11 +430,11 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateShipment(fx.ctx, &UpdateShipmentRequest{ + updated, err := fx.Service().UpdateShipment(fx.Context(), &UpdateShipmentRequest{ Shipment: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetShipment(fx.ctx, &GetShipmentRequest{ + persisted, err := fx.Service().GetShipment(fx.Context(), &GetShipmentRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -415,7 +447,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) created := fx.create(t, parent) originalCreateTime := created.CreateTime - updated, err := fx.service.UpdateShipment(fx.ctx, &UpdateShipmentRequest{ + updated, err := fx.Service().UpdateShipment(fx.Context(), &UpdateShipmentRequest{ Shipment: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -434,7 +466,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateShipment(fx.ctx, &UpdateShipmentRequest{ + _, err := fx.Service().UpdateShipment(fx.Context(), &UpdateShipmentRequest{ Shipment: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -443,7 +475,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testUpdate(t *testing.T) { // The method should fail with InvalidArgument if the update_mask is invalid. t.Run("invalid update mask", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.UpdateShipment(fx.ctx, &UpdateShipmentRequest{ + _, err := fx.Service().UpdateShipment(fx.Context(), &UpdateShipmentRequest{ Shipment: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -467,7 +499,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("sender") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateShipment(fx.ctx, &UpdateShipmentRequest{ + _, err := fx.Service().UpdateShipment(fx.Context(), &UpdateShipmentRequest{ Shipment: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -486,7 +518,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("recipient") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateShipment(fx.ctx, &UpdateShipmentRequest{ + _, err := fx.Service().UpdateShipment(fx.Context(), &UpdateShipmentRequest{ Shipment: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -505,7 +537,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("line1") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateShipment(fx.ctx, &UpdateShipmentRequest{ + _, err := fx.Service().UpdateShipment(fx.Context(), &UpdateShipmentRequest{ Shipment: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -524,7 +556,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("postal_code") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateShipment(fx.ctx, &UpdateShipmentRequest{ + _, err := fx.Service().UpdateShipment(fx.Context(), &UpdateShipmentRequest{ Shipment: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -543,7 +575,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("city") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateShipment(fx.ctx, &UpdateShipmentRequest{ + _, err := fx.Service().UpdateShipment(fx.Context(), &UpdateShipmentRequest{ Shipment: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -562,7 +594,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("region_code") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateShipment(fx.ctx, &UpdateShipmentRequest{ + _, err := fx.Service().UpdateShipment(fx.Context(), &UpdateShipmentRequest{ Shipment: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -581,7 +613,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("delivery_address") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateShipment(fx.ctx, &UpdateShipmentRequest{ + _, err := fx.Service().UpdateShipment(fx.Context(), &UpdateShipmentRequest{ Shipment: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -600,7 +632,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("units") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateShipment(fx.ctx, &UpdateShipmentRequest{ + _, err := fx.Service().UpdateShipment(fx.Context(), &UpdateShipmentRequest{ Shipment: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -619,7 +651,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("reference_id") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateShipment(fx.ctx, &UpdateShipmentRequest{ + _, err := fx.Service().UpdateShipment(fx.Context(), &UpdateShipmentRequest{ Shipment: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -638,7 +670,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testList(t *testing.T) { // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListShipments(fx.ctx, &ListShipmentsRequest{ + _, err := fx.Service().ListShipments(fx.Context(), &ListShipmentsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -648,7 +680,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListShipments(fx.ctx, &ListShipmentsRequest{ + _, err := fx.Service().ListShipments(fx.Context(), &ListShipmentsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -659,7 +691,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListShipments(fx.ctx, &ListShipmentsRequest{ + _, err := fx.Service().ListShipments(fx.Context(), &ListShipmentsRequest{ Parent: parent, PageSize: -10, }) @@ -677,7 +709,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListShipments(fx.ctx, &ListShipmentsRequest{ + response, err := fx.Service().ListShipments(fx.Context(), &ListShipmentsRequest{ Parent: parent, PageSize: 999, }) @@ -696,7 +728,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testList(t *testing.T) { // If there are no more resources, next_page_token should not be set. t.Run("last page", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListShipments(fx.ctx, &ListShipmentsRequest{ + response, err := fx.Service().ListShipments(fx.Context(), &ListShipmentsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -707,7 +739,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testList(t *testing.T) { // If there are more resources, next_page_token should be set. t.Run("more pages", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListShipments(fx.ctx, &ListShipmentsRequest{ + response, err := fx.Service().ListShipments(fx.Context(), &ListShipmentsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -721,7 +753,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Shipment, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListShipments(fx.ctx, &ListShipmentsRequest{ + response, err := fx.Service().ListShipments(fx.Context(), &ListShipmentsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -775,7 +807,7 @@ func (fx *ShipmentServiceShipmentTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *ShipmentServiceShipmentTestSuiteConfig) create(t *testing.T, parent string) *Shipment { t.Helper() - created, err := fx.service.CreateShipment(fx.ctx, &CreateShipmentRequest{ + created, err := fx.Service().CreateShipment(fx.Context(), &CreateShipmentRequest{ Parent: parent, Shipment: fx.Create(parent), }) diff --git a/proto/gen/go/einride/saga/extend/book/v1beta1/shipment_tracking_event_service_aiptest.pb.go b/proto/gen/go/einride/saga/extend/book/v1beta1/shipment_tracking_event_service_aiptest.pb.go index 3e042bb..d27cc12 100644 --- a/proto/gen/go/einride/saga/extend/book/v1beta1/shipment_tracking_event_service_aiptest.pb.go +++ b/proto/gen/go/einride/saga/extend/book/v1beta1/shipment_tracking_event_service_aiptest.pb.go @@ -14,6 +14,34 @@ import ( time "time" ) +// ShipmentTrackingEventServiceTestSuiteConfigProvider is the interface to implement to decide which resources +// that should be tested and how it's configured. +type ShipmentTrackingEventServiceTestSuiteConfigProvider interface { + // ShipmentTrackingEventServiceShipmentTrackingEvent should return a config, or nil, which means that the tests will be skipped. + ShipmentTrackingEventServiceShipmentTrackingEvent(t *testing.T) *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig +} + +// testShipmentTrackingEventService is the main entrypoint for starting the AIP tests. +func testShipmentTrackingEventService(t *testing.T, s ShipmentTrackingEventServiceTestSuiteConfigProvider) { + testShipmentTrackingEventServiceShipmentTrackingEvent(t, s) +} + +func testShipmentTrackingEventServiceShipmentTrackingEvent(t *testing.T, s ShipmentTrackingEventServiceTestSuiteConfigProvider) { + t.Run("ShipmentTrackingEvent", func(t *testing.T) { + config := s.ShipmentTrackingEventServiceShipmentTrackingEvent(t) + if config == nil { + t.Skip("Method ShipmentTrackingEventServiceShipmentTrackingEvent not implemented") + } + if config.Service == nil { + t.Skip("Method ShipmentTrackingEventServiceShipmentTrackingEvent.Service() not implemented") + } + if config.Context == nil { + config.Context = func() context.Context { return context.Background() } + } + config.test(t) + }) +} + type ShipmentTrackingEventServiceTestSuite struct { T *testing.T // Server to test. @@ -22,17 +50,21 @@ type ShipmentTrackingEventServiceTestSuite struct { func (fx ShipmentTrackingEventServiceTestSuite) TestShipmentTrackingEvent(ctx context.Context, options ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) { fx.T.Run("ShipmentTrackingEvent", func(t *testing.T) { - options.ctx = ctx - options.service = fx.Server + options.Context = func() context.Context { return ctx } + options.Service = func() ShipmentTrackingEventServiceServer { return fx.Server } options.test(t) }) } type ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig struct { - ctx context.Context - service ShipmentTrackingEventServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() ShipmentTrackingEventServiceServer + // Context should return a new context. + // The context will be used for several tests. + Context func() context.Context // The parents to use when creating resources. // At least one parent needs to be set. Depending on methods available on the resource, // more may be required. If insufficient number of parents are @@ -59,7 +91,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test // Method should fail with InvalidArgument if no parent is provided. t.Run("missing parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateShipmentTrackingEvent(fx.ctx, &CreateShipmentTrackingEventRequest{ + _, err := fx.Service().CreateShipmentTrackingEvent(fx.Context(), &CreateShipmentTrackingEventRequest{ Parent: "", ShipmentTrackingEvent: fx.Create(fx.nextParent(t, false)), }) @@ -69,7 +101,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateShipmentTrackingEvent(fx.ctx, &CreateShipmentTrackingEventRequest{ + _, err := fx.Service().CreateShipmentTrackingEvent(fx.Context(), &CreateShipmentTrackingEventRequest{ Parent: "invalid resource name", ShipmentTrackingEvent: fx.Create(fx.nextParent(t, false)), }) @@ -81,7 +113,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateShipmentTrackingEvent(fx.ctx, &CreateShipmentTrackingEventRequest{ + msg, err := fx.Service().CreateShipmentTrackingEvent(fx.Context(), &CreateShipmentTrackingEventRequest{ Parent: parent, ShipmentTrackingEvent: fx.Create(parent), }) @@ -95,12 +127,12 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateShipmentTrackingEvent(fx.ctx, &CreateShipmentTrackingEventRequest{ + msg, err := fx.Service().CreateShipmentTrackingEvent(fx.Context(), &CreateShipmentTrackingEventRequest{ Parent: parent, ShipmentTrackingEvent: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetShipmentTrackingEvent(fx.ctx, &GetShipmentTrackingEventRequest{ + persisted, err := fx.Service().GetShipmentTrackingEvent(fx.Context(), &GetShipmentTrackingEventRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -121,7 +153,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test } fd := container.ProtoReflect().Descriptor().Fields().ByName("code") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateShipmentTrackingEvent(fx.ctx, &CreateShipmentTrackingEventRequest{ + _, err := fx.Service().CreateShipmentTrackingEvent(fx.Context(), &CreateShipmentTrackingEventRequest{ Parent: parent, ShipmentTrackingEvent: msg, }) @@ -137,7 +169,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test } fd := container.ProtoReflect().Descriptor().Fields().ByName("occurred_time") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateShipmentTrackingEvent(fx.ctx, &CreateShipmentTrackingEventRequest{ + _, err := fx.Service().CreateShipmentTrackingEvent(fx.Context(), &CreateShipmentTrackingEventRequest{ Parent: parent, ShipmentTrackingEvent: msg, }) @@ -153,7 +185,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test } fd := container.ProtoReflect().Descriptor().Fields().ByName("recipient") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateShipmentTrackingEvent(fx.ctx, &CreateShipmentTrackingEventRequest{ + _, err := fx.Service().CreateShipmentTrackingEvent(fx.Context(), &CreateShipmentTrackingEventRequest{ Parent: parent, ShipmentTrackingEvent: msg, }) @@ -169,7 +201,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test } fd := container.ProtoReflect().Descriptor().Fields().ByName("line1") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateShipmentTrackingEvent(fx.ctx, &CreateShipmentTrackingEventRequest{ + _, err := fx.Service().CreateShipmentTrackingEvent(fx.Context(), &CreateShipmentTrackingEventRequest{ Parent: parent, ShipmentTrackingEvent: msg, }) @@ -185,7 +217,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test } fd := container.ProtoReflect().Descriptor().Fields().ByName("postal_code") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateShipmentTrackingEvent(fx.ctx, &CreateShipmentTrackingEventRequest{ + _, err := fx.Service().CreateShipmentTrackingEvent(fx.Context(), &CreateShipmentTrackingEventRequest{ Parent: parent, ShipmentTrackingEvent: msg, }) @@ -201,7 +233,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test } fd := container.ProtoReflect().Descriptor().Fields().ByName("city") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateShipmentTrackingEvent(fx.ctx, &CreateShipmentTrackingEventRequest{ + _, err := fx.Service().CreateShipmentTrackingEvent(fx.Context(), &CreateShipmentTrackingEventRequest{ Parent: parent, ShipmentTrackingEvent: msg, }) @@ -217,7 +249,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test } fd := container.ProtoReflect().Descriptor().Fields().ByName("region_code") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateShipmentTrackingEvent(fx.ctx, &CreateShipmentTrackingEventRequest{ + _, err := fx.Service().CreateShipmentTrackingEvent(fx.Context(), &CreateShipmentTrackingEventRequest{ Parent: parent, ShipmentTrackingEvent: msg, }) @@ -233,7 +265,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test } fd := container.ProtoReflect().Descriptor().Fields().ByName("reference_id") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateShipmentTrackingEvent(fx.ctx, &CreateShipmentTrackingEventRequest{ + _, err := fx.Service().CreateShipmentTrackingEvent(fx.Context(), &CreateShipmentTrackingEventRequest{ Parent: parent, ShipmentTrackingEvent: msg, }) @@ -248,7 +280,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.GetShipmentTrackingEvent(fx.ctx, &GetShipmentTrackingEventRequest{ + _, err := fx.Service().GetShipmentTrackingEvent(fx.Context(), &GetShipmentTrackingEventRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -257,7 +289,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test // Method should fail with InvalidArgument if the provided name is not valid. t.Run("invalid name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.GetShipmentTrackingEvent(fx.ctx, &GetShipmentTrackingEventRequest{ + _, err := fx.Service().GetShipmentTrackingEvent(fx.Context(), &GetShipmentTrackingEventRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -268,7 +300,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetShipmentTrackingEvent(fx.ctx, &GetShipmentTrackingEventRequest{ + msg, err := fx.Service().GetShipmentTrackingEvent(fx.Context(), &GetShipmentTrackingEventRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -280,7 +312,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetShipmentTrackingEvent(fx.ctx, &GetShipmentTrackingEventRequest{ + _, err := fx.Service().GetShipmentTrackingEvent(fx.Context(), &GetShipmentTrackingEventRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -289,7 +321,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test // Method should fail with InvalidArgument if the provided name only contains wildcards ('-') t.Run("only wildcards", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.GetShipmentTrackingEvent(fx.ctx, &GetShipmentTrackingEventRequest{ + _, err := fx.Service().GetShipmentTrackingEvent(fx.Context(), &GetShipmentTrackingEventRequest{ Name: "spaces/-/shipments/-/trackingEvents/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -302,7 +334,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListShipmentTrackingEvents(fx.ctx, &ListShipmentTrackingEventsRequest{ + _, err := fx.Service().ListShipmentTrackingEvents(fx.Context(), &ListShipmentTrackingEventsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -312,7 +344,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListShipmentTrackingEvents(fx.ctx, &ListShipmentTrackingEventsRequest{ + _, err := fx.Service().ListShipmentTrackingEvents(fx.Context(), &ListShipmentTrackingEventsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -323,7 +355,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListShipmentTrackingEvents(fx.ctx, &ListShipmentTrackingEventsRequest{ + _, err := fx.Service().ListShipmentTrackingEvents(fx.Context(), &ListShipmentTrackingEventsRequest{ Parent: parent, PageSize: -10, }) @@ -341,7 +373,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListShipmentTrackingEvents(fx.ctx, &ListShipmentTrackingEventsRequest{ + response, err := fx.Service().ListShipmentTrackingEvents(fx.Context(), &ListShipmentTrackingEventsRequest{ Parent: parent, PageSize: 999, }) @@ -360,7 +392,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test // If there are no more resources, next_page_token should not be set. t.Run("last page", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListShipmentTrackingEvents(fx.ctx, &ListShipmentTrackingEventsRequest{ + response, err := fx.Service().ListShipmentTrackingEvents(fx.Context(), &ListShipmentTrackingEventsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -371,7 +403,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test // If there are more resources, next_page_token should be set. t.Run("more pages", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListShipmentTrackingEvents(fx.ctx, &ListShipmentTrackingEventsRequest{ + response, err := fx.Service().ListShipmentTrackingEvents(fx.Context(), &ListShipmentTrackingEventsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -385,7 +417,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) test msgs := make([]*ShipmentTrackingEvent, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListShipmentTrackingEvents(fx.ctx, &ListShipmentTrackingEventsRequest{ + response, err := fx.Service().ListShipmentTrackingEvents(fx.Context(), &ListShipmentTrackingEventsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -439,7 +471,7 @@ func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) mayb func (fx *ShipmentTrackingEventServiceShipmentTrackingEventTestSuiteConfig) create(t *testing.T, parent string) *ShipmentTrackingEvent { t.Helper() - created, err := fx.service.CreateShipmentTrackingEvent(fx.ctx, &CreateShipmentTrackingEventRequest{ + created, err := fx.Service().CreateShipmentTrackingEvent(fx.Context(), &CreateShipmentTrackingEventRequest{ Parent: parent, ShipmentTrackingEvent: fx.Create(parent), })