From b984d6bbfbf6b5ba361a10588a2a795832fd686d Mon Sep 17 00:00:00 2001 From: Niclas Thall Date: Thu, 3 Oct 2024 14:09:12 +0200 Subject: [PATCH] feat: replace service field with a function This commit replaces the `service` field on the config struct, with a function for getting the service to be tested. This is a preparation for upcomming commit. --- internal/plugin/resource.go | 4 +- internal/plugin/service.go | 6 +- internal/util/method.go | 14 +- .../freight/v1/freight_service_aiptest.pb.go | 200 +++--- .../dataset_service_aiptest.pb.go | 228 +++---- ...oyment_resource_pool_service_aiptest.pb.go | 58 +- .../endpoint_service_aiptest.pb.go | 80 +-- ...e_online_store_admin_service_aiptest.pb.go | 174 +++--- .../feature_registry_service_aiptest.pb.go | 126 ++-- .../featurestore_service_aiptest.pb.go | 196 +++--- .../index_endpoint_service_aiptest.pb.go | 78 +-- .../aiplatformpb/index_service_aiptest.pb.go | 68 ++- .../aiplatformpb/job_service_aiptest.pb.go | 576 +++++++++--------- .../metadata_service_aiptest.pb.go | 332 +++++----- .../model_garden_service_aiptest.pb.go | 16 +- .../aiplatformpb/model_service_aiptest.pb.go | 140 +++-- .../pipeline_service_aiptest.pb.go | 172 +++--- .../schedule_service_aiptest.pb.go | 104 ++-- .../specialist_pool_service_aiptest.pb.go | 68 ++- .../tensorboard_service_aiptest.pb.go | 310 +++++----- .../aiplatformpb/vizier_service_aiptest.pb.go | 126 ++-- .../apiv1alpha1/tablespb/tables_aiptest.pb.go | 110 ++-- .../gsuiteaddonspb/gsuiteaddons_aiptest.pb.go | 102 ++-- .../apiv1/pubsubpb/pubsub_aiptest.pb.go | 60 +- .../apiv1/pubsubpb/schema_aiptest.pb.go | 60 +- .../schedulerpb/cloudscheduler_aiptest.pb.go | 72 +-- .../spanner_database_admin_aiptest.pb.go | 126 ++-- .../spanner_instance_admin_aiptest.pb.go | 226 +++---- .../apiv1/spannerpb/spanner_aiptest.pb.go | 30 +- 29 files changed, 1998 insertions(+), 1864 deletions(-) diff --git a/internal/plugin/resource.go b/internal/plugin/resource.go index 8b40288..1a9dacf 100644 --- a/internal/plugin/resource.go +++ b/internal/plugin/resource.go @@ -41,10 +41,12 @@ func (r *resourceGenerator) generateFixture(f *protogen.GeneratedFile) { }) f.P("type ", resourceTestSuiteConfigName(r.service.Desc, r.resource), " struct {") - f.P("service ", service) f.P("currParent int") f.P() + f.P("// Service should return the service that should be tested.") + f.P("// The service will be used for several tests.") + f.P("Service", " func() ", service) f.P("// Context should return a new context.") f.P("// The context will be used for several tests.") f.P("Context", " func() ", context) diff --git a/internal/plugin/service.go b/internal/plugin/service.go index fd9b207..707017e 100644 --- a/internal/plugin/service.go +++ b/internal/plugin/service.go @@ -60,13 +60,17 @@ func (s *serviceGenerator) generateTestMethods(f *protogen.GeneratedFile) { GoName: "T", GoImportPath: "testing", }) + service := f.QualifiedGoIdent(protogen.GoIdent{ + GoName: s.service.GoName + "Server", + GoImportPath: s.service.Methods[0].Input.GoIdent.GoImportPath, + }) serviceFx := serviceTestSuiteName(s.service.Desc) for _, resource := range s.resources { resourceFx := resourceTestSuiteConfigName(s.service.Desc, resource) f.P("func (fx ", serviceFx, ") Test", resourceType(resource), "(ctx ", context, ", options ", resourceFx, ") {") f.P("fx.T.Run(", strconv.Quote(resourceType(resource)), ", func(t *", testingT, ") {") f.P("options.Context = func() ", context, " { return ctx }") - f.P("options.service = fx.Server") + f.P("options.Service = func() ", service, " { return fx.Server", "}") f.P("options.test(t)") f.P("})") f.P("}") diff --git a/internal/util/method.go b/internal/util/method.go index 4b1d531..6362b04 100644 --- a/internal/util/method.go +++ b/internal/util/method.go @@ -25,7 +25,7 @@ func (m MethodCreate) Generate(f *protogen.GeneratedFile, response, err, assign f.P("}") } - f.P(response, ", ", err, " ", assign, " fx.service.", m.Method.GoName, "(fx.Context(), &", m.Method.Input.GoIdent, "{") + f.P(response, ", ", err, " ", assign, " fx.Service().", m.Method.GoName, "(fx.Context(), &", m.Method.Input.GoIdent, "{") //nolint:lll if HasParent(m.Resource) { f.P("Parent: ", m.Parent, ",") } @@ -59,7 +59,7 @@ type MethodGet struct { } func (m MethodGet) Generate(f *protogen.GeneratedFile, response, err, assign string) { - f.P(response, ", ", err, " ", assign, " fx.service.", m.Method.GoName, "(fx.Context(), &", m.Method.Input.GoIdent, "{") + f.P(response, ", ", err, " ", assign, " fx.Service().", m.Method.GoName, "(fx.Context(), &", m.Method.Input.GoIdent, "{") //nolint:lll f.P("Name: ", m.Name, ",") f.P("})") } @@ -73,7 +73,7 @@ type MethodBatchGet struct { } func (m MethodBatchGet) Generate(f *protogen.GeneratedFile, response, err, assign string) { - f.P(response, ", ", err, " ", assign, " fx.service.", m.Method.GoName, "(fx.Context(), &", m.Method.Input.GoIdent, "{") + f.P(response, ", ", err, " ", assign, " fx.Service().", m.Method.GoName, "(fx.Context(), &", m.Method.Input.GoIdent, "{") //nolint:lll if HasParent(m.Resource) { f.P("Parent: ", m.Parent, ",") } @@ -111,7 +111,7 @@ func (m MethodUpdate) Generate(f *protogen.GeneratedFile, response, err, assign } f.P("msg.Name = ", m.Name) } - f.P(response, ", ", err, " ", assign, " fx.service.", m.Method.GoName, "(fx.Context(), &", m.Method.Input.GoIdent, "{") + f.P(response, ", ", err, " ", assign, " fx.Service().", m.Method.GoName, "(fx.Context(), &", m.Method.Input.GoIdent, "{") //nolint:lll if m.Msg != "" { f.P(upper, ":", m.Msg, ",") } else { @@ -154,7 +154,7 @@ type MethodList struct { } func (m MethodList) Generate(f *protogen.GeneratedFile, response, err, assign string) { - f.P(response, ", ", err, " ", assign, " fx.service.", m.Method.GoName, "(fx.Context(), &", m.Method.Input.GoIdent, "{") + f.P(response, ", ", err, " ", assign, " fx.Service().", m.Method.GoName, "(fx.Context(), &", m.Method.Input.GoIdent, "{") //nolint:lll if HasParent(m.Resource) { f.P("Parent: ", m.Parent, ",") } @@ -177,7 +177,7 @@ type MethodSearch struct { } func (m MethodSearch) Generate(f *protogen.GeneratedFile, response, err, assign string) { - f.P(response, ", ", err, " ", assign, " fx.service.", m.Method.GoName, "(fx.Context(), &", m.Method.Input.GoIdent, "{") + f.P(response, ", ", err, " ", assign, " fx.Service().", m.Method.GoName, "(fx.Context(), &", m.Method.Input.GoIdent, "{") //nolint:lll if HasParent(m.Resource) { f.P("Parent: ", m.Parent, ",") } @@ -200,7 +200,7 @@ type MethodDelete struct { } func (m MethodDelete) Generate(f *protogen.GeneratedFile, response, err, assign string) { - f.P(response, ", ", err, " ", assign, " fx.service.", m.Method.GoName, "(fx.Context(), &", m.Method.Input.GoIdent, "{") + f.P(response, ", ", err, " ", assign, " fx.Service().", m.Method.GoName, "(fx.Context(), &", m.Method.Input.GoIdent, "{") //nolint:lll if m.Name != "" { f.P("Name: ", m.Name, ",") } else { diff --git a/proto/gen/einride/example/freight/v1/freight_service_aiptest.pb.go b/proto/gen/einride/example/freight/v1/freight_service_aiptest.pb.go index 6b938ef..c8d317e 100644 --- a/proto/gen/einride/example/freight/v1/freight_service_aiptest.pb.go +++ b/proto/gen/einride/example/freight/v1/freight_service_aiptest.pb.go @@ -25,7 +25,7 @@ type FreightServiceTestSuite struct { func (fx FreightServiceTestSuite) TestShipper(ctx context.Context, options FreightServiceShipperTestSuiteConfig) { fx.T.Run("Shipper", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() FreightServiceServer { return fx.Server } options.test(t) }) } @@ -33,15 +33,17 @@ func (fx FreightServiceTestSuite) TestShipper(ctx context.Context, options Freig func (fx FreightServiceTestSuite) TestSite(ctx context.Context, options FreightServiceSiteTestSuiteConfig) { fx.T.Run("Site", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() FreightServiceServer { return fx.Server } options.test(t) }) } type FreightServiceShipperTestSuiteConfig struct { - service FreightServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() FreightServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -80,7 +82,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testCreate(t *testing.T) { if fx.IDGenerator != nil { userSetID = fx.IDGenerator() } - msg, err := fx.service.CreateShipper(fx.Context(), &CreateShipperRequest{ + msg, err := fx.Service().CreateShipper(fx.Context(), &CreateShipperRequest{ Shipper: fx.Create(), ShipperId: userSetID, }) @@ -97,12 +99,12 @@ func (fx *FreightServiceShipperTestSuiteConfig) testCreate(t *testing.T) { if fx.IDGenerator != nil { userSetID = fx.IDGenerator() } - msg, err := fx.service.CreateShipper(fx.Context(), &CreateShipperRequest{ + msg, err := fx.Service().CreateShipper(fx.Context(), &CreateShipperRequest{ Shipper: fx.Create(), ShipperId: userSetID, }) assert.NilError(t, err) - persisted, err := fx.service.GetShipper(fx.Context(), &GetShipperRequest{ + persisted, err := fx.Service().GetShipper(fx.Context(), &GetShipperRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -113,7 +115,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testCreate(t *testing.T) { // be returned with the provided ID. t.Run("user settable id", func(t *testing.T) { fx.maybeSkip(t) - msg, err := fx.service.CreateShipper(fx.Context(), &CreateShipperRequest{ + msg, err := fx.Service().CreateShipper(fx.Context(), &CreateShipperRequest{ Shipper: fx.Create(), ShipperId: "usersetid", }) @@ -125,12 +127,12 @@ func (fx *FreightServiceShipperTestSuiteConfig) testCreate(t *testing.T) { // the method should return AlreadyExists. t.Run("already exists", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateShipper(fx.Context(), &CreateShipperRequest{ + _, err := fx.Service().CreateShipper(fx.Context(), &CreateShipperRequest{ Shipper: fx.Create(), ShipperId: "alreadyexists", }) assert.NilError(t, err) - _, err = fx.service.CreateShipper(fx.Context(), &CreateShipperRequest{ + _, err = fx.Service().CreateShipper(fx.Context(), &CreateShipperRequest{ Shipper: fx.Create(), ShipperId: "alreadyexists", }) @@ -154,7 +156,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testCreate(t *testing.T) { if fx.IDGenerator != nil { userSetID = fx.IDGenerator() } - _, err := fx.service.CreateShipper(fx.Context(), &CreateShipperRequest{ + _, err := fx.Service().CreateShipper(fx.Context(), &CreateShipperRequest{ Shipper: msg, ShipperId: userSetID, }) @@ -173,7 +175,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testCreate(t *testing.T) { if fx.IDGenerator != nil { userSetID = fx.IDGenerator() } - _, err := fx.service.CreateShipper(fx.Context(), &CreateShipperRequest{ + _, err := fx.Service().CreateShipper(fx.Context(), &CreateShipperRequest{ Shipper: msg, ShipperId: userSetID, }) @@ -197,7 +199,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testCreate(t *testing.T) { if fx.IDGenerator != nil { userSetID = fx.IDGenerator() } - _, err := fx.service.CreateShipper(fx.Context(), &CreateShipperRequest{ + _, err := fx.Service().CreateShipper(fx.Context(), &CreateShipperRequest{ Shipper: msg, ShipperId: userSetID, }) @@ -212,7 +214,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testCreate(t *testing.T) { if fx.IDGenerator != nil { userSetID = fx.IDGenerator() } - created, _ := fx.service.CreateShipper(fx.Context(), &CreateShipperRequest{ + created, _ := fx.Service().CreateShipper(fx.Context(), &CreateShipperRequest{ Shipper: fx.Create(), ShipperId: userSetID, }) @@ -226,7 +228,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) 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.GetShipper(fx.Context(), &GetShipperRequest{ + _, err := fx.Service().GetShipper(fx.Context(), &GetShipperRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -235,7 +237,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) 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.GetShipper(fx.Context(), &GetShipperRequest{ + _, err := fx.Service().GetShipper(fx.Context(), &GetShipperRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -245,7 +247,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testGet(t *testing.T) { t.Run("exists", func(t *testing.T) { fx.maybeSkip(t) created := fx.create(t) - msg, err := fx.service.GetShipper(fx.Context(), &GetShipperRequest{ + msg, err := fx.Service().GetShipper(fx.Context(), &GetShipperRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -256,7 +258,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testGet(t *testing.T) { t.Run("not found", func(t *testing.T) { fx.maybeSkip(t) created := fx.create(t) - _, err := fx.service.GetShipper(fx.Context(), &GetShipperRequest{ + _, err := fx.Service().GetShipper(fx.Context(), &GetShipperRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -265,7 +267,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) 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.GetShipper(fx.Context(), &GetShipperRequest{ + _, err := fx.Service().GetShipper(fx.Context(), &GetShipperRequest{ Name: "shippers/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -275,11 +277,11 @@ func (fx *FreightServiceShipperTestSuiteConfig) testGet(t *testing.T) { t.Run("soft-deleted", func(t *testing.T) { fx.maybeSkip(t) created := fx.create(t) - deleted, err := fx.service.DeleteShipper(fx.Context(), &DeleteShipperRequest{ + deleted, err := fx.Service().DeleteShipper(fx.Context(), &DeleteShipperRequest{ Name: created.Name, }) assert.NilError(t, err) - msg, err := fx.service.GetShipper(fx.Context(), &GetShipperRequest{ + msg, err := fx.Service().GetShipper(fx.Context(), &GetShipperRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -295,7 +297,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update() msg.Name = "" - _, err := fx.service.UpdateShipper(fx.Context(), &UpdateShipperRequest{ + _, err := fx.Service().UpdateShipper(fx.Context(), &UpdateShipperRequest{ Shipper: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -306,7 +308,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update() msg.Name = "invalid resource name" - _, err := fx.service.UpdateShipper(fx.Context(), &UpdateShipperRequest{ + _, err := fx.Service().UpdateShipper(fx.Context(), &UpdateShipperRequest{ Shipper: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -316,7 +318,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testUpdate(t *testing.T) { t.Run("update time", func(t *testing.T) { fx.maybeSkip(t) created := fx.create(t) - updated, err := fx.service.UpdateShipper(fx.Context(), &UpdateShipperRequest{ + updated, err := fx.Service().UpdateShipper(fx.Context(), &UpdateShipperRequest{ Shipper: created, }) assert.NilError(t, err) @@ -327,11 +329,11 @@ func (fx *FreightServiceShipperTestSuiteConfig) testUpdate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) created := fx.create(t) - updated, err := fx.service.UpdateShipper(fx.Context(), &UpdateShipperRequest{ + updated, err := fx.Service().UpdateShipper(fx.Context(), &UpdateShipperRequest{ Shipper: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetShipper(fx.Context(), &GetShipperRequest{ + persisted, err := fx.Service().GetShipper(fx.Context(), &GetShipperRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -343,7 +345,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) created := fx.create(t) originalCreateTime := created.CreateTime - updated, err := fx.service.UpdateShipper(fx.Context(), &UpdateShipperRequest{ + updated, err := fx.Service().UpdateShipper(fx.Context(), &UpdateShipperRequest{ Shipper: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -359,7 +361,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testUpdate(t *testing.T) { t.Run("etag mismatch", func(t *testing.T) { fx.maybeSkip(t) created := fx.create(t) - _, err := fx.service.UpdateShipper(fx.Context(), &UpdateShipperRequest{ + _, err := fx.Service().UpdateShipper(fx.Context(), &UpdateShipperRequest{ Shipper: created, Etag: `"99999"`, }) @@ -372,7 +374,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testUpdate(t *testing.T) { created := fx.create(t) msg := fx.Update() msg.Name = created.Name - updated, err := fx.service.UpdateShipper(fx.Context(), &UpdateShipperRequest{ + updated, err := fx.Service().UpdateShipper(fx.Context(), &UpdateShipperRequest{ Shipper: msg, Etag: created.Etag, }) @@ -386,7 +388,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update() msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateShipper(fx.Context(), &UpdateShipperRequest{ + _, err := fx.Service().UpdateShipper(fx.Context(), &UpdateShipperRequest{ Shipper: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -395,7 +397,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) 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.UpdateShipper(fx.Context(), &UpdateShipperRequest{ + _, err := fx.Service().UpdateShipper(fx.Context(), &UpdateShipperRequest{ Shipper: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -419,7 +421,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateShipper(fx.Context(), &UpdateShipperRequest{ + _, err := fx.Service().UpdateShipper(fx.Context(), &UpdateShipperRequest{ Shipper: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -438,7 +440,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("billing_account") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateShipper(fx.Context(), &UpdateShipperRequest{ + _, err := fx.Service().UpdateShipper(fx.Context(), &UpdateShipperRequest{ Shipper: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -457,7 +459,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testList(t *testing.T) { // Method should fail with InvalidArgument is provided page token is not valid. t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListShippers(fx.Context(), &ListShippersRequest{ + _, err := fx.Service().ListShippers(fx.Context(), &ListShippersRequest{ PageToken: "invalid page token", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -466,7 +468,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testList(t *testing.T) { // Method should fail with InvalidArgument is provided page size is negative. t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListShippers(fx.Context(), &ListShippersRequest{ + _, err := fx.Service().ListShippers(fx.Context(), &ListShippersRequest{ PageSize: -10, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -479,7 +481,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testDelete(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.DeleteShipper(fx.Context(), &DeleteShipperRequest{ + _, err := fx.Service().DeleteShipper(fx.Context(), &DeleteShipperRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -488,7 +490,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testDelete(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.DeleteShipper(fx.Context(), &DeleteShipperRequest{ + _, err := fx.Service().DeleteShipper(fx.Context(), &DeleteShipperRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -498,7 +500,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testDelete(t *testing.T) { t.Run("exists", func(t *testing.T) { fx.maybeSkip(t) created := fx.create(t) - _, err := fx.service.DeleteShipper(fx.Context(), &DeleteShipperRequest{ + _, err := fx.Service().DeleteShipper(fx.Context(), &DeleteShipperRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -508,7 +510,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testDelete(t *testing.T) { t.Run("not found", func(t *testing.T) { fx.maybeSkip(t) created := fx.create(t) - _, err := fx.service.DeleteShipper(fx.Context(), &DeleteShipperRequest{ + _, err := fx.Service().DeleteShipper(fx.Context(), &DeleteShipperRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -518,12 +520,12 @@ func (fx *FreightServiceShipperTestSuiteConfig) testDelete(t *testing.T) { t.Run("already deleted", func(t *testing.T) { fx.maybeSkip(t) created := fx.create(t) - deleted, err := fx.service.DeleteShipper(fx.Context(), &DeleteShipperRequest{ + deleted, err := fx.Service().DeleteShipper(fx.Context(), &DeleteShipperRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteShipper(fx.Context(), &DeleteShipperRequest{ + _, err = fx.Service().DeleteShipper(fx.Context(), &DeleteShipperRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -532,7 +534,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testDelete(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.DeleteShipper(fx.Context(), &DeleteShipperRequest{ + _, err := fx.Service().DeleteShipper(fx.Context(), &DeleteShipperRequest{ Name: "shippers/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -542,7 +544,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) testDelete(t *testing.T) { t.Run("etag mismatch", func(t *testing.T) { fx.maybeSkip(t) created := fx.create(t) - _, err := fx.service.DeleteShipper(fx.Context(), &DeleteShipperRequest{ + _, err := fx.Service().DeleteShipper(fx.Context(), &DeleteShipperRequest{ Name: created.Name, Etag: `"99999"`, }) @@ -565,7 +567,7 @@ func (fx *FreightServiceShipperTestSuiteConfig) create(t *testing.T) *Shipper { if fx.IDGenerator != nil { userSetID = fx.IDGenerator() } - created, err := fx.service.CreateShipper(fx.Context(), &CreateShipperRequest{ + created, err := fx.Service().CreateShipper(fx.Context(), &CreateShipperRequest{ Shipper: fx.Create(), ShipperId: userSetID, }) @@ -574,9 +576,11 @@ func (fx *FreightServiceShipperTestSuiteConfig) create(t *testing.T) *Shipper { } type FreightServiceSiteTestSuiteConfig struct { - service FreightServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() FreightServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -612,7 +616,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) 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.CreateSite(fx.Context(), &CreateSiteRequest{ + _, err := fx.Service().CreateSite(fx.Context(), &CreateSiteRequest{ Parent: "", Site: fx.Create(fx.nextParent(t, false)), }) @@ -622,7 +626,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) 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.CreateSite(fx.Context(), &CreateSiteRequest{ + _, err := fx.Service().CreateSite(fx.Context(), &CreateSiteRequest{ Parent: "invalid resource name", Site: fx.Create(fx.nextParent(t, false)), }) @@ -634,7 +638,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testCreate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateSite(fx.Context(), &CreateSiteRequest{ + msg, err := fx.Service().CreateSite(fx.Context(), &CreateSiteRequest{ Parent: parent, Site: fx.Create(parent), }) @@ -648,12 +652,12 @@ func (fx *FreightServiceSiteTestSuiteConfig) testCreate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateSite(fx.Context(), &CreateSiteRequest{ + msg, err := fx.Service().CreateSite(fx.Context(), &CreateSiteRequest{ Parent: parent, Site: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetSite(fx.Context(), &GetSiteRequest{ + persisted, err := fx.Service().GetSite(fx.Context(), &GetSiteRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -674,7 +678,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateSite(fx.Context(), &CreateSiteRequest{ + _, err := fx.Service().CreateSite(fx.Context(), &CreateSiteRequest{ Parent: parent, Site: msg, }) @@ -690,7 +694,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("region") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateSite(fx.Context(), &CreateSiteRequest{ + _, err := fx.Service().CreateSite(fx.Context(), &CreateSiteRequest{ Parent: parent, Site: msg, }) @@ -711,7 +715,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.BillingAccount = "invalid resource name" - _, err := fx.service.CreateSite(fx.Context(), &CreateSiteRequest{ + _, err := fx.Service().CreateSite(fx.Context(), &CreateSiteRequest{ Parent: parent, Site: msg, }) @@ -723,7 +727,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testCreate(t *testing.T) { t.Run("etag populated", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - created, _ := fx.service.CreateSite(fx.Context(), &CreateSiteRequest{ + created, _ := fx.Service().CreateSite(fx.Context(), &CreateSiteRequest{ Parent: parent, Site: fx.Create(parent), }) @@ -737,7 +741,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) 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.GetSite(fx.Context(), &GetSiteRequest{ + _, err := fx.Service().GetSite(fx.Context(), &GetSiteRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -746,7 +750,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) 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.GetSite(fx.Context(), &GetSiteRequest{ + _, err := fx.Service().GetSite(fx.Context(), &GetSiteRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -757,7 +761,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetSite(fx.Context(), &GetSiteRequest{ + msg, err := fx.Service().GetSite(fx.Context(), &GetSiteRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -769,7 +773,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetSite(fx.Context(), &GetSiteRequest{ + _, err := fx.Service().GetSite(fx.Context(), &GetSiteRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -778,7 +782,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) 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.GetSite(fx.Context(), &GetSiteRequest{ + _, err := fx.Service().GetSite(fx.Context(), &GetSiteRequest{ Name: "shippers/-/sites/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -789,12 +793,12 @@ func (fx *FreightServiceSiteTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteSite(fx.Context(), &DeleteSiteRequest{ + deleted, err := fx.Service().DeleteSite(fx.Context(), &DeleteSiteRequest{ Name: created.Name, Etag: created.Etag, }) assert.NilError(t, err) - msg, err := fx.service.GetSite(fx.Context(), &GetSiteRequest{ + msg, err := fx.Service().GetSite(fx.Context(), &GetSiteRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -808,7 +812,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testBatchGet(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.BatchGetSites(fx.Context(), &BatchGetSitesRequest{ + _, err := fx.Service().BatchGetSites(fx.Context(), &BatchGetSitesRequest{ Parent: "invalid resource name", Names: []string{}, }) @@ -819,7 +823,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testBatchGet(t *testing.T) { t.Run("names missing", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.BatchGetSites(fx.Context(), &BatchGetSitesRequest{ + _, err := fx.Service().BatchGetSites(fx.Context(), &BatchGetSitesRequest{ Parent: parent, Names: []string{}, }) @@ -830,7 +834,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testBatchGet(t *testing.T) { t.Run("invalid names", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.BatchGetSites(fx.Context(), &BatchGetSitesRequest{ + _, err := fx.Service().BatchGetSites(fx.Context(), &BatchGetSitesRequest{ Parent: parent, Names: []string{ "invalid resource name", @@ -843,7 +847,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testBatchGet(t *testing.T) { t.Run("wildcard name", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.BatchGetSites(fx.Context(), &BatchGetSitesRequest{ + _, err := fx.Service().BatchGetSites(fx.Context(), &BatchGetSitesRequest{ Parent: parent, Names: []string{ "shippers/-/sites/-", @@ -859,7 +863,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testBatchGet(t *testing.T) { // Resources should be returned without errors if they exist. t.Run("all exists", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.BatchGetSites(fx.Context(), &BatchGetSitesRequest{ + response, err := fx.Service().BatchGetSites(fx.Context(), &BatchGetSitesRequest{ Parent: parent, Names: []string{ created00.Name, @@ -884,7 +888,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testBatchGet(t *testing.T) { // or succeed for all resources (no partial success). t.Run("atomic", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.BatchGetSites(fx.Context(), &BatchGetSitesRequest{ + _, err := fx.Service().BatchGetSites(fx.Context(), &BatchGetSitesRequest{ Parent: parent, Names: []string{ created00.Name, @@ -899,7 +903,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testBatchGet(t *testing.T) { // being retrieved does not match, the request must fail. t.Run("parent mismatch", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.BatchGetSites(fx.Context(), &BatchGetSitesRequest{ + _, err := fx.Service().BatchGetSites(fx.Context(), &BatchGetSitesRequest{ Parent: fx.peekNextParent(t), Names: []string{ created00.Name, @@ -916,7 +920,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testBatchGet(t *testing.T) { {created01, created00, created02}, {created02, created01, created00}, } { - response, err := fx.service.BatchGetSites(fx.Context(), &BatchGetSitesRequest{ + response, err := fx.Service().BatchGetSites(fx.Context(), &BatchGetSitesRequest{ Parent: parent, Names: []string{ order[0].GetName(), @@ -933,7 +937,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testBatchGet(t *testing.T) { // duplicate resources. t.Run("duplicate names", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.BatchGetSites(fx.Context(), &BatchGetSitesRequest{ + response, err := fx.Service().BatchGetSites(fx.Context(), &BatchGetSitesRequest{ Parent: parent, Names: []string{ created00.Name, @@ -962,7 +966,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateSite(fx.Context(), &UpdateSiteRequest{ + _, err := fx.Service().UpdateSite(fx.Context(), &UpdateSiteRequest{ Site: msg, Etag: msg.Etag, }) @@ -975,7 +979,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateSite(fx.Context(), &UpdateSiteRequest{ + _, err := fx.Service().UpdateSite(fx.Context(), &UpdateSiteRequest{ Site: msg, Etag: msg.Etag, }) @@ -987,7 +991,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateSite(fx.Context(), &UpdateSiteRequest{ + updated, err := fx.Service().UpdateSite(fx.Context(), &UpdateSiteRequest{ Site: created, Etag: created.Etag, }) @@ -1000,12 +1004,12 @@ func (fx *FreightServiceSiteTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateSite(fx.Context(), &UpdateSiteRequest{ + updated, err := fx.Service().UpdateSite(fx.Context(), &UpdateSiteRequest{ Site: created, Etag: created.Etag, }) assert.NilError(t, err) - persisted, err := fx.service.GetSite(fx.Context(), &GetSiteRequest{ + persisted, err := fx.Service().GetSite(fx.Context(), &GetSiteRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -1018,7 +1022,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) created := fx.create(t, parent) originalCreateTime := created.CreateTime - updated, err := fx.service.UpdateSite(fx.Context(), &UpdateSiteRequest{ + updated, err := fx.Service().UpdateSite(fx.Context(), &UpdateSiteRequest{ Site: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -1036,7 +1040,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.UpdateSite(fx.Context(), &UpdateSiteRequest{ + _, err := fx.Service().UpdateSite(fx.Context(), &UpdateSiteRequest{ Site: created, Etag: `"99999"`, }) @@ -1050,7 +1054,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testUpdate(t *testing.T) { created := fx.create(t, parent) msg := fx.Update(parent) msg.Name = created.Name - updated, err := fx.service.UpdateSite(fx.Context(), &UpdateSiteRequest{ + updated, err := fx.Service().UpdateSite(fx.Context(), &UpdateSiteRequest{ Site: msg, Etag: created.Etag, }) @@ -1065,7 +1069,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateSite(fx.Context(), &UpdateSiteRequest{ + _, err := fx.Service().UpdateSite(fx.Context(), &UpdateSiteRequest{ Site: msg, Etag: msg.Etag, }) @@ -1075,7 +1079,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) 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.UpdateSite(fx.Context(), &UpdateSiteRequest{ + _, err := fx.Service().UpdateSite(fx.Context(), &UpdateSiteRequest{ Site: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -1100,7 +1104,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateSite(fx.Context(), &UpdateSiteRequest{ + _, err := fx.Service().UpdateSite(fx.Context(), &UpdateSiteRequest{ Site: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -1120,7 +1124,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) 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.ListSites(fx.Context(), &ListSitesRequest{ + _, err := fx.Service().ListSites(fx.Context(), &ListSitesRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1130,7 +1134,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListSites(fx.Context(), &ListSitesRequest{ + _, err := fx.Service().ListSites(fx.Context(), &ListSitesRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -1141,7 +1145,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListSites(fx.Context(), &ListSitesRequest{ + _, err := fx.Service().ListSites(fx.Context(), &ListSitesRequest{ Parent: parent, PageSize: -10, }) @@ -1159,7 +1163,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListSites(fx.Context(), &ListSitesRequest{ + response, err := fx.Service().ListSites(fx.Context(), &ListSitesRequest{ Parent: parent, PageSize: 999, }) @@ -1178,7 +1182,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) 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.ListSites(fx.Context(), &ListSitesRequest{ + response, err := fx.Service().ListSites(fx.Context(), &ListSitesRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -1189,7 +1193,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) 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.ListSites(fx.Context(), &ListSitesRequest{ + response, err := fx.Service().ListSites(fx.Context(), &ListSitesRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -1203,7 +1207,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Site, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListSites(fx.Context(), &ListSitesRequest{ + response, err := fx.Service().ListSites(fx.Context(), &ListSitesRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -1232,13 +1236,13 @@ func (fx *FreightServiceSiteTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteSite(fx.Context(), &DeleteSiteRequest{ + _, err := fx.Service().DeleteSite(fx.Context(), &DeleteSiteRequest{ Name: parentMsgs[i].Name, Etag: parentMsgs[i].Etag, }) assert.NilError(t, err) } - response, err := fx.service.ListSites(fx.Context(), &ListSitesRequest{ + response, err := fx.Service().ListSites(fx.Context(), &ListSitesRequest{ Parent: parent, PageSize: 9999, }) @@ -1261,7 +1265,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testDelete(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.DeleteSite(fx.Context(), &DeleteSiteRequest{ + _, err := fx.Service().DeleteSite(fx.Context(), &DeleteSiteRequest{ Name: "", Etag: "", }) @@ -1271,7 +1275,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testDelete(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.DeleteSite(fx.Context(), &DeleteSiteRequest{ + _, err := fx.Service().DeleteSite(fx.Context(), &DeleteSiteRequest{ Name: "invalid resource name", Etag: "", }) @@ -1283,7 +1287,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteSite(fx.Context(), &DeleteSiteRequest{ + _, err := fx.Service().DeleteSite(fx.Context(), &DeleteSiteRequest{ Name: created.Name, Etag: created.Etag, }) @@ -1295,7 +1299,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteSite(fx.Context(), &DeleteSiteRequest{ + _, err := fx.Service().DeleteSite(fx.Context(), &DeleteSiteRequest{ Name: created.Name + "notfound", Etag: created.Etag, }) @@ -1307,13 +1311,13 @@ func (fx *FreightServiceSiteTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteSite(fx.Context(), &DeleteSiteRequest{ + deleted, err := fx.Service().DeleteSite(fx.Context(), &DeleteSiteRequest{ Name: created.Name, Etag: created.Etag, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteSite(fx.Context(), &DeleteSiteRequest{ + _, err = fx.Service().DeleteSite(fx.Context(), &DeleteSiteRequest{ Name: created.Name, Etag: deleted.Etag, }) @@ -1323,7 +1327,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testDelete(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.DeleteSite(fx.Context(), &DeleteSiteRequest{ + _, err := fx.Service().DeleteSite(fx.Context(), &DeleteSiteRequest{ Name: "shippers/-/sites/-", Etag: "", }) @@ -1335,7 +1339,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteSite(fx.Context(), &DeleteSiteRequest{ + _, err := fx.Service().DeleteSite(fx.Context(), &DeleteSiteRequest{ Name: created.Name, Etag: `"99999"`, }) @@ -1372,7 +1376,7 @@ func (fx *FreightServiceSiteTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *FreightServiceSiteTestSuiteConfig) create(t *testing.T, parent string) *Site { t.Helper() - created, err := fx.service.CreateSite(fx.Context(), &CreateSiteRequest{ + created, err := fx.Service().CreateSite(fx.Context(), &CreateSiteRequest{ Parent: parent, Site: fx.Create(parent), }) diff --git a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/dataset_service_aiptest.pb.go b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/dataset_service_aiptest.pb.go index a1fe125..871949e 100644 --- a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/dataset_service_aiptest.pb.go +++ b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/dataset_service_aiptest.pb.go @@ -24,7 +24,7 @@ type DatasetServiceTestSuite struct { func (fx DatasetServiceTestSuite) TestAnnotation(ctx context.Context, options DatasetServiceAnnotationTestSuiteConfig) { fx.T.Run("Annotation", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() DatasetServiceServer { return fx.Server } options.test(t) }) } @@ -32,7 +32,7 @@ func (fx DatasetServiceTestSuite) TestAnnotation(ctx context.Context, options Da func (fx DatasetServiceTestSuite) TestAnnotationSpec(ctx context.Context, options DatasetServiceAnnotationSpecTestSuiteConfig) { fx.T.Run("AnnotationSpec", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() DatasetServiceServer { return fx.Server } options.test(t) }) } @@ -40,7 +40,7 @@ func (fx DatasetServiceTestSuite) TestAnnotationSpec(ctx context.Context, option func (fx DatasetServiceTestSuite) TestDataItem(ctx context.Context, options DatasetServiceDataItemTestSuiteConfig) { fx.T.Run("DataItem", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() DatasetServiceServer { return fx.Server } options.test(t) }) } @@ -48,7 +48,7 @@ func (fx DatasetServiceTestSuite) TestDataItem(ctx context.Context, options Data func (fx DatasetServiceTestSuite) TestDataset(ctx context.Context, options DatasetServiceDatasetTestSuiteConfig) { fx.T.Run("Dataset", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() DatasetServiceServer { return fx.Server } options.test(t) }) } @@ -56,7 +56,7 @@ func (fx DatasetServiceTestSuite) TestDataset(ctx context.Context, options Datas func (fx DatasetServiceTestSuite) TestDatasetVersion(ctx context.Context, options DatasetServiceDatasetVersionTestSuiteConfig) { fx.T.Run("DatasetVersion", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() DatasetServiceServer { return fx.Server } options.test(t) }) } @@ -64,15 +64,17 @@ func (fx DatasetServiceTestSuite) TestDatasetVersion(ctx context.Context, option func (fx DatasetServiceTestSuite) TestSavedQuery(ctx context.Context, options DatasetServiceSavedQueryTestSuiteConfig) { fx.T.Run("SavedQuery", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() DatasetServiceServer { return fx.Server } options.test(t) }) } type DatasetServiceAnnotationTestSuiteConfig struct { - service DatasetServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() DatasetServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -103,7 +105,7 @@ func (fx *DatasetServiceAnnotationTestSuiteConfig) 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.ListAnnotations(fx.Context(), &ListAnnotationsRequest{ + _, err := fx.Service().ListAnnotations(fx.Context(), &ListAnnotationsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -113,7 +115,7 @@ func (fx *DatasetServiceAnnotationTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListAnnotations(fx.Context(), &ListAnnotationsRequest{ + _, err := fx.Service().ListAnnotations(fx.Context(), &ListAnnotationsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -124,7 +126,7 @@ func (fx *DatasetServiceAnnotationTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListAnnotations(fx.Context(), &ListAnnotationsRequest{ + _, err := fx.Service().ListAnnotations(fx.Context(), &ListAnnotationsRequest{ Parent: parent, PageSize: -10, }) @@ -142,7 +144,7 @@ func (fx *DatasetServiceAnnotationTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListAnnotations(fx.Context(), &ListAnnotationsRequest{ + response, err := fx.Service().ListAnnotations(fx.Context(), &ListAnnotationsRequest{ Parent: parent, PageSize: 999, }) @@ -161,7 +163,7 @@ func (fx *DatasetServiceAnnotationTestSuiteConfig) 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.ListAnnotations(fx.Context(), &ListAnnotationsRequest{ + response, err := fx.Service().ListAnnotations(fx.Context(), &ListAnnotationsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -172,7 +174,7 @@ func (fx *DatasetServiceAnnotationTestSuiteConfig) 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.ListAnnotations(fx.Context(), &ListAnnotationsRequest{ + response, err := fx.Service().ListAnnotations(fx.Context(), &ListAnnotationsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -186,7 +188,7 @@ func (fx *DatasetServiceAnnotationTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Annotation, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListAnnotations(fx.Context(), &ListAnnotationsRequest{ + response, err := fx.Service().ListAnnotations(fx.Context(), &ListAnnotationsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -249,9 +251,11 @@ func (fx *DatasetServiceAnnotationTestSuiteConfig) create(t *testing.T, parent s } type DatasetServiceAnnotationSpecTestSuiteConfig struct { - service DatasetServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() DatasetServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -282,7 +286,7 @@ func (fx *DatasetServiceAnnotationSpecTestSuiteConfig) 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.GetAnnotationSpec(fx.Context(), &GetAnnotationSpecRequest{ + _, err := fx.Service().GetAnnotationSpec(fx.Context(), &GetAnnotationSpecRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -291,7 +295,7 @@ func (fx *DatasetServiceAnnotationSpecTestSuiteConfig) 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.GetAnnotationSpec(fx.Context(), &GetAnnotationSpecRequest{ + _, err := fx.Service().GetAnnotationSpec(fx.Context(), &GetAnnotationSpecRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -302,7 +306,7 @@ func (fx *DatasetServiceAnnotationSpecTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetAnnotationSpec(fx.Context(), &GetAnnotationSpecRequest{ + msg, err := fx.Service().GetAnnotationSpec(fx.Context(), &GetAnnotationSpecRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -314,7 +318,7 @@ func (fx *DatasetServiceAnnotationSpecTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetAnnotationSpec(fx.Context(), &GetAnnotationSpecRequest{ + _, err := fx.Service().GetAnnotationSpec(fx.Context(), &GetAnnotationSpecRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -323,7 +327,7 @@ func (fx *DatasetServiceAnnotationSpecTestSuiteConfig) 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.GetAnnotationSpec(fx.Context(), &GetAnnotationSpecRequest{ + _, err := fx.Service().GetAnnotationSpec(fx.Context(), &GetAnnotationSpecRequest{ Name: "projects/-/locations/-/datasets/-/annotationSpecs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -368,9 +372,11 @@ func (fx *DatasetServiceAnnotationSpecTestSuiteConfig) create(t *testing.T, pare } type DatasetServiceDataItemTestSuiteConfig struct { - service DatasetServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() DatasetServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -401,7 +407,7 @@ func (fx *DatasetServiceDataItemTestSuiteConfig) 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.ListDataItems(fx.Context(), &ListDataItemsRequest{ + _, err := fx.Service().ListDataItems(fx.Context(), &ListDataItemsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -411,7 +417,7 @@ func (fx *DatasetServiceDataItemTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListDataItems(fx.Context(), &ListDataItemsRequest{ + _, err := fx.Service().ListDataItems(fx.Context(), &ListDataItemsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -422,7 +428,7 @@ func (fx *DatasetServiceDataItemTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListDataItems(fx.Context(), &ListDataItemsRequest{ + _, err := fx.Service().ListDataItems(fx.Context(), &ListDataItemsRequest{ Parent: parent, PageSize: -10, }) @@ -440,7 +446,7 @@ func (fx *DatasetServiceDataItemTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListDataItems(fx.Context(), &ListDataItemsRequest{ + response, err := fx.Service().ListDataItems(fx.Context(), &ListDataItemsRequest{ Parent: parent, PageSize: 999, }) @@ -459,7 +465,7 @@ func (fx *DatasetServiceDataItemTestSuiteConfig) 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.ListDataItems(fx.Context(), &ListDataItemsRequest{ + response, err := fx.Service().ListDataItems(fx.Context(), &ListDataItemsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -470,7 +476,7 @@ func (fx *DatasetServiceDataItemTestSuiteConfig) 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.ListDataItems(fx.Context(), &ListDataItemsRequest{ + response, err := fx.Service().ListDataItems(fx.Context(), &ListDataItemsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -484,7 +490,7 @@ func (fx *DatasetServiceDataItemTestSuiteConfig) testList(t *testing.T) { msgs := make([]*DataItem, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListDataItems(fx.Context(), &ListDataItemsRequest{ + response, err := fx.Service().ListDataItems(fx.Context(), &ListDataItemsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -547,9 +553,11 @@ func (fx *DatasetServiceDataItemTestSuiteConfig) create(t *testing.T, parent str } type DatasetServiceDatasetTestSuiteConfig struct { - service DatasetServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() DatasetServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -584,7 +592,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) 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.CreateDataset(fx.Context(), &CreateDatasetRequest{ + _, err := fx.Service().CreateDataset(fx.Context(), &CreateDatasetRequest{ Parent: "", Dataset: fx.Create(fx.nextParent(t, false)), }) @@ -594,7 +602,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) 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.CreateDataset(fx.Context(), &CreateDatasetRequest{ + _, err := fx.Service().CreateDataset(fx.Context(), &CreateDatasetRequest{ Parent: "invalid resource name", Dataset: fx.Create(fx.nextParent(t, false)), }) @@ -615,7 +623,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDataset(fx.Context(), &CreateDatasetRequest{ + _, err := fx.Service().CreateDataset(fx.Context(), &CreateDatasetRequest{ Parent: parent, Dataset: msg, }) @@ -631,7 +639,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("metadata_schema_uri") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDataset(fx.Context(), &CreateDatasetRequest{ + _, err := fx.Service().CreateDataset(fx.Context(), &CreateDatasetRequest{ Parent: parent, Dataset: msg, }) @@ -647,7 +655,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("metadata") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDataset(fx.Context(), &CreateDatasetRequest{ + _, err := fx.Service().CreateDataset(fx.Context(), &CreateDatasetRequest{ Parent: parent, Dataset: msg, }) @@ -663,7 +671,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDataset(fx.Context(), &CreateDatasetRequest{ + _, err := fx.Service().CreateDataset(fx.Context(), &CreateDatasetRequest{ Parent: parent, Dataset: msg, }) @@ -678,7 +686,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) 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.GetDataset(fx.Context(), &GetDatasetRequest{ + _, err := fx.Service().GetDataset(fx.Context(), &GetDatasetRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -687,7 +695,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) 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.GetDataset(fx.Context(), &GetDatasetRequest{ + _, err := fx.Service().GetDataset(fx.Context(), &GetDatasetRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -698,7 +706,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetDataset(fx.Context(), &GetDatasetRequest{ + msg, err := fx.Service().GetDataset(fx.Context(), &GetDatasetRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -710,7 +718,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetDataset(fx.Context(), &GetDatasetRequest{ + _, err := fx.Service().GetDataset(fx.Context(), &GetDatasetRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -719,7 +727,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) 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.GetDataset(fx.Context(), &GetDatasetRequest{ + _, err := fx.Service().GetDataset(fx.Context(), &GetDatasetRequest{ Name: "projects/-/locations/-/datasets/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -735,7 +743,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateDataset(fx.Context(), &UpdateDatasetRequest{ + _, err := fx.Service().UpdateDataset(fx.Context(), &UpdateDatasetRequest{ Dataset: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -747,7 +755,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateDataset(fx.Context(), &UpdateDatasetRequest{ + _, err := fx.Service().UpdateDataset(fx.Context(), &UpdateDatasetRequest{ Dataset: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -758,11 +766,11 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateDataset(fx.Context(), &UpdateDatasetRequest{ + updated, err := fx.Service().UpdateDataset(fx.Context(), &UpdateDatasetRequest{ Dataset: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetDataset(fx.Context(), &GetDatasetRequest{ + persisted, err := fx.Service().GetDataset(fx.Context(), &GetDatasetRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -775,7 +783,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) created := fx.create(t, parent) originalCreateTime := created.CreateTime - updated, err := fx.service.UpdateDataset(fx.Context(), &UpdateDatasetRequest{ + updated, err := fx.Service().UpdateDataset(fx.Context(), &UpdateDatasetRequest{ Dataset: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -794,7 +802,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateDataset(fx.Context(), &UpdateDatasetRequest{ + _, err := fx.Service().UpdateDataset(fx.Context(), &UpdateDatasetRequest{ Dataset: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -803,7 +811,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) 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.UpdateDataset(fx.Context(), &UpdateDatasetRequest{ + _, err := fx.Service().UpdateDataset(fx.Context(), &UpdateDatasetRequest{ Dataset: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -827,7 +835,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateDataset(fx.Context(), &UpdateDatasetRequest{ + _, err := fx.Service().UpdateDataset(fx.Context(), &UpdateDatasetRequest{ Dataset: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -846,7 +854,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("metadata_schema_uri") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateDataset(fx.Context(), &UpdateDatasetRequest{ + _, err := fx.Service().UpdateDataset(fx.Context(), &UpdateDatasetRequest{ Dataset: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -865,7 +873,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("metadata") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateDataset(fx.Context(), &UpdateDatasetRequest{ + _, err := fx.Service().UpdateDataset(fx.Context(), &UpdateDatasetRequest{ Dataset: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -884,7 +892,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateDataset(fx.Context(), &UpdateDatasetRequest{ + _, err := fx.Service().UpdateDataset(fx.Context(), &UpdateDatasetRequest{ Dataset: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -903,7 +911,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) 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.ListDatasets(fx.Context(), &ListDatasetsRequest{ + _, err := fx.Service().ListDatasets(fx.Context(), &ListDatasetsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -913,7 +921,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListDatasets(fx.Context(), &ListDatasetsRequest{ + _, err := fx.Service().ListDatasets(fx.Context(), &ListDatasetsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -924,7 +932,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListDatasets(fx.Context(), &ListDatasetsRequest{ + _, err := fx.Service().ListDatasets(fx.Context(), &ListDatasetsRequest{ Parent: parent, PageSize: -10, }) @@ -942,7 +950,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListDatasets(fx.Context(), &ListDatasetsRequest{ + response, err := fx.Service().ListDatasets(fx.Context(), &ListDatasetsRequest{ Parent: parent, PageSize: 999, }) @@ -961,7 +969,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) 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.ListDatasets(fx.Context(), &ListDatasetsRequest{ + response, err := fx.Service().ListDatasets(fx.Context(), &ListDatasetsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -972,7 +980,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) 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.ListDatasets(fx.Context(), &ListDatasetsRequest{ + response, err := fx.Service().ListDatasets(fx.Context(), &ListDatasetsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -986,7 +994,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Dataset, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListDatasets(fx.Context(), &ListDatasetsRequest{ + response, err := fx.Service().ListDatasets(fx.Context(), &ListDatasetsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -1015,12 +1023,12 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteDataset(fx.Context(), &DeleteDatasetRequest{ + _, err := fx.Service().DeleteDataset(fx.Context(), &DeleteDatasetRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListDatasets(fx.Context(), &ListDatasetsRequest{ + response, err := fx.Service().ListDatasets(fx.Context(), &ListDatasetsRequest{ Parent: parent, PageSize: 9999, }) @@ -1043,7 +1051,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testDelete(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.DeleteDataset(fx.Context(), &DeleteDatasetRequest{ + _, err := fx.Service().DeleteDataset(fx.Context(), &DeleteDatasetRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1052,7 +1060,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testDelete(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.DeleteDataset(fx.Context(), &DeleteDatasetRequest{ + _, err := fx.Service().DeleteDataset(fx.Context(), &DeleteDatasetRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1063,7 +1071,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteDataset(fx.Context(), &DeleteDatasetRequest{ + _, err := fx.Service().DeleteDataset(fx.Context(), &DeleteDatasetRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1074,7 +1082,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteDataset(fx.Context(), &DeleteDatasetRequest{ + _, err := fx.Service().DeleteDataset(fx.Context(), &DeleteDatasetRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1085,12 +1093,12 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteDataset(fx.Context(), &DeleteDatasetRequest{ + deleted, err := fx.Service().DeleteDataset(fx.Context(), &DeleteDatasetRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteDataset(fx.Context(), &DeleteDatasetRequest{ + _, err = fx.Service().DeleteDataset(fx.Context(), &DeleteDatasetRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1099,7 +1107,7 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) testDelete(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.DeleteDataset(fx.Context(), &DeleteDatasetRequest{ + _, err := fx.Service().DeleteDataset(fx.Context(), &DeleteDatasetRequest{ Name: "projects/-/locations/-/datasets/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1140,9 +1148,11 @@ func (fx *DatasetServiceDatasetTestSuiteConfig) create(t *testing.T, parent stri } type DatasetServiceDatasetVersionTestSuiteConfig struct { - service DatasetServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() DatasetServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -1173,7 +1183,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) 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.CreateDatasetVersion(fx.Context(), &CreateDatasetVersionRequest{ + _, err := fx.Service().CreateDatasetVersion(fx.Context(), &CreateDatasetVersionRequest{ Parent: "", DatasetVersion: fx.Create(fx.nextParent(t, false)), }) @@ -1183,7 +1193,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) 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.CreateDatasetVersion(fx.Context(), &CreateDatasetVersionRequest{ + _, err := fx.Service().CreateDatasetVersion(fx.Context(), &CreateDatasetVersionRequest{ Parent: "invalid resource name", DatasetVersion: fx.Create(fx.nextParent(t, false)), }) @@ -1197,7 +1207,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) 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.GetDatasetVersion(fx.Context(), &GetDatasetVersionRequest{ + _, err := fx.Service().GetDatasetVersion(fx.Context(), &GetDatasetVersionRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1206,7 +1216,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) 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.GetDatasetVersion(fx.Context(), &GetDatasetVersionRequest{ + _, err := fx.Service().GetDatasetVersion(fx.Context(), &GetDatasetVersionRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1217,7 +1227,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetDatasetVersion(fx.Context(), &GetDatasetVersionRequest{ + msg, err := fx.Service().GetDatasetVersion(fx.Context(), &GetDatasetVersionRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1229,7 +1239,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetDatasetVersion(fx.Context(), &GetDatasetVersionRequest{ + _, err := fx.Service().GetDatasetVersion(fx.Context(), &GetDatasetVersionRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1238,7 +1248,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) 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.GetDatasetVersion(fx.Context(), &GetDatasetVersionRequest{ + _, err := fx.Service().GetDatasetVersion(fx.Context(), &GetDatasetVersionRequest{ Name: "projects/-/locations/-/datasets/-/datasetVersions/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1251,7 +1261,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) 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.ListDatasetVersions(fx.Context(), &ListDatasetVersionsRequest{ + _, err := fx.Service().ListDatasetVersions(fx.Context(), &ListDatasetVersionsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1261,7 +1271,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListDatasetVersions(fx.Context(), &ListDatasetVersionsRequest{ + _, err := fx.Service().ListDatasetVersions(fx.Context(), &ListDatasetVersionsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -1272,7 +1282,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListDatasetVersions(fx.Context(), &ListDatasetVersionsRequest{ + _, err := fx.Service().ListDatasetVersions(fx.Context(), &ListDatasetVersionsRequest{ Parent: parent, PageSize: -10, }) @@ -1290,7 +1300,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListDatasetVersions(fx.Context(), &ListDatasetVersionsRequest{ + response, err := fx.Service().ListDatasetVersions(fx.Context(), &ListDatasetVersionsRequest{ Parent: parent, PageSize: 999, }) @@ -1309,7 +1319,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) 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.ListDatasetVersions(fx.Context(), &ListDatasetVersionsRequest{ + response, err := fx.Service().ListDatasetVersions(fx.Context(), &ListDatasetVersionsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -1320,7 +1330,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) 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.ListDatasetVersions(fx.Context(), &ListDatasetVersionsRequest{ + response, err := fx.Service().ListDatasetVersions(fx.Context(), &ListDatasetVersionsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -1334,7 +1344,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) testList(t *testing.T) { msgs := make([]*DatasetVersion, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListDatasetVersions(fx.Context(), &ListDatasetVersionsRequest{ + response, err := fx.Service().ListDatasetVersions(fx.Context(), &ListDatasetVersionsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -1363,12 +1373,12 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteDatasetVersion(fx.Context(), &DeleteDatasetVersionRequest{ + _, err := fx.Service().DeleteDatasetVersion(fx.Context(), &DeleteDatasetVersionRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListDatasetVersions(fx.Context(), &ListDatasetVersionsRequest{ + response, err := fx.Service().ListDatasetVersions(fx.Context(), &ListDatasetVersionsRequest{ Parent: parent, PageSize: 9999, }) @@ -1391,7 +1401,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) testDelete(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.DeleteDatasetVersion(fx.Context(), &DeleteDatasetVersionRequest{ + _, err := fx.Service().DeleteDatasetVersion(fx.Context(), &DeleteDatasetVersionRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1400,7 +1410,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) testDelete(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.DeleteDatasetVersion(fx.Context(), &DeleteDatasetVersionRequest{ + _, err := fx.Service().DeleteDatasetVersion(fx.Context(), &DeleteDatasetVersionRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1411,7 +1421,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteDatasetVersion(fx.Context(), &DeleteDatasetVersionRequest{ + _, err := fx.Service().DeleteDatasetVersion(fx.Context(), &DeleteDatasetVersionRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1422,7 +1432,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteDatasetVersion(fx.Context(), &DeleteDatasetVersionRequest{ + _, err := fx.Service().DeleteDatasetVersion(fx.Context(), &DeleteDatasetVersionRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1433,12 +1443,12 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteDatasetVersion(fx.Context(), &DeleteDatasetVersionRequest{ + deleted, err := fx.Service().DeleteDatasetVersion(fx.Context(), &DeleteDatasetVersionRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteDatasetVersion(fx.Context(), &DeleteDatasetVersionRequest{ + _, err = fx.Service().DeleteDatasetVersion(fx.Context(), &DeleteDatasetVersionRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1447,7 +1457,7 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) testDelete(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.DeleteDatasetVersion(fx.Context(), &DeleteDatasetVersionRequest{ + _, err := fx.Service().DeleteDatasetVersion(fx.Context(), &DeleteDatasetVersionRequest{ Name: "projects/-/locations/-/datasets/-/datasetVersions/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1488,9 +1498,11 @@ func (fx *DatasetServiceDatasetVersionTestSuiteConfig) create(t *testing.T, pare } type DatasetServiceSavedQueryTestSuiteConfig struct { - service DatasetServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() DatasetServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -1522,7 +1534,7 @@ func (fx *DatasetServiceSavedQueryTestSuiteConfig) 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.ListSavedQueries(fx.Context(), &ListSavedQueriesRequest{ + _, err := fx.Service().ListSavedQueries(fx.Context(), &ListSavedQueriesRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1532,7 +1544,7 @@ func (fx *DatasetServiceSavedQueryTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListSavedQueries(fx.Context(), &ListSavedQueriesRequest{ + _, err := fx.Service().ListSavedQueries(fx.Context(), &ListSavedQueriesRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -1543,7 +1555,7 @@ func (fx *DatasetServiceSavedQueryTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListSavedQueries(fx.Context(), &ListSavedQueriesRequest{ + _, err := fx.Service().ListSavedQueries(fx.Context(), &ListSavedQueriesRequest{ Parent: parent, PageSize: -10, }) @@ -1561,7 +1573,7 @@ func (fx *DatasetServiceSavedQueryTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListSavedQueries(fx.Context(), &ListSavedQueriesRequest{ + response, err := fx.Service().ListSavedQueries(fx.Context(), &ListSavedQueriesRequest{ Parent: parent, PageSize: 999, }) @@ -1580,7 +1592,7 @@ func (fx *DatasetServiceSavedQueryTestSuiteConfig) 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.ListSavedQueries(fx.Context(), &ListSavedQueriesRequest{ + response, err := fx.Service().ListSavedQueries(fx.Context(), &ListSavedQueriesRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -1591,7 +1603,7 @@ func (fx *DatasetServiceSavedQueryTestSuiteConfig) 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.ListSavedQueries(fx.Context(), &ListSavedQueriesRequest{ + response, err := fx.Service().ListSavedQueries(fx.Context(), &ListSavedQueriesRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -1605,7 +1617,7 @@ func (fx *DatasetServiceSavedQueryTestSuiteConfig) testList(t *testing.T) { msgs := make([]*SavedQuery, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListSavedQueries(fx.Context(), &ListSavedQueriesRequest{ + response, err := fx.Service().ListSavedQueries(fx.Context(), &ListSavedQueriesRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -1634,12 +1646,12 @@ func (fx *DatasetServiceSavedQueryTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteSavedQuery(fx.Context(), &DeleteSavedQueryRequest{ + _, err := fx.Service().DeleteSavedQuery(fx.Context(), &DeleteSavedQueryRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListSavedQueries(fx.Context(), &ListSavedQueriesRequest{ + response, err := fx.Service().ListSavedQueries(fx.Context(), &ListSavedQueriesRequest{ Parent: parent, PageSize: 9999, }) @@ -1662,7 +1674,7 @@ func (fx *DatasetServiceSavedQueryTestSuiteConfig) testDelete(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.DeleteSavedQuery(fx.Context(), &DeleteSavedQueryRequest{ + _, err := fx.Service().DeleteSavedQuery(fx.Context(), &DeleteSavedQueryRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1671,7 +1683,7 @@ func (fx *DatasetServiceSavedQueryTestSuiteConfig) testDelete(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.DeleteSavedQuery(fx.Context(), &DeleteSavedQueryRequest{ + _, err := fx.Service().DeleteSavedQuery(fx.Context(), &DeleteSavedQueryRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1682,7 +1694,7 @@ func (fx *DatasetServiceSavedQueryTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteSavedQuery(fx.Context(), &DeleteSavedQueryRequest{ + _, err := fx.Service().DeleteSavedQuery(fx.Context(), &DeleteSavedQueryRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1693,7 +1705,7 @@ func (fx *DatasetServiceSavedQueryTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteSavedQuery(fx.Context(), &DeleteSavedQueryRequest{ + _, err := fx.Service().DeleteSavedQuery(fx.Context(), &DeleteSavedQueryRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1704,12 +1716,12 @@ func (fx *DatasetServiceSavedQueryTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteSavedQuery(fx.Context(), &DeleteSavedQueryRequest{ + deleted, err := fx.Service().DeleteSavedQuery(fx.Context(), &DeleteSavedQueryRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteSavedQuery(fx.Context(), &DeleteSavedQueryRequest{ + _, err = fx.Service().DeleteSavedQuery(fx.Context(), &DeleteSavedQueryRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1718,7 +1730,7 @@ func (fx *DatasetServiceSavedQueryTestSuiteConfig) testDelete(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.DeleteSavedQuery(fx.Context(), &DeleteSavedQueryRequest{ + _, err := fx.Service().DeleteSavedQuery(fx.Context(), &DeleteSavedQueryRequest{ Name: "projects/-/locations/-/datasets/-/savedQueries/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) diff --git a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/deployment_resource_pool_service_aiptest.pb.go b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/deployment_resource_pool_service_aiptest.pb.go index e966bfb..2710147 100644 --- a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/deployment_resource_pool_service_aiptest.pb.go +++ b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/deployment_resource_pool_service_aiptest.pb.go @@ -22,15 +22,17 @@ type DeploymentResourcePoolServiceTestSuite struct { func (fx DeploymentResourcePoolServiceTestSuite) TestDeploymentResourcePool(ctx context.Context, options DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) { fx.T.Run("DeploymentResourcePool", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() DeploymentResourcePoolServiceServer { return fx.Server } options.test(t) }) } type DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig struct { - service DeploymentResourcePoolServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() DeploymentResourcePoolServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -61,7 +63,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te // Method should fail with InvalidArgument if no parent is provided. t.Run("missing parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateDeploymentResourcePool(fx.Context(), &CreateDeploymentResourcePoolRequest{ + _, err := fx.Service().CreateDeploymentResourcePool(fx.Context(), &CreateDeploymentResourcePoolRequest{ Parent: "", DeploymentResourcePool: fx.Create(fx.nextParent(t, false)), }) @@ -71,7 +73,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateDeploymentResourcePool(fx.Context(), &CreateDeploymentResourcePoolRequest{ + _, err := fx.Service().CreateDeploymentResourcePool(fx.Context(), &CreateDeploymentResourcePoolRequest{ Parent: "invalid resource name", DeploymentResourcePool: fx.Create(fx.nextParent(t, false)), }) @@ -92,7 +94,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te } fd := container.ProtoReflect().Descriptor().Fields().ByName("dedicated_resources") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDeploymentResourcePool(fx.Context(), &CreateDeploymentResourcePoolRequest{ + _, err := fx.Service().CreateDeploymentResourcePool(fx.Context(), &CreateDeploymentResourcePoolRequest{ Parent: parent, DeploymentResourcePool: msg, }) @@ -108,7 +110,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te } fd := container.ProtoReflect().Descriptor().Fields().ByName("machine_spec") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDeploymentResourcePool(fx.Context(), &CreateDeploymentResourcePoolRequest{ + _, err := fx.Service().CreateDeploymentResourcePool(fx.Context(), &CreateDeploymentResourcePoolRequest{ Parent: parent, DeploymentResourcePool: msg, }) @@ -124,7 +126,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te } fd := container.ProtoReflect().Descriptor().Fields().ByName("min_replica_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDeploymentResourcePool(fx.Context(), &CreateDeploymentResourcePoolRequest{ + _, err := fx.Service().CreateDeploymentResourcePool(fx.Context(), &CreateDeploymentResourcePoolRequest{ Parent: parent, DeploymentResourcePool: msg, }) @@ -139,7 +141,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.GetDeploymentResourcePool(fx.Context(), &GetDeploymentResourcePoolRequest{ + _, err := fx.Service().GetDeploymentResourcePool(fx.Context(), &GetDeploymentResourcePoolRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -148,7 +150,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te // 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.GetDeploymentResourcePool(fx.Context(), &GetDeploymentResourcePoolRequest{ + _, err := fx.Service().GetDeploymentResourcePool(fx.Context(), &GetDeploymentResourcePoolRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -159,7 +161,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetDeploymentResourcePool(fx.Context(), &GetDeploymentResourcePoolRequest{ + msg, err := fx.Service().GetDeploymentResourcePool(fx.Context(), &GetDeploymentResourcePoolRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -171,7 +173,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetDeploymentResourcePool(fx.Context(), &GetDeploymentResourcePoolRequest{ + _, err := fx.Service().GetDeploymentResourcePool(fx.Context(), &GetDeploymentResourcePoolRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -180,7 +182,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te // 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.GetDeploymentResourcePool(fx.Context(), &GetDeploymentResourcePoolRequest{ + _, err := fx.Service().GetDeploymentResourcePool(fx.Context(), &GetDeploymentResourcePoolRequest{ Name: "projects/-/locations/-/deploymentResourcePools/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -193,7 +195,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListDeploymentResourcePools(fx.Context(), &ListDeploymentResourcePoolsRequest{ + _, err := fx.Service().ListDeploymentResourcePools(fx.Context(), &ListDeploymentResourcePoolsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -203,7 +205,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListDeploymentResourcePools(fx.Context(), &ListDeploymentResourcePoolsRequest{ + _, err := fx.Service().ListDeploymentResourcePools(fx.Context(), &ListDeploymentResourcePoolsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -214,7 +216,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListDeploymentResourcePools(fx.Context(), &ListDeploymentResourcePoolsRequest{ + _, err := fx.Service().ListDeploymentResourcePools(fx.Context(), &ListDeploymentResourcePoolsRequest{ Parent: parent, PageSize: -10, }) @@ -232,7 +234,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListDeploymentResourcePools(fx.Context(), &ListDeploymentResourcePoolsRequest{ + response, err := fx.Service().ListDeploymentResourcePools(fx.Context(), &ListDeploymentResourcePoolsRequest{ Parent: parent, PageSize: 999, }) @@ -251,7 +253,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te // 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.ListDeploymentResourcePools(fx.Context(), &ListDeploymentResourcePoolsRequest{ + response, err := fx.Service().ListDeploymentResourcePools(fx.Context(), &ListDeploymentResourcePoolsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -262,7 +264,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te // 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.ListDeploymentResourcePools(fx.Context(), &ListDeploymentResourcePoolsRequest{ + response, err := fx.Service().ListDeploymentResourcePools(fx.Context(), &ListDeploymentResourcePoolsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -276,7 +278,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te msgs := make([]*DeploymentResourcePool, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListDeploymentResourcePools(fx.Context(), &ListDeploymentResourcePoolsRequest{ + response, err := fx.Service().ListDeploymentResourcePools(fx.Context(), &ListDeploymentResourcePoolsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -305,12 +307,12 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteDeploymentResourcePool(fx.Context(), &DeleteDeploymentResourcePoolRequest{ + _, err := fx.Service().DeleteDeploymentResourcePool(fx.Context(), &DeleteDeploymentResourcePoolRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListDeploymentResourcePools(fx.Context(), &ListDeploymentResourcePoolsRequest{ + response, err := fx.Service().ListDeploymentResourcePools(fx.Context(), &ListDeploymentResourcePoolsRequest{ Parent: parent, PageSize: 9999, }) @@ -333,7 +335,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.DeleteDeploymentResourcePool(fx.Context(), &DeleteDeploymentResourcePoolRequest{ + _, err := fx.Service().DeleteDeploymentResourcePool(fx.Context(), &DeleteDeploymentResourcePoolRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -342,7 +344,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te // 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.DeleteDeploymentResourcePool(fx.Context(), &DeleteDeploymentResourcePoolRequest{ + _, err := fx.Service().DeleteDeploymentResourcePool(fx.Context(), &DeleteDeploymentResourcePoolRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -353,7 +355,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteDeploymentResourcePool(fx.Context(), &DeleteDeploymentResourcePoolRequest{ + _, err := fx.Service().DeleteDeploymentResourcePool(fx.Context(), &DeleteDeploymentResourcePoolRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -364,7 +366,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteDeploymentResourcePool(fx.Context(), &DeleteDeploymentResourcePoolRequest{ + _, err := fx.Service().DeleteDeploymentResourcePool(fx.Context(), &DeleteDeploymentResourcePoolRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -375,12 +377,12 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteDeploymentResourcePool(fx.Context(), &DeleteDeploymentResourcePoolRequest{ + deleted, err := fx.Service().DeleteDeploymentResourcePool(fx.Context(), &DeleteDeploymentResourcePoolRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteDeploymentResourcePool(fx.Context(), &DeleteDeploymentResourcePoolRequest{ + _, err = fx.Service().DeleteDeploymentResourcePool(fx.Context(), &DeleteDeploymentResourcePoolRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -389,7 +391,7 @@ func (fx *DeploymentResourcePoolServiceDeploymentResourcePoolTestSuiteConfig) te // 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.DeleteDeploymentResourcePool(fx.Context(), &DeleteDeploymentResourcePoolRequest{ + _, err := fx.Service().DeleteDeploymentResourcePool(fx.Context(), &DeleteDeploymentResourcePoolRequest{ Name: "projects/-/locations/-/deploymentResourcePools/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) diff --git a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/endpoint_service_aiptest.pb.go b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/endpoint_service_aiptest.pb.go index 3789402..6afc1cc 100644 --- a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/endpoint_service_aiptest.pb.go +++ b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/endpoint_service_aiptest.pb.go @@ -24,15 +24,17 @@ type EndpointServiceTestSuite struct { func (fx EndpointServiceTestSuite) TestEndpoint(ctx context.Context, options EndpointServiceEndpointTestSuiteConfig) { fx.T.Run("Endpoint", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() EndpointServiceServer { return fx.Server } options.test(t) }) } type EndpointServiceEndpointTestSuiteConfig struct { - service EndpointServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() EndpointServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -67,7 +69,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) 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.CreateEndpoint(fx.Context(), &CreateEndpointRequest{ + _, err := fx.Service().CreateEndpoint(fx.Context(), &CreateEndpointRequest{ Parent: "", Endpoint: fx.Create(fx.nextParent(t, false)), }) @@ -77,7 +79,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) 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.CreateEndpoint(fx.Context(), &CreateEndpointRequest{ + _, err := fx.Service().CreateEndpoint(fx.Context(), &CreateEndpointRequest{ Parent: "invalid resource name", Endpoint: fx.Create(fx.nextParent(t, false)), }) @@ -98,7 +100,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateEndpoint(fx.Context(), &CreateEndpointRequest{ + _, err := fx.Service().CreateEndpoint(fx.Context(), &CreateEndpointRequest{ Parent: parent, Endpoint: msg, }) @@ -114,7 +116,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateEndpoint(fx.Context(), &CreateEndpointRequest{ + _, err := fx.Service().CreateEndpoint(fx.Context(), &CreateEndpointRequest{ Parent: parent, Endpoint: msg, }) @@ -130,7 +132,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("output_uri") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateEndpoint(fx.Context(), &CreateEndpointRequest{ + _, err := fx.Service().CreateEndpoint(fx.Context(), &CreateEndpointRequest{ Parent: parent, Endpoint: msg, }) @@ -151,7 +153,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Network = "invalid resource name" - _, err := fx.service.CreateEndpoint(fx.Context(), &CreateEndpointRequest{ + _, err := fx.Service().CreateEndpoint(fx.Context(), &CreateEndpointRequest{ Parent: parent, Endpoint: msg, }) @@ -166,7 +168,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) 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.GetEndpoint(fx.Context(), &GetEndpointRequest{ + _, err := fx.Service().GetEndpoint(fx.Context(), &GetEndpointRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -175,7 +177,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) 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.GetEndpoint(fx.Context(), &GetEndpointRequest{ + _, err := fx.Service().GetEndpoint(fx.Context(), &GetEndpointRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -186,7 +188,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetEndpoint(fx.Context(), &GetEndpointRequest{ + msg, err := fx.Service().GetEndpoint(fx.Context(), &GetEndpointRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -198,7 +200,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetEndpoint(fx.Context(), &GetEndpointRequest{ + _, err := fx.Service().GetEndpoint(fx.Context(), &GetEndpointRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -207,7 +209,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) 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.GetEndpoint(fx.Context(), &GetEndpointRequest{ + _, err := fx.Service().GetEndpoint(fx.Context(), &GetEndpointRequest{ Name: "projects/-/locations/-/endpoints/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -223,7 +225,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ + _, err := fx.Service().UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ Endpoint: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -235,7 +237,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ + _, err := fx.Service().UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ Endpoint: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -246,11 +248,11 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ + updated, err := fx.Service().UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ Endpoint: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetEndpoint(fx.Context(), &GetEndpointRequest{ + persisted, err := fx.Service().GetEndpoint(fx.Context(), &GetEndpointRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -263,7 +265,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) created := fx.create(t, parent) originalCreateTime := created.CreateTime - updated, err := fx.service.UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ + updated, err := fx.Service().UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ Endpoint: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -282,7 +284,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ + _, err := fx.Service().UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ Endpoint: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -291,7 +293,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) 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.UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ + _, err := fx.Service().UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ Endpoint: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -315,7 +317,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ + _, err := fx.Service().UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ Endpoint: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -334,7 +336,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ + _, err := fx.Service().UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ Endpoint: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -353,7 +355,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("output_uri") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ + _, err := fx.Service().UpdateEndpoint(fx.Context(), &UpdateEndpointRequest{ Endpoint: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -372,7 +374,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) 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.ListEndpoints(fx.Context(), &ListEndpointsRequest{ + _, err := fx.Service().ListEndpoints(fx.Context(), &ListEndpointsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -382,7 +384,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListEndpoints(fx.Context(), &ListEndpointsRequest{ + _, err := fx.Service().ListEndpoints(fx.Context(), &ListEndpointsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -393,7 +395,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListEndpoints(fx.Context(), &ListEndpointsRequest{ + _, err := fx.Service().ListEndpoints(fx.Context(), &ListEndpointsRequest{ Parent: parent, PageSize: -10, }) @@ -411,7 +413,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListEndpoints(fx.Context(), &ListEndpointsRequest{ + response, err := fx.Service().ListEndpoints(fx.Context(), &ListEndpointsRequest{ Parent: parent, PageSize: 999, }) @@ -430,7 +432,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) 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.ListEndpoints(fx.Context(), &ListEndpointsRequest{ + response, err := fx.Service().ListEndpoints(fx.Context(), &ListEndpointsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -441,7 +443,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) 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.ListEndpoints(fx.Context(), &ListEndpointsRequest{ + response, err := fx.Service().ListEndpoints(fx.Context(), &ListEndpointsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -455,7 +457,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Endpoint, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListEndpoints(fx.Context(), &ListEndpointsRequest{ + response, err := fx.Service().ListEndpoints(fx.Context(), &ListEndpointsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -484,12 +486,12 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteEndpoint(fx.Context(), &DeleteEndpointRequest{ + _, err := fx.Service().DeleteEndpoint(fx.Context(), &DeleteEndpointRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListEndpoints(fx.Context(), &ListEndpointsRequest{ + response, err := fx.Service().ListEndpoints(fx.Context(), &ListEndpointsRequest{ Parent: parent, PageSize: 9999, }) @@ -512,7 +514,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testDelete(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.DeleteEndpoint(fx.Context(), &DeleteEndpointRequest{ + _, err := fx.Service().DeleteEndpoint(fx.Context(), &DeleteEndpointRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -521,7 +523,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testDelete(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.DeleteEndpoint(fx.Context(), &DeleteEndpointRequest{ + _, err := fx.Service().DeleteEndpoint(fx.Context(), &DeleteEndpointRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -532,7 +534,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteEndpoint(fx.Context(), &DeleteEndpointRequest{ + _, err := fx.Service().DeleteEndpoint(fx.Context(), &DeleteEndpointRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -543,7 +545,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteEndpoint(fx.Context(), &DeleteEndpointRequest{ + _, err := fx.Service().DeleteEndpoint(fx.Context(), &DeleteEndpointRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -554,12 +556,12 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteEndpoint(fx.Context(), &DeleteEndpointRequest{ + deleted, err := fx.Service().DeleteEndpoint(fx.Context(), &DeleteEndpointRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteEndpoint(fx.Context(), &DeleteEndpointRequest{ + _, err = fx.Service().DeleteEndpoint(fx.Context(), &DeleteEndpointRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -568,7 +570,7 @@ func (fx *EndpointServiceEndpointTestSuiteConfig) testDelete(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.DeleteEndpoint(fx.Context(), &DeleteEndpointRequest{ + _, err := fx.Service().DeleteEndpoint(fx.Context(), &DeleteEndpointRequest{ Name: "projects/-/locations/-/endpoints/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) diff --git a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/feature_online_store_admin_service_aiptest.pb.go b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/feature_online_store_admin_service_aiptest.pb.go index 0500233..cc01d3d 100644 --- a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/feature_online_store_admin_service_aiptest.pb.go +++ b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/feature_online_store_admin_service_aiptest.pb.go @@ -24,7 +24,7 @@ type FeatureOnlineStoreAdminServiceTestSuite struct { func (fx FeatureOnlineStoreAdminServiceTestSuite) TestFeatureOnlineStore(ctx context.Context, options FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) { fx.T.Run("FeatureOnlineStore", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() FeatureOnlineStoreAdminServiceServer { return fx.Server } options.test(t) }) } @@ -32,7 +32,7 @@ func (fx FeatureOnlineStoreAdminServiceTestSuite) TestFeatureOnlineStore(ctx con func (fx FeatureOnlineStoreAdminServiceTestSuite) TestFeatureView(ctx context.Context, options FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) { fx.T.Run("FeatureView", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() FeatureOnlineStoreAdminServiceServer { return fx.Server } options.test(t) }) } @@ -40,15 +40,17 @@ func (fx FeatureOnlineStoreAdminServiceTestSuite) TestFeatureView(ctx context.Co func (fx FeatureOnlineStoreAdminServiceTestSuite) TestFeatureViewSync(ctx context.Context, options FeatureOnlineStoreAdminServiceFeatureViewSyncTestSuiteConfig) { fx.T.Run("FeatureViewSync", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() FeatureOnlineStoreAdminServiceServer { return fx.Server } options.test(t) }) } type FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig struct { - service FeatureOnlineStoreAdminServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() FeatureOnlineStoreAdminServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -83,7 +85,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testC // Method should fail with InvalidArgument if no parent is provided. t.Run("missing parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateFeatureOnlineStore(fx.Context(), &CreateFeatureOnlineStoreRequest{ + _, err := fx.Service().CreateFeatureOnlineStore(fx.Context(), &CreateFeatureOnlineStoreRequest{ Parent: "", FeatureOnlineStore: fx.Create(fx.nextParent(t, false)), }) @@ -93,7 +95,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testC // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateFeatureOnlineStore(fx.Context(), &CreateFeatureOnlineStoreRequest{ + _, err := fx.Service().CreateFeatureOnlineStore(fx.Context(), &CreateFeatureOnlineStoreRequest{ Parent: "invalid resource name", FeatureOnlineStore: fx.Create(fx.nextParent(t, false)), }) @@ -114,7 +116,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testC } fd := container.ProtoReflect().Descriptor().Fields().ByName("auto_scaling") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateFeatureOnlineStore(fx.Context(), &CreateFeatureOnlineStoreRequest{ + _, err := fx.Service().CreateFeatureOnlineStore(fx.Context(), &CreateFeatureOnlineStoreRequest{ Parent: parent, FeatureOnlineStore: msg, }) @@ -130,7 +132,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testC } fd := container.ProtoReflect().Descriptor().Fields().ByName("min_node_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateFeatureOnlineStore(fx.Context(), &CreateFeatureOnlineStoreRequest{ + _, err := fx.Service().CreateFeatureOnlineStore(fx.Context(), &CreateFeatureOnlineStoreRequest{ Parent: parent, FeatureOnlineStore: msg, }) @@ -146,7 +148,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testC } fd := container.ProtoReflect().Descriptor().Fields().ByName("max_node_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateFeatureOnlineStore(fx.Context(), &CreateFeatureOnlineStoreRequest{ + _, err := fx.Service().CreateFeatureOnlineStore(fx.Context(), &CreateFeatureOnlineStoreRequest{ Parent: parent, FeatureOnlineStore: msg, }) @@ -161,7 +163,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testG // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.GetFeatureOnlineStore(fx.Context(), &GetFeatureOnlineStoreRequest{ + _, err := fx.Service().GetFeatureOnlineStore(fx.Context(), &GetFeatureOnlineStoreRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -170,7 +172,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testG // 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.GetFeatureOnlineStore(fx.Context(), &GetFeatureOnlineStoreRequest{ + _, err := fx.Service().GetFeatureOnlineStore(fx.Context(), &GetFeatureOnlineStoreRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -181,7 +183,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testG fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetFeatureOnlineStore(fx.Context(), &GetFeatureOnlineStoreRequest{ + msg, err := fx.Service().GetFeatureOnlineStore(fx.Context(), &GetFeatureOnlineStoreRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -193,7 +195,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testG fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetFeatureOnlineStore(fx.Context(), &GetFeatureOnlineStoreRequest{ + _, err := fx.Service().GetFeatureOnlineStore(fx.Context(), &GetFeatureOnlineStoreRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -202,7 +204,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testG // 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.GetFeatureOnlineStore(fx.Context(), &GetFeatureOnlineStoreRequest{ + _, err := fx.Service().GetFeatureOnlineStore(fx.Context(), &GetFeatureOnlineStoreRequest{ Name: "projects/-/locations/-/featureOnlineStores/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -218,7 +220,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testU parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateFeatureOnlineStore(fx.Context(), &UpdateFeatureOnlineStoreRequest{ + _, err := fx.Service().UpdateFeatureOnlineStore(fx.Context(), &UpdateFeatureOnlineStoreRequest{ FeatureOnlineStore: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -230,7 +232,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testU parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateFeatureOnlineStore(fx.Context(), &UpdateFeatureOnlineStoreRequest{ + _, err := fx.Service().UpdateFeatureOnlineStore(fx.Context(), &UpdateFeatureOnlineStoreRequest{ FeatureOnlineStore: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -243,7 +245,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testU fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateFeatureOnlineStore(fx.Context(), &UpdateFeatureOnlineStoreRequest{ + _, err := fx.Service().UpdateFeatureOnlineStore(fx.Context(), &UpdateFeatureOnlineStoreRequest{ FeatureOnlineStore: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -252,7 +254,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testU // 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.UpdateFeatureOnlineStore(fx.Context(), &UpdateFeatureOnlineStoreRequest{ + _, err := fx.Service().UpdateFeatureOnlineStore(fx.Context(), &UpdateFeatureOnlineStoreRequest{ FeatureOnlineStore: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -276,7 +278,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testU } fd := container.ProtoReflect().Descriptor().Fields().ByName("auto_scaling") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateFeatureOnlineStore(fx.Context(), &UpdateFeatureOnlineStoreRequest{ + _, err := fx.Service().UpdateFeatureOnlineStore(fx.Context(), &UpdateFeatureOnlineStoreRequest{ FeatureOnlineStore: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -295,7 +297,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testU } fd := container.ProtoReflect().Descriptor().Fields().ByName("min_node_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateFeatureOnlineStore(fx.Context(), &UpdateFeatureOnlineStoreRequest{ + _, err := fx.Service().UpdateFeatureOnlineStore(fx.Context(), &UpdateFeatureOnlineStoreRequest{ FeatureOnlineStore: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -314,7 +316,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testU } fd := container.ProtoReflect().Descriptor().Fields().ByName("max_node_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateFeatureOnlineStore(fx.Context(), &UpdateFeatureOnlineStoreRequest{ + _, err := fx.Service().UpdateFeatureOnlineStore(fx.Context(), &UpdateFeatureOnlineStoreRequest{ FeatureOnlineStore: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -333,7 +335,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testL // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListFeatureOnlineStores(fx.Context(), &ListFeatureOnlineStoresRequest{ + _, err := fx.Service().ListFeatureOnlineStores(fx.Context(), &ListFeatureOnlineStoresRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -343,7 +345,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testL t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListFeatureOnlineStores(fx.Context(), &ListFeatureOnlineStoresRequest{ + _, err := fx.Service().ListFeatureOnlineStores(fx.Context(), &ListFeatureOnlineStoresRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -354,7 +356,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testL t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListFeatureOnlineStores(fx.Context(), &ListFeatureOnlineStoresRequest{ + _, err := fx.Service().ListFeatureOnlineStores(fx.Context(), &ListFeatureOnlineStoresRequest{ Parent: parent, PageSize: -10, }) @@ -372,7 +374,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testL // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListFeatureOnlineStores(fx.Context(), &ListFeatureOnlineStoresRequest{ + response, err := fx.Service().ListFeatureOnlineStores(fx.Context(), &ListFeatureOnlineStoresRequest{ Parent: parent, PageSize: 999, }) @@ -391,7 +393,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testL // 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.ListFeatureOnlineStores(fx.Context(), &ListFeatureOnlineStoresRequest{ + response, err := fx.Service().ListFeatureOnlineStores(fx.Context(), &ListFeatureOnlineStoresRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -402,7 +404,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testL // 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.ListFeatureOnlineStores(fx.Context(), &ListFeatureOnlineStoresRequest{ + response, err := fx.Service().ListFeatureOnlineStores(fx.Context(), &ListFeatureOnlineStoresRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -416,7 +418,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testL msgs := make([]*FeatureOnlineStore, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListFeatureOnlineStores(fx.Context(), &ListFeatureOnlineStoresRequest{ + response, err := fx.Service().ListFeatureOnlineStores(fx.Context(), &ListFeatureOnlineStoresRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -445,12 +447,12 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testL fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteFeatureOnlineStore(fx.Context(), &DeleteFeatureOnlineStoreRequest{ + _, err := fx.Service().DeleteFeatureOnlineStore(fx.Context(), &DeleteFeatureOnlineStoreRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListFeatureOnlineStores(fx.Context(), &ListFeatureOnlineStoresRequest{ + response, err := fx.Service().ListFeatureOnlineStores(fx.Context(), &ListFeatureOnlineStoresRequest{ Parent: parent, PageSize: 9999, }) @@ -473,7 +475,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testD // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.DeleteFeatureOnlineStore(fx.Context(), &DeleteFeatureOnlineStoreRequest{ + _, err := fx.Service().DeleteFeatureOnlineStore(fx.Context(), &DeleteFeatureOnlineStoreRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -482,7 +484,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testD // 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.DeleteFeatureOnlineStore(fx.Context(), &DeleteFeatureOnlineStoreRequest{ + _, err := fx.Service().DeleteFeatureOnlineStore(fx.Context(), &DeleteFeatureOnlineStoreRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -493,7 +495,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testD fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteFeatureOnlineStore(fx.Context(), &DeleteFeatureOnlineStoreRequest{ + _, err := fx.Service().DeleteFeatureOnlineStore(fx.Context(), &DeleteFeatureOnlineStoreRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -504,7 +506,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testD fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteFeatureOnlineStore(fx.Context(), &DeleteFeatureOnlineStoreRequest{ + _, err := fx.Service().DeleteFeatureOnlineStore(fx.Context(), &DeleteFeatureOnlineStoreRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -515,12 +517,12 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testD fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteFeatureOnlineStore(fx.Context(), &DeleteFeatureOnlineStoreRequest{ + deleted, err := fx.Service().DeleteFeatureOnlineStore(fx.Context(), &DeleteFeatureOnlineStoreRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteFeatureOnlineStore(fx.Context(), &DeleteFeatureOnlineStoreRequest{ + _, err = fx.Service().DeleteFeatureOnlineStore(fx.Context(), &DeleteFeatureOnlineStoreRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -529,7 +531,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) testD // 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.DeleteFeatureOnlineStore(fx.Context(), &DeleteFeatureOnlineStoreRequest{ + _, err := fx.Service().DeleteFeatureOnlineStore(fx.Context(), &DeleteFeatureOnlineStoreRequest{ Name: "projects/-/locations/-/featureOnlineStores/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -570,9 +572,11 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureOnlineStoreTestSuiteConfig) creat } type FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig struct { - service FeatureOnlineStoreAdminServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() FeatureOnlineStoreAdminServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -607,7 +611,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testCreate(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.CreateFeatureView(fx.Context(), &CreateFeatureViewRequest{ + _, err := fx.Service().CreateFeatureView(fx.Context(), &CreateFeatureViewRequest{ Parent: "", FeatureView: fx.Create(fx.nextParent(t, false)), }) @@ -617,7 +621,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testCreate(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.CreateFeatureView(fx.Context(), &CreateFeatureViewRequest{ + _, err := fx.Service().CreateFeatureView(fx.Context(), &CreateFeatureViewRequest{ Parent: "invalid resource name", FeatureView: fx.Create(fx.nextParent(t, false)), }) @@ -638,7 +642,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testCreate(t } fd := container.ProtoReflect().Descriptor().Fields().ByName("uri") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateFeatureView(fx.Context(), &CreateFeatureViewRequest{ + _, err := fx.Service().CreateFeatureView(fx.Context(), &CreateFeatureViewRequest{ Parent: parent, FeatureView: msg, }) @@ -654,7 +658,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testCreate(t } fd := container.ProtoReflect().Descriptor().Fields().ByName("entity_id_columns") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateFeatureView(fx.Context(), &CreateFeatureViewRequest{ + _, err := fx.Service().CreateFeatureView(fx.Context(), &CreateFeatureViewRequest{ Parent: parent, FeatureView: msg, }) @@ -670,7 +674,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testCreate(t } fd := container.ProtoReflect().Descriptor().Fields().ByName("feature_groups") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateFeatureView(fx.Context(), &CreateFeatureViewRequest{ + _, err := fx.Service().CreateFeatureView(fx.Context(), &CreateFeatureViewRequest{ Parent: parent, FeatureView: msg, }) @@ -685,7 +689,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testGet(t *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.GetFeatureView(fx.Context(), &GetFeatureViewRequest{ + _, err := fx.Service().GetFeatureView(fx.Context(), &GetFeatureViewRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -694,7 +698,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testGet(t *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.GetFeatureView(fx.Context(), &GetFeatureViewRequest{ + _, err := fx.Service().GetFeatureView(fx.Context(), &GetFeatureViewRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -705,7 +709,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testGet(t *t fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetFeatureView(fx.Context(), &GetFeatureViewRequest{ + msg, err := fx.Service().GetFeatureView(fx.Context(), &GetFeatureViewRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -717,7 +721,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testGet(t *t fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetFeatureView(fx.Context(), &GetFeatureViewRequest{ + _, err := fx.Service().GetFeatureView(fx.Context(), &GetFeatureViewRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -726,7 +730,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testGet(t *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.GetFeatureView(fx.Context(), &GetFeatureViewRequest{ + _, err := fx.Service().GetFeatureView(fx.Context(), &GetFeatureViewRequest{ Name: "projects/-/locations/-/featureOnlineStores/-/featureViews/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -742,7 +746,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testUpdate(t parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateFeatureView(fx.Context(), &UpdateFeatureViewRequest{ + _, err := fx.Service().UpdateFeatureView(fx.Context(), &UpdateFeatureViewRequest{ FeatureView: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -754,7 +758,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testUpdate(t parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateFeatureView(fx.Context(), &UpdateFeatureViewRequest{ + _, err := fx.Service().UpdateFeatureView(fx.Context(), &UpdateFeatureViewRequest{ FeatureView: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -767,7 +771,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testUpdate(t fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateFeatureView(fx.Context(), &UpdateFeatureViewRequest{ + _, err := fx.Service().UpdateFeatureView(fx.Context(), &UpdateFeatureViewRequest{ FeatureView: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -776,7 +780,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testUpdate(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.UpdateFeatureView(fx.Context(), &UpdateFeatureViewRequest{ + _, err := fx.Service().UpdateFeatureView(fx.Context(), &UpdateFeatureViewRequest{ FeatureView: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -800,7 +804,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testUpdate(t } fd := container.ProtoReflect().Descriptor().Fields().ByName("uri") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateFeatureView(fx.Context(), &UpdateFeatureViewRequest{ + _, err := fx.Service().UpdateFeatureView(fx.Context(), &UpdateFeatureViewRequest{ FeatureView: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -819,7 +823,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testUpdate(t } fd := container.ProtoReflect().Descriptor().Fields().ByName("entity_id_columns") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateFeatureView(fx.Context(), &UpdateFeatureViewRequest{ + _, err := fx.Service().UpdateFeatureView(fx.Context(), &UpdateFeatureViewRequest{ FeatureView: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -838,7 +842,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testUpdate(t } fd := container.ProtoReflect().Descriptor().Fields().ByName("feature_groups") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateFeatureView(fx.Context(), &UpdateFeatureViewRequest{ + _, err := fx.Service().UpdateFeatureView(fx.Context(), &UpdateFeatureViewRequest{ FeatureView: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -857,7 +861,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testList(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.ListFeatureViews(fx.Context(), &ListFeatureViewsRequest{ + _, err := fx.Service().ListFeatureViews(fx.Context(), &ListFeatureViewsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -867,7 +871,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testList(t * t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListFeatureViews(fx.Context(), &ListFeatureViewsRequest{ + _, err := fx.Service().ListFeatureViews(fx.Context(), &ListFeatureViewsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -878,7 +882,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testList(t * t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListFeatureViews(fx.Context(), &ListFeatureViewsRequest{ + _, err := fx.Service().ListFeatureViews(fx.Context(), &ListFeatureViewsRequest{ Parent: parent, PageSize: -10, }) @@ -896,7 +900,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testList(t * // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListFeatureViews(fx.Context(), &ListFeatureViewsRequest{ + response, err := fx.Service().ListFeatureViews(fx.Context(), &ListFeatureViewsRequest{ Parent: parent, PageSize: 999, }) @@ -915,7 +919,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testList(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.ListFeatureViews(fx.Context(), &ListFeatureViewsRequest{ + response, err := fx.Service().ListFeatureViews(fx.Context(), &ListFeatureViewsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -926,7 +930,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testList(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.ListFeatureViews(fx.Context(), &ListFeatureViewsRequest{ + response, err := fx.Service().ListFeatureViews(fx.Context(), &ListFeatureViewsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -940,7 +944,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testList(t * msgs := make([]*FeatureView, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListFeatureViews(fx.Context(), &ListFeatureViewsRequest{ + response, err := fx.Service().ListFeatureViews(fx.Context(), &ListFeatureViewsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -969,12 +973,12 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testList(t * fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteFeatureView(fx.Context(), &DeleteFeatureViewRequest{ + _, err := fx.Service().DeleteFeatureView(fx.Context(), &DeleteFeatureViewRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListFeatureViews(fx.Context(), &ListFeatureViewsRequest{ + response, err := fx.Service().ListFeatureViews(fx.Context(), &ListFeatureViewsRequest{ Parent: parent, PageSize: 9999, }) @@ -997,7 +1001,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testDelete(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.DeleteFeatureView(fx.Context(), &DeleteFeatureViewRequest{ + _, err := fx.Service().DeleteFeatureView(fx.Context(), &DeleteFeatureViewRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1006,7 +1010,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testDelete(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.DeleteFeatureView(fx.Context(), &DeleteFeatureViewRequest{ + _, err := fx.Service().DeleteFeatureView(fx.Context(), &DeleteFeatureViewRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1017,7 +1021,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testDelete(t fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteFeatureView(fx.Context(), &DeleteFeatureViewRequest{ + _, err := fx.Service().DeleteFeatureView(fx.Context(), &DeleteFeatureViewRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1028,7 +1032,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testDelete(t fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteFeatureView(fx.Context(), &DeleteFeatureViewRequest{ + _, err := fx.Service().DeleteFeatureView(fx.Context(), &DeleteFeatureViewRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1039,12 +1043,12 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testDelete(t fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteFeatureView(fx.Context(), &DeleteFeatureViewRequest{ + deleted, err := fx.Service().DeleteFeatureView(fx.Context(), &DeleteFeatureViewRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteFeatureView(fx.Context(), &DeleteFeatureViewRequest{ + _, err = fx.Service().DeleteFeatureView(fx.Context(), &DeleteFeatureViewRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1053,7 +1057,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) testDelete(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.DeleteFeatureView(fx.Context(), &DeleteFeatureViewRequest{ + _, err := fx.Service().DeleteFeatureView(fx.Context(), &DeleteFeatureViewRequest{ Name: "projects/-/locations/-/featureOnlineStores/-/featureViews/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1094,9 +1098,11 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewTestSuiteConfig) create(t *te } type FeatureOnlineStoreAdminServiceFeatureViewSyncTestSuiteConfig struct { - service FeatureOnlineStoreAdminServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() FeatureOnlineStoreAdminServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -1128,7 +1134,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewSyncTestSuiteConfig) testGet( // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.GetFeatureViewSync(fx.Context(), &GetFeatureViewSyncRequest{ + _, err := fx.Service().GetFeatureViewSync(fx.Context(), &GetFeatureViewSyncRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1137,7 +1143,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewSyncTestSuiteConfig) testGet( // 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.GetFeatureViewSync(fx.Context(), &GetFeatureViewSyncRequest{ + _, err := fx.Service().GetFeatureViewSync(fx.Context(), &GetFeatureViewSyncRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1148,7 +1154,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewSyncTestSuiteConfig) testGet( fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetFeatureViewSync(fx.Context(), &GetFeatureViewSyncRequest{ + msg, err := fx.Service().GetFeatureViewSync(fx.Context(), &GetFeatureViewSyncRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1160,7 +1166,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewSyncTestSuiteConfig) testGet( fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetFeatureViewSync(fx.Context(), &GetFeatureViewSyncRequest{ + _, err := fx.Service().GetFeatureViewSync(fx.Context(), &GetFeatureViewSyncRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1169,7 +1175,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewSyncTestSuiteConfig) testGet( // 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.GetFeatureViewSync(fx.Context(), &GetFeatureViewSyncRequest{ + _, err := fx.Service().GetFeatureViewSync(fx.Context(), &GetFeatureViewSyncRequest{ Name: "projects/-/locations/-/featureOnlineStores/-/featureViews/-/featureViewSyncs/feature_view_sync", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1182,7 +1188,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewSyncTestSuiteConfig) testList // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListFeatureViewSyncs(fx.Context(), &ListFeatureViewSyncsRequest{ + _, err := fx.Service().ListFeatureViewSyncs(fx.Context(), &ListFeatureViewSyncsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1192,7 +1198,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewSyncTestSuiteConfig) testList t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListFeatureViewSyncs(fx.Context(), &ListFeatureViewSyncsRequest{ + _, err := fx.Service().ListFeatureViewSyncs(fx.Context(), &ListFeatureViewSyncsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -1203,7 +1209,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewSyncTestSuiteConfig) testList t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListFeatureViewSyncs(fx.Context(), &ListFeatureViewSyncsRequest{ + _, err := fx.Service().ListFeatureViewSyncs(fx.Context(), &ListFeatureViewSyncsRequest{ Parent: parent, PageSize: -10, }) @@ -1221,7 +1227,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewSyncTestSuiteConfig) testList // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListFeatureViewSyncs(fx.Context(), &ListFeatureViewSyncsRequest{ + response, err := fx.Service().ListFeatureViewSyncs(fx.Context(), &ListFeatureViewSyncsRequest{ Parent: parent, PageSize: 999, }) @@ -1240,7 +1246,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewSyncTestSuiteConfig) testList // 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.ListFeatureViewSyncs(fx.Context(), &ListFeatureViewSyncsRequest{ + response, err := fx.Service().ListFeatureViewSyncs(fx.Context(), &ListFeatureViewSyncsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -1251,7 +1257,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewSyncTestSuiteConfig) testList // 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.ListFeatureViewSyncs(fx.Context(), &ListFeatureViewSyncsRequest{ + response, err := fx.Service().ListFeatureViewSyncs(fx.Context(), &ListFeatureViewSyncsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -1265,7 +1271,7 @@ func (fx *FeatureOnlineStoreAdminServiceFeatureViewSyncTestSuiteConfig) testList msgs := make([]*FeatureViewSync, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListFeatureViewSyncs(fx.Context(), &ListFeatureViewSyncsRequest{ + response, err := fx.Service().ListFeatureViewSyncs(fx.Context(), &ListFeatureViewSyncsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, diff --git a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/feature_registry_service_aiptest.pb.go b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/feature_registry_service_aiptest.pb.go index 2b495dd..b48503c 100644 --- a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/feature_registry_service_aiptest.pb.go +++ b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/feature_registry_service_aiptest.pb.go @@ -24,7 +24,7 @@ type FeatureRegistryServiceTestSuite struct { func (fx FeatureRegistryServiceTestSuite) TestFeature(ctx context.Context, options FeatureRegistryServiceFeatureTestSuiteConfig) { fx.T.Run("Feature", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() FeatureRegistryServiceServer { return fx.Server } options.test(t) }) } @@ -32,15 +32,17 @@ func (fx FeatureRegistryServiceTestSuite) TestFeature(ctx context.Context, optio func (fx FeatureRegistryServiceTestSuite) TestFeatureGroup(ctx context.Context, options FeatureRegistryServiceFeatureGroupTestSuiteConfig) { fx.T.Run("FeatureGroup", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() FeatureRegistryServiceServer { return fx.Server } options.test(t) }) } type FeatureRegistryServiceFeatureTestSuiteConfig struct { - service FeatureRegistryServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() FeatureRegistryServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -83,7 +85,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testCreate(t *testing.T) if fx.IDGenerator != nil { userSetID = fx.IDGenerator() } - _, err := fx.service.CreateFeature(fx.Context(), &CreateFeatureRequest{ + _, err := fx.Service().CreateFeature(fx.Context(), &CreateFeatureRequest{ Parent: "", Feature: fx.Create(fx.nextParent(t, false)), FeatureId: userSetID, @@ -98,7 +100,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testCreate(t *testing.T) if fx.IDGenerator != nil { userSetID = fx.IDGenerator() } - _, err := fx.service.CreateFeature(fx.Context(), &CreateFeatureRequest{ + _, err := fx.Service().CreateFeature(fx.Context(), &CreateFeatureRequest{ Parent: "invalid resource name", Feature: fx.Create(fx.nextParent(t, false)), FeatureId: userSetID, @@ -113,7 +115,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) 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.GetFeature(fx.Context(), &GetFeatureRequest{ + _, err := fx.Service().GetFeature(fx.Context(), &GetFeatureRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -122,7 +124,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) 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.GetFeature(fx.Context(), &GetFeatureRequest{ + _, err := fx.Service().GetFeature(fx.Context(), &GetFeatureRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -133,7 +135,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetFeature(fx.Context(), &GetFeatureRequest{ + msg, err := fx.Service().GetFeature(fx.Context(), &GetFeatureRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -145,7 +147,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetFeature(fx.Context(), &GetFeatureRequest{ + _, err := fx.Service().GetFeature(fx.Context(), &GetFeatureRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -154,7 +156,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) 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.GetFeature(fx.Context(), &GetFeatureRequest{ + _, err := fx.Service().GetFeature(fx.Context(), &GetFeatureRequest{ Name: "projects/-/locations/-/featurestores/-/entityTypes/-/features/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -170,7 +172,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testUpdate(t *testing.T) parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateFeature(fx.Context(), &UpdateFeatureRequest{ + _, err := fx.Service().UpdateFeature(fx.Context(), &UpdateFeatureRequest{ Feature: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -182,7 +184,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testUpdate(t *testing.T) parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateFeature(fx.Context(), &UpdateFeatureRequest{ + _, err := fx.Service().UpdateFeature(fx.Context(), &UpdateFeatureRequest{ Feature: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -195,7 +197,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testUpdate(t *testing.T) fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateFeature(fx.Context(), &UpdateFeatureRequest{ + _, err := fx.Service().UpdateFeature(fx.Context(), &UpdateFeatureRequest{ Feature: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -204,7 +206,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) 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.UpdateFeature(fx.Context(), &UpdateFeatureRequest{ + _, err := fx.Service().UpdateFeature(fx.Context(), &UpdateFeatureRequest{ Feature: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -222,7 +224,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) 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.ListFeatures(fx.Context(), &ListFeaturesRequest{ + _, err := fx.Service().ListFeatures(fx.Context(), &ListFeaturesRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -232,7 +234,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListFeatures(fx.Context(), &ListFeaturesRequest{ + _, err := fx.Service().ListFeatures(fx.Context(), &ListFeaturesRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -243,7 +245,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListFeatures(fx.Context(), &ListFeaturesRequest{ + _, err := fx.Service().ListFeatures(fx.Context(), &ListFeaturesRequest{ Parent: parent, PageSize: -10, }) @@ -261,7 +263,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListFeatures(fx.Context(), &ListFeaturesRequest{ + response, err := fx.Service().ListFeatures(fx.Context(), &ListFeaturesRequest{ Parent: parent, PageSize: 999, }) @@ -280,7 +282,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) 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.ListFeatures(fx.Context(), &ListFeaturesRequest{ + response, err := fx.Service().ListFeatures(fx.Context(), &ListFeaturesRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -291,7 +293,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) 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.ListFeatures(fx.Context(), &ListFeaturesRequest{ + response, err := fx.Service().ListFeatures(fx.Context(), &ListFeaturesRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -305,7 +307,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Feature, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListFeatures(fx.Context(), &ListFeaturesRequest{ + response, err := fx.Service().ListFeatures(fx.Context(), &ListFeaturesRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -334,12 +336,12 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteFeature(fx.Context(), &DeleteFeatureRequest{ + _, err := fx.Service().DeleteFeature(fx.Context(), &DeleteFeatureRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListFeatures(fx.Context(), &ListFeaturesRequest{ + response, err := fx.Service().ListFeatures(fx.Context(), &ListFeaturesRequest{ Parent: parent, PageSize: 9999, }) @@ -362,7 +364,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testDelete(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.DeleteFeature(fx.Context(), &DeleteFeatureRequest{ + _, err := fx.Service().DeleteFeature(fx.Context(), &DeleteFeatureRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -371,7 +373,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testDelete(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.DeleteFeature(fx.Context(), &DeleteFeatureRequest{ + _, err := fx.Service().DeleteFeature(fx.Context(), &DeleteFeatureRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -382,7 +384,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteFeature(fx.Context(), &DeleteFeatureRequest{ + _, err := fx.Service().DeleteFeature(fx.Context(), &DeleteFeatureRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -393,7 +395,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteFeature(fx.Context(), &DeleteFeatureRequest{ + _, err := fx.Service().DeleteFeature(fx.Context(), &DeleteFeatureRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -404,12 +406,12 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteFeature(fx.Context(), &DeleteFeatureRequest{ + deleted, err := fx.Service().DeleteFeature(fx.Context(), &DeleteFeatureRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteFeature(fx.Context(), &DeleteFeatureRequest{ + _, err = fx.Service().DeleteFeature(fx.Context(), &DeleteFeatureRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -418,7 +420,7 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) testDelete(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.DeleteFeature(fx.Context(), &DeleteFeatureRequest{ + _, err := fx.Service().DeleteFeature(fx.Context(), &DeleteFeatureRequest{ Name: "projects/-/locations/-/featurestores/-/entityTypes/-/features/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -459,9 +461,11 @@ func (fx *FeatureRegistryServiceFeatureTestSuiteConfig) create(t *testing.T, par } type FeatureRegistryServiceFeatureGroupTestSuiteConfig struct { - service FeatureRegistryServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() FeatureRegistryServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -496,7 +500,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testCreate(t *testi // Method should fail with InvalidArgument if no parent is provided. t.Run("missing parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateFeatureGroup(fx.Context(), &CreateFeatureGroupRequest{ + _, err := fx.Service().CreateFeatureGroup(fx.Context(), &CreateFeatureGroupRequest{ Parent: "", FeatureGroup: fx.Create(fx.nextParent(t, false)), }) @@ -506,7 +510,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testCreate(t *testi // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateFeatureGroup(fx.Context(), &CreateFeatureGroupRequest{ + _, err := fx.Service().CreateFeatureGroup(fx.Context(), &CreateFeatureGroupRequest{ Parent: "invalid resource name", FeatureGroup: fx.Create(fx.nextParent(t, false)), }) @@ -527,7 +531,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testCreate(t *testi } fd := container.ProtoReflect().Descriptor().Fields().ByName("big_query_source") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateFeatureGroup(fx.Context(), &CreateFeatureGroupRequest{ + _, err := fx.Service().CreateFeatureGroup(fx.Context(), &CreateFeatureGroupRequest{ Parent: parent, FeatureGroup: msg, }) @@ -543,7 +547,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testCreate(t *testi } fd := container.ProtoReflect().Descriptor().Fields().ByName("input_uri") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateFeatureGroup(fx.Context(), &CreateFeatureGroupRequest{ + _, err := fx.Service().CreateFeatureGroup(fx.Context(), &CreateFeatureGroupRequest{ Parent: parent, FeatureGroup: msg, }) @@ -558,7 +562,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testGet(t *testing. // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.GetFeatureGroup(fx.Context(), &GetFeatureGroupRequest{ + _, err := fx.Service().GetFeatureGroup(fx.Context(), &GetFeatureGroupRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -567,7 +571,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testGet(t *testing. // 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.GetFeatureGroup(fx.Context(), &GetFeatureGroupRequest{ + _, err := fx.Service().GetFeatureGroup(fx.Context(), &GetFeatureGroupRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -578,7 +582,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testGet(t *testing. fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetFeatureGroup(fx.Context(), &GetFeatureGroupRequest{ + msg, err := fx.Service().GetFeatureGroup(fx.Context(), &GetFeatureGroupRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -590,7 +594,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testGet(t *testing. fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetFeatureGroup(fx.Context(), &GetFeatureGroupRequest{ + _, err := fx.Service().GetFeatureGroup(fx.Context(), &GetFeatureGroupRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -599,7 +603,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testGet(t *testing. // 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.GetFeatureGroup(fx.Context(), &GetFeatureGroupRequest{ + _, err := fx.Service().GetFeatureGroup(fx.Context(), &GetFeatureGroupRequest{ Name: "projects/-/locations/-/featureGroups/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -615,7 +619,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testUpdate(t *testi parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateFeatureGroup(fx.Context(), &UpdateFeatureGroupRequest{ + _, err := fx.Service().UpdateFeatureGroup(fx.Context(), &UpdateFeatureGroupRequest{ FeatureGroup: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -627,7 +631,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testUpdate(t *testi parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateFeatureGroup(fx.Context(), &UpdateFeatureGroupRequest{ + _, err := fx.Service().UpdateFeatureGroup(fx.Context(), &UpdateFeatureGroupRequest{ FeatureGroup: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -640,7 +644,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testUpdate(t *testi fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateFeatureGroup(fx.Context(), &UpdateFeatureGroupRequest{ + _, err := fx.Service().UpdateFeatureGroup(fx.Context(), &UpdateFeatureGroupRequest{ FeatureGroup: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -649,7 +653,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testUpdate(t *testi // 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.UpdateFeatureGroup(fx.Context(), &UpdateFeatureGroupRequest{ + _, err := fx.Service().UpdateFeatureGroup(fx.Context(), &UpdateFeatureGroupRequest{ FeatureGroup: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -673,7 +677,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testUpdate(t *testi } fd := container.ProtoReflect().Descriptor().Fields().ByName("input_uri") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateFeatureGroup(fx.Context(), &UpdateFeatureGroupRequest{ + _, err := fx.Service().UpdateFeatureGroup(fx.Context(), &UpdateFeatureGroupRequest{ FeatureGroup: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -692,7 +696,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testList(t *testing // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListFeatureGroups(fx.Context(), &ListFeatureGroupsRequest{ + _, err := fx.Service().ListFeatureGroups(fx.Context(), &ListFeatureGroupsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -702,7 +706,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testList(t *testing t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListFeatureGroups(fx.Context(), &ListFeatureGroupsRequest{ + _, err := fx.Service().ListFeatureGroups(fx.Context(), &ListFeatureGroupsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -713,7 +717,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testList(t *testing t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListFeatureGroups(fx.Context(), &ListFeatureGroupsRequest{ + _, err := fx.Service().ListFeatureGroups(fx.Context(), &ListFeatureGroupsRequest{ Parent: parent, PageSize: -10, }) @@ -731,7 +735,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testList(t *testing // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListFeatureGroups(fx.Context(), &ListFeatureGroupsRequest{ + response, err := fx.Service().ListFeatureGroups(fx.Context(), &ListFeatureGroupsRequest{ Parent: parent, PageSize: 999, }) @@ -750,7 +754,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testList(t *testing // 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.ListFeatureGroups(fx.Context(), &ListFeatureGroupsRequest{ + response, err := fx.Service().ListFeatureGroups(fx.Context(), &ListFeatureGroupsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -761,7 +765,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testList(t *testing // 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.ListFeatureGroups(fx.Context(), &ListFeatureGroupsRequest{ + response, err := fx.Service().ListFeatureGroups(fx.Context(), &ListFeatureGroupsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -775,7 +779,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testList(t *testing msgs := make([]*FeatureGroup, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListFeatureGroups(fx.Context(), &ListFeatureGroupsRequest{ + response, err := fx.Service().ListFeatureGroups(fx.Context(), &ListFeatureGroupsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -804,12 +808,12 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testList(t *testing fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteFeatureGroup(fx.Context(), &DeleteFeatureGroupRequest{ + _, err := fx.Service().DeleteFeatureGroup(fx.Context(), &DeleteFeatureGroupRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListFeatureGroups(fx.Context(), &ListFeatureGroupsRequest{ + response, err := fx.Service().ListFeatureGroups(fx.Context(), &ListFeatureGroupsRequest{ Parent: parent, PageSize: 9999, }) @@ -832,7 +836,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testDelete(t *testi // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.DeleteFeatureGroup(fx.Context(), &DeleteFeatureGroupRequest{ + _, err := fx.Service().DeleteFeatureGroup(fx.Context(), &DeleteFeatureGroupRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -841,7 +845,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testDelete(t *testi // 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.DeleteFeatureGroup(fx.Context(), &DeleteFeatureGroupRequest{ + _, err := fx.Service().DeleteFeatureGroup(fx.Context(), &DeleteFeatureGroupRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -852,7 +856,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testDelete(t *testi fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteFeatureGroup(fx.Context(), &DeleteFeatureGroupRequest{ + _, err := fx.Service().DeleteFeatureGroup(fx.Context(), &DeleteFeatureGroupRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -863,7 +867,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testDelete(t *testi fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteFeatureGroup(fx.Context(), &DeleteFeatureGroupRequest{ + _, err := fx.Service().DeleteFeatureGroup(fx.Context(), &DeleteFeatureGroupRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -874,12 +878,12 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testDelete(t *testi fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteFeatureGroup(fx.Context(), &DeleteFeatureGroupRequest{ + deleted, err := fx.Service().DeleteFeatureGroup(fx.Context(), &DeleteFeatureGroupRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteFeatureGroup(fx.Context(), &DeleteFeatureGroupRequest{ + _, err = fx.Service().DeleteFeatureGroup(fx.Context(), &DeleteFeatureGroupRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -888,7 +892,7 @@ func (fx *FeatureRegistryServiceFeatureGroupTestSuiteConfig) testDelete(t *testi // 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.DeleteFeatureGroup(fx.Context(), &DeleteFeatureGroupRequest{ + _, err := fx.Service().DeleteFeatureGroup(fx.Context(), &DeleteFeatureGroupRequest{ Name: "projects/-/locations/-/featureGroups/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) diff --git a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/featurestore_service_aiptest.pb.go b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/featurestore_service_aiptest.pb.go index 8bfd9c9..d7b49fa 100644 --- a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/featurestore_service_aiptest.pb.go +++ b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/featurestore_service_aiptest.pb.go @@ -24,7 +24,7 @@ type FeaturestoreServiceTestSuite struct { func (fx FeaturestoreServiceTestSuite) TestEntityType(ctx context.Context, options FeaturestoreServiceEntityTypeTestSuiteConfig) { fx.T.Run("EntityType", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() FeaturestoreServiceServer { return fx.Server } options.test(t) }) } @@ -32,7 +32,7 @@ func (fx FeaturestoreServiceTestSuite) TestEntityType(ctx context.Context, optio func (fx FeaturestoreServiceTestSuite) TestFeature(ctx context.Context, options FeaturestoreServiceFeatureTestSuiteConfig) { fx.T.Run("Feature", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() FeaturestoreServiceServer { return fx.Server } options.test(t) }) } @@ -40,15 +40,17 @@ func (fx FeaturestoreServiceTestSuite) TestFeature(ctx context.Context, options func (fx FeaturestoreServiceTestSuite) TestFeaturestore(ctx context.Context, options FeaturestoreServiceFeaturestoreTestSuiteConfig) { fx.T.Run("Featurestore", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() FeaturestoreServiceServer { return fx.Server } options.test(t) }) } type FeaturestoreServiceEntityTypeTestSuiteConfig struct { - service FeaturestoreServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() FeaturestoreServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -83,7 +85,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) 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.CreateEntityType(fx.Context(), &CreateEntityTypeRequest{ + _, err := fx.Service().CreateEntityType(fx.Context(), &CreateEntityTypeRequest{ Parent: "", EntityType: fx.Create(fx.nextParent(t, false)), }) @@ -93,7 +95,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) 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.CreateEntityType(fx.Context(), &CreateEntityTypeRequest{ + _, err := fx.Service().CreateEntityType(fx.Context(), &CreateEntityTypeRequest{ Parent: "invalid resource name", EntityType: fx.Create(fx.nextParent(t, false)), }) @@ -107,7 +109,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) 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.GetEntityType(fx.Context(), &GetEntityTypeRequest{ + _, err := fx.Service().GetEntityType(fx.Context(), &GetEntityTypeRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -116,7 +118,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) 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.GetEntityType(fx.Context(), &GetEntityTypeRequest{ + _, err := fx.Service().GetEntityType(fx.Context(), &GetEntityTypeRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -127,7 +129,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetEntityType(fx.Context(), &GetEntityTypeRequest{ + msg, err := fx.Service().GetEntityType(fx.Context(), &GetEntityTypeRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -139,7 +141,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetEntityType(fx.Context(), &GetEntityTypeRequest{ + _, err := fx.Service().GetEntityType(fx.Context(), &GetEntityTypeRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -148,7 +150,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) 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.GetEntityType(fx.Context(), &GetEntityTypeRequest{ + _, err := fx.Service().GetEntityType(fx.Context(), &GetEntityTypeRequest{ Name: "projects/-/locations/-/featurestores/-/entityTypes/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -164,7 +166,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) testUpdate(t *testing.T) parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateEntityType(fx.Context(), &UpdateEntityTypeRequest{ + _, err := fx.Service().UpdateEntityType(fx.Context(), &UpdateEntityTypeRequest{ EntityType: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -176,7 +178,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) testUpdate(t *testing.T) parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateEntityType(fx.Context(), &UpdateEntityTypeRequest{ + _, err := fx.Service().UpdateEntityType(fx.Context(), &UpdateEntityTypeRequest{ EntityType: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -187,11 +189,11 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) testUpdate(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateEntityType(fx.Context(), &UpdateEntityTypeRequest{ + updated, err := fx.Service().UpdateEntityType(fx.Context(), &UpdateEntityTypeRequest{ EntityType: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetEntityType(fx.Context(), &GetEntityTypeRequest{ + persisted, err := fx.Service().GetEntityType(fx.Context(), &GetEntityTypeRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -205,7 +207,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) testUpdate(t *testing.T) fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateEntityType(fx.Context(), &UpdateEntityTypeRequest{ + _, err := fx.Service().UpdateEntityType(fx.Context(), &UpdateEntityTypeRequest{ EntityType: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -214,7 +216,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) 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.UpdateEntityType(fx.Context(), &UpdateEntityTypeRequest{ + _, err := fx.Service().UpdateEntityType(fx.Context(), &UpdateEntityTypeRequest{ EntityType: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -232,7 +234,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) 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.ListEntityTypes(fx.Context(), &ListEntityTypesRequest{ + _, err := fx.Service().ListEntityTypes(fx.Context(), &ListEntityTypesRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -242,7 +244,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListEntityTypes(fx.Context(), &ListEntityTypesRequest{ + _, err := fx.Service().ListEntityTypes(fx.Context(), &ListEntityTypesRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -253,7 +255,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListEntityTypes(fx.Context(), &ListEntityTypesRequest{ + _, err := fx.Service().ListEntityTypes(fx.Context(), &ListEntityTypesRequest{ Parent: parent, PageSize: -10, }) @@ -271,7 +273,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListEntityTypes(fx.Context(), &ListEntityTypesRequest{ + response, err := fx.Service().ListEntityTypes(fx.Context(), &ListEntityTypesRequest{ Parent: parent, PageSize: 999, }) @@ -290,7 +292,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) 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.ListEntityTypes(fx.Context(), &ListEntityTypesRequest{ + response, err := fx.Service().ListEntityTypes(fx.Context(), &ListEntityTypesRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -301,7 +303,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) 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.ListEntityTypes(fx.Context(), &ListEntityTypesRequest{ + response, err := fx.Service().ListEntityTypes(fx.Context(), &ListEntityTypesRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -315,7 +317,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) testList(t *testing.T) { msgs := make([]*EntityType, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListEntityTypes(fx.Context(), &ListEntityTypesRequest{ + response, err := fx.Service().ListEntityTypes(fx.Context(), &ListEntityTypesRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -344,12 +346,12 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteEntityType(fx.Context(), &DeleteEntityTypeRequest{ + _, err := fx.Service().DeleteEntityType(fx.Context(), &DeleteEntityTypeRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListEntityTypes(fx.Context(), &ListEntityTypesRequest{ + response, err := fx.Service().ListEntityTypes(fx.Context(), &ListEntityTypesRequest{ Parent: parent, PageSize: 9999, }) @@ -372,7 +374,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) testDelete(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.DeleteEntityType(fx.Context(), &DeleteEntityTypeRequest{ + _, err := fx.Service().DeleteEntityType(fx.Context(), &DeleteEntityTypeRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -381,7 +383,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) testDelete(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.DeleteEntityType(fx.Context(), &DeleteEntityTypeRequest{ + _, err := fx.Service().DeleteEntityType(fx.Context(), &DeleteEntityTypeRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -392,7 +394,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteEntityType(fx.Context(), &DeleteEntityTypeRequest{ + _, err := fx.Service().DeleteEntityType(fx.Context(), &DeleteEntityTypeRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -403,7 +405,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteEntityType(fx.Context(), &DeleteEntityTypeRequest{ + _, err := fx.Service().DeleteEntityType(fx.Context(), &DeleteEntityTypeRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -414,12 +416,12 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteEntityType(fx.Context(), &DeleteEntityTypeRequest{ + deleted, err := fx.Service().DeleteEntityType(fx.Context(), &DeleteEntityTypeRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteEntityType(fx.Context(), &DeleteEntityTypeRequest{ + _, err = fx.Service().DeleteEntityType(fx.Context(), &DeleteEntityTypeRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -428,7 +430,7 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) testDelete(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.DeleteEntityType(fx.Context(), &DeleteEntityTypeRequest{ + _, err := fx.Service().DeleteEntityType(fx.Context(), &DeleteEntityTypeRequest{ Name: "projects/-/locations/-/featurestores/-/entityTypes/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -469,9 +471,11 @@ func (fx *FeaturestoreServiceEntityTypeTestSuiteConfig) create(t *testing.T, par } type FeaturestoreServiceFeatureTestSuiteConfig struct { - service FeaturestoreServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() FeaturestoreServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -514,7 +518,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testCreate(t *testing.T) { if fx.IDGenerator != nil { userSetID = fx.IDGenerator() } - _, err := fx.service.CreateFeature(fx.Context(), &CreateFeatureRequest{ + _, err := fx.Service().CreateFeature(fx.Context(), &CreateFeatureRequest{ Parent: "", Feature: fx.Create(fx.nextParent(t, false)), FeatureId: userSetID, @@ -529,7 +533,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testCreate(t *testing.T) { if fx.IDGenerator != nil { userSetID = fx.IDGenerator() } - _, err := fx.service.CreateFeature(fx.Context(), &CreateFeatureRequest{ + _, err := fx.Service().CreateFeature(fx.Context(), &CreateFeatureRequest{ Parent: "invalid resource name", Feature: fx.Create(fx.nextParent(t, false)), FeatureId: userSetID, @@ -544,7 +548,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) 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.GetFeature(fx.Context(), &GetFeatureRequest{ + _, err := fx.Service().GetFeature(fx.Context(), &GetFeatureRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -553,7 +557,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) 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.GetFeature(fx.Context(), &GetFeatureRequest{ + _, err := fx.Service().GetFeature(fx.Context(), &GetFeatureRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -564,7 +568,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetFeature(fx.Context(), &GetFeatureRequest{ + msg, err := fx.Service().GetFeature(fx.Context(), &GetFeatureRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -576,7 +580,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetFeature(fx.Context(), &GetFeatureRequest{ + _, err := fx.Service().GetFeature(fx.Context(), &GetFeatureRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -585,7 +589,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) 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.GetFeature(fx.Context(), &GetFeatureRequest{ + _, err := fx.Service().GetFeature(fx.Context(), &GetFeatureRequest{ Name: "projects/-/locations/-/featurestores/-/entityTypes/-/features/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -601,7 +605,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateFeature(fx.Context(), &UpdateFeatureRequest{ + _, err := fx.Service().UpdateFeature(fx.Context(), &UpdateFeatureRequest{ Feature: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -613,7 +617,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateFeature(fx.Context(), &UpdateFeatureRequest{ + _, err := fx.Service().UpdateFeature(fx.Context(), &UpdateFeatureRequest{ Feature: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -624,11 +628,11 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateFeature(fx.Context(), &UpdateFeatureRequest{ + updated, err := fx.Service().UpdateFeature(fx.Context(), &UpdateFeatureRequest{ Feature: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetFeature(fx.Context(), &GetFeatureRequest{ + persisted, err := fx.Service().GetFeature(fx.Context(), &GetFeatureRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -642,7 +646,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateFeature(fx.Context(), &UpdateFeatureRequest{ + _, err := fx.Service().UpdateFeature(fx.Context(), &UpdateFeatureRequest{ Feature: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -651,7 +655,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) 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.UpdateFeature(fx.Context(), &UpdateFeatureRequest{ + _, err := fx.Service().UpdateFeature(fx.Context(), &UpdateFeatureRequest{ Feature: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -669,7 +673,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) 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.ListFeatures(fx.Context(), &ListFeaturesRequest{ + _, err := fx.Service().ListFeatures(fx.Context(), &ListFeaturesRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -679,7 +683,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListFeatures(fx.Context(), &ListFeaturesRequest{ + _, err := fx.Service().ListFeatures(fx.Context(), &ListFeaturesRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -690,7 +694,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListFeatures(fx.Context(), &ListFeaturesRequest{ + _, err := fx.Service().ListFeatures(fx.Context(), &ListFeaturesRequest{ Parent: parent, PageSize: -10, }) @@ -708,7 +712,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListFeatures(fx.Context(), &ListFeaturesRequest{ + response, err := fx.Service().ListFeatures(fx.Context(), &ListFeaturesRequest{ Parent: parent, PageSize: 999, }) @@ -727,7 +731,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) 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.ListFeatures(fx.Context(), &ListFeaturesRequest{ + response, err := fx.Service().ListFeatures(fx.Context(), &ListFeaturesRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -738,7 +742,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) 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.ListFeatures(fx.Context(), &ListFeaturesRequest{ + response, err := fx.Service().ListFeatures(fx.Context(), &ListFeaturesRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -752,7 +756,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Feature, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListFeatures(fx.Context(), &ListFeaturesRequest{ + response, err := fx.Service().ListFeatures(fx.Context(), &ListFeaturesRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -781,12 +785,12 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteFeature(fx.Context(), &DeleteFeatureRequest{ + _, err := fx.Service().DeleteFeature(fx.Context(), &DeleteFeatureRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListFeatures(fx.Context(), &ListFeaturesRequest{ + response, err := fx.Service().ListFeatures(fx.Context(), &ListFeaturesRequest{ Parent: parent, PageSize: 9999, }) @@ -809,7 +813,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testDelete(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.DeleteFeature(fx.Context(), &DeleteFeatureRequest{ + _, err := fx.Service().DeleteFeature(fx.Context(), &DeleteFeatureRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -818,7 +822,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testDelete(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.DeleteFeature(fx.Context(), &DeleteFeatureRequest{ + _, err := fx.Service().DeleteFeature(fx.Context(), &DeleteFeatureRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -829,7 +833,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteFeature(fx.Context(), &DeleteFeatureRequest{ + _, err := fx.Service().DeleteFeature(fx.Context(), &DeleteFeatureRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -840,7 +844,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteFeature(fx.Context(), &DeleteFeatureRequest{ + _, err := fx.Service().DeleteFeature(fx.Context(), &DeleteFeatureRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -851,12 +855,12 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteFeature(fx.Context(), &DeleteFeatureRequest{ + deleted, err := fx.Service().DeleteFeature(fx.Context(), &DeleteFeatureRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteFeature(fx.Context(), &DeleteFeatureRequest{ + _, err = fx.Service().DeleteFeature(fx.Context(), &DeleteFeatureRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -865,7 +869,7 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) testDelete(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.DeleteFeature(fx.Context(), &DeleteFeatureRequest{ + _, err := fx.Service().DeleteFeature(fx.Context(), &DeleteFeatureRequest{ Name: "projects/-/locations/-/featurestores/-/entityTypes/-/features/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -906,9 +910,11 @@ func (fx *FeaturestoreServiceFeatureTestSuiteConfig) create(t *testing.T, parent } type FeaturestoreServiceFeaturestoreTestSuiteConfig struct { - service FeaturestoreServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() FeaturestoreServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -943,7 +949,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testCreate(t *testing. // Method should fail with InvalidArgument if no parent is provided. t.Run("missing parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateFeaturestore(fx.Context(), &CreateFeaturestoreRequest{ + _, err := fx.Service().CreateFeaturestore(fx.Context(), &CreateFeaturestoreRequest{ Parent: "", Featurestore: fx.Create(fx.nextParent(t, false)), }) @@ -953,7 +959,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testCreate(t *testing. // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateFeaturestore(fx.Context(), &CreateFeaturestoreRequest{ + _, err := fx.Service().CreateFeaturestore(fx.Context(), &CreateFeaturestoreRequest{ Parent: "invalid resource name", Featurestore: fx.Create(fx.nextParent(t, false)), }) @@ -974,7 +980,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("min_node_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateFeaturestore(fx.Context(), &CreateFeaturestoreRequest{ + _, err := fx.Service().CreateFeaturestore(fx.Context(), &CreateFeaturestoreRequest{ Parent: parent, Featurestore: msg, }) @@ -990,7 +996,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateFeaturestore(fx.Context(), &CreateFeaturestoreRequest{ + _, err := fx.Service().CreateFeaturestore(fx.Context(), &CreateFeaturestoreRequest{ Parent: parent, Featurestore: msg, }) @@ -1005,7 +1011,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) 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.GetFeaturestore(fx.Context(), &GetFeaturestoreRequest{ + _, err := fx.Service().GetFeaturestore(fx.Context(), &GetFeaturestoreRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1014,7 +1020,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) 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.GetFeaturestore(fx.Context(), &GetFeaturestoreRequest{ + _, err := fx.Service().GetFeaturestore(fx.Context(), &GetFeaturestoreRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1025,7 +1031,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testGet(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetFeaturestore(fx.Context(), &GetFeaturestoreRequest{ + msg, err := fx.Service().GetFeaturestore(fx.Context(), &GetFeaturestoreRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1037,7 +1043,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testGet(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetFeaturestore(fx.Context(), &GetFeaturestoreRequest{ + _, err := fx.Service().GetFeaturestore(fx.Context(), &GetFeaturestoreRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1046,7 +1052,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) 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.GetFeaturestore(fx.Context(), &GetFeaturestoreRequest{ + _, err := fx.Service().GetFeaturestore(fx.Context(), &GetFeaturestoreRequest{ Name: "projects/-/locations/-/featurestores/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1062,7 +1068,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testUpdate(t *testing. parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateFeaturestore(fx.Context(), &UpdateFeaturestoreRequest{ + _, err := fx.Service().UpdateFeaturestore(fx.Context(), &UpdateFeaturestoreRequest{ Featurestore: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1074,7 +1080,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testUpdate(t *testing. parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateFeaturestore(fx.Context(), &UpdateFeaturestoreRequest{ + _, err := fx.Service().UpdateFeaturestore(fx.Context(), &UpdateFeaturestoreRequest{ Featurestore: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1087,7 +1093,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testUpdate(t *testing. fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateFeaturestore(fx.Context(), &UpdateFeaturestoreRequest{ + _, err := fx.Service().UpdateFeaturestore(fx.Context(), &UpdateFeaturestoreRequest{ Featurestore: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1096,7 +1102,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testUpdate(t *testing. // 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.UpdateFeaturestore(fx.Context(), &UpdateFeaturestoreRequest{ + _, err := fx.Service().UpdateFeaturestore(fx.Context(), &UpdateFeaturestoreRequest{ Featurestore: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -1120,7 +1126,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testUpdate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("min_node_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateFeaturestore(fx.Context(), &UpdateFeaturestoreRequest{ + _, err := fx.Service().UpdateFeaturestore(fx.Context(), &UpdateFeaturestoreRequest{ Featurestore: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -1139,7 +1145,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testUpdate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateFeaturestore(fx.Context(), &UpdateFeaturestoreRequest{ + _, err := fx.Service().UpdateFeaturestore(fx.Context(), &UpdateFeaturestoreRequest{ Featurestore: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -1158,7 +1164,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) 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.ListFeaturestores(fx.Context(), &ListFeaturestoresRequest{ + _, err := fx.Service().ListFeaturestores(fx.Context(), &ListFeaturestoresRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1168,7 +1174,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testList(t *testing.T) t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListFeaturestores(fx.Context(), &ListFeaturestoresRequest{ + _, err := fx.Service().ListFeaturestores(fx.Context(), &ListFeaturestoresRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -1179,7 +1185,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testList(t *testing.T) t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListFeaturestores(fx.Context(), &ListFeaturestoresRequest{ + _, err := fx.Service().ListFeaturestores(fx.Context(), &ListFeaturestoresRequest{ Parent: parent, PageSize: -10, }) @@ -1197,7 +1203,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testList(t *testing.T) // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListFeaturestores(fx.Context(), &ListFeaturestoresRequest{ + response, err := fx.Service().ListFeaturestores(fx.Context(), &ListFeaturestoresRequest{ Parent: parent, PageSize: 999, }) @@ -1216,7 +1222,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) 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.ListFeaturestores(fx.Context(), &ListFeaturestoresRequest{ + response, err := fx.Service().ListFeaturestores(fx.Context(), &ListFeaturestoresRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -1227,7 +1233,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) 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.ListFeaturestores(fx.Context(), &ListFeaturestoresRequest{ + response, err := fx.Service().ListFeaturestores(fx.Context(), &ListFeaturestoresRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -1241,7 +1247,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testList(t *testing.T) msgs := make([]*Featurestore, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListFeaturestores(fx.Context(), &ListFeaturestoresRequest{ + response, err := fx.Service().ListFeaturestores(fx.Context(), &ListFeaturestoresRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -1270,12 +1276,12 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testList(t *testing.T) fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteFeaturestore(fx.Context(), &DeleteFeaturestoreRequest{ + _, err := fx.Service().DeleteFeaturestore(fx.Context(), &DeleteFeaturestoreRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListFeaturestores(fx.Context(), &ListFeaturestoresRequest{ + response, err := fx.Service().ListFeaturestores(fx.Context(), &ListFeaturestoresRequest{ Parent: parent, PageSize: 9999, }) @@ -1298,7 +1304,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testDelete(t *testing. // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.DeleteFeaturestore(fx.Context(), &DeleteFeaturestoreRequest{ + _, err := fx.Service().DeleteFeaturestore(fx.Context(), &DeleteFeaturestoreRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1307,7 +1313,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testDelete(t *testing. // 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.DeleteFeaturestore(fx.Context(), &DeleteFeaturestoreRequest{ + _, err := fx.Service().DeleteFeaturestore(fx.Context(), &DeleteFeaturestoreRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1318,7 +1324,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testDelete(t *testing. fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteFeaturestore(fx.Context(), &DeleteFeaturestoreRequest{ + _, err := fx.Service().DeleteFeaturestore(fx.Context(), &DeleteFeaturestoreRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1329,7 +1335,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testDelete(t *testing. fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteFeaturestore(fx.Context(), &DeleteFeaturestoreRequest{ + _, err := fx.Service().DeleteFeaturestore(fx.Context(), &DeleteFeaturestoreRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1340,12 +1346,12 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testDelete(t *testing. fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteFeaturestore(fx.Context(), &DeleteFeaturestoreRequest{ + deleted, err := fx.Service().DeleteFeaturestore(fx.Context(), &DeleteFeaturestoreRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteFeaturestore(fx.Context(), &DeleteFeaturestoreRequest{ + _, err = fx.Service().DeleteFeaturestore(fx.Context(), &DeleteFeaturestoreRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1354,7 +1360,7 @@ func (fx *FeaturestoreServiceFeaturestoreTestSuiteConfig) testDelete(t *testing. // 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.DeleteFeaturestore(fx.Context(), &DeleteFeaturestoreRequest{ + _, err := fx.Service().DeleteFeaturestore(fx.Context(), &DeleteFeaturestoreRequest{ Name: "projects/-/locations/-/featurestores/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) diff --git a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/index_endpoint_service_aiptest.pb.go b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/index_endpoint_service_aiptest.pb.go index 89c4ddd..0c1aec1 100644 --- a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/index_endpoint_service_aiptest.pb.go +++ b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/index_endpoint_service_aiptest.pb.go @@ -24,15 +24,17 @@ type IndexEndpointServiceTestSuite struct { func (fx IndexEndpointServiceTestSuite) TestIndexEndpoint(ctx context.Context, options IndexEndpointServiceIndexEndpointTestSuiteConfig) { fx.T.Run("IndexEndpoint", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() IndexEndpointServiceServer { return fx.Server } options.test(t) }) } type IndexEndpointServiceIndexEndpointTestSuiteConfig struct { - service IndexEndpointServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() IndexEndpointServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -67,7 +69,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testCreate(t *testin // Method should fail with InvalidArgument if no parent is provided. t.Run("missing parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateIndexEndpoint(fx.Context(), &CreateIndexEndpointRequest{ + _, err := fx.Service().CreateIndexEndpoint(fx.Context(), &CreateIndexEndpointRequest{ Parent: "", IndexEndpoint: fx.Create(fx.nextParent(t, false)), }) @@ -77,7 +79,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testCreate(t *testin // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateIndexEndpoint(fx.Context(), &CreateIndexEndpointRequest{ + _, err := fx.Service().CreateIndexEndpoint(fx.Context(), &CreateIndexEndpointRequest{ Parent: "invalid resource name", IndexEndpoint: fx.Create(fx.nextParent(t, false)), }) @@ -98,7 +100,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testCreate(t *testin } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateIndexEndpoint(fx.Context(), &CreateIndexEndpointRequest{ + _, err := fx.Service().CreateIndexEndpoint(fx.Context(), &CreateIndexEndpointRequest{ Parent: parent, IndexEndpoint: msg, }) @@ -114,7 +116,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testCreate(t *testin } fd := container.ProtoReflect().Descriptor().Fields().ByName("enable_private_service_connect") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateIndexEndpoint(fx.Context(), &CreateIndexEndpointRequest{ + _, err := fx.Service().CreateIndexEndpoint(fx.Context(), &CreateIndexEndpointRequest{ Parent: parent, IndexEndpoint: msg, }) @@ -130,7 +132,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testCreate(t *testin } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateIndexEndpoint(fx.Context(), &CreateIndexEndpointRequest{ + _, err := fx.Service().CreateIndexEndpoint(fx.Context(), &CreateIndexEndpointRequest{ Parent: parent, IndexEndpoint: msg, }) @@ -145,7 +147,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) 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.GetIndexEndpoint(fx.Context(), &GetIndexEndpointRequest{ + _, err := fx.Service().GetIndexEndpoint(fx.Context(), &GetIndexEndpointRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -154,7 +156,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) 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.GetIndexEndpoint(fx.Context(), &GetIndexEndpointRequest{ + _, err := fx.Service().GetIndexEndpoint(fx.Context(), &GetIndexEndpointRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -165,7 +167,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testGet(t *testing.T fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetIndexEndpoint(fx.Context(), &GetIndexEndpointRequest{ + msg, err := fx.Service().GetIndexEndpoint(fx.Context(), &GetIndexEndpointRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -177,7 +179,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testGet(t *testing.T fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetIndexEndpoint(fx.Context(), &GetIndexEndpointRequest{ + _, err := fx.Service().GetIndexEndpoint(fx.Context(), &GetIndexEndpointRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -186,7 +188,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) 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.GetIndexEndpoint(fx.Context(), &GetIndexEndpointRequest{ + _, err := fx.Service().GetIndexEndpoint(fx.Context(), &GetIndexEndpointRequest{ Name: "projects/-/locations/-/indexEndpoints/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -202,7 +204,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testUpdate(t *testin parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ + _, err := fx.Service().UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ IndexEndpoint: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -214,7 +216,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testUpdate(t *testin parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ + _, err := fx.Service().UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ IndexEndpoint: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -225,11 +227,11 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testUpdate(t *testin fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ + updated, err := fx.Service().UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ IndexEndpoint: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetIndexEndpoint(fx.Context(), &GetIndexEndpointRequest{ + persisted, err := fx.Service().GetIndexEndpoint(fx.Context(), &GetIndexEndpointRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -242,7 +244,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testUpdate(t *testin parent := fx.nextParent(t, false) created := fx.create(t, parent) originalCreateTime := created.CreateTime - updated, err := fx.service.UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ + updated, err := fx.Service().UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ IndexEndpoint: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -261,7 +263,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testUpdate(t *testin fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ + _, err := fx.Service().UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ IndexEndpoint: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -270,7 +272,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testUpdate(t *testin // 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.UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ + _, err := fx.Service().UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ IndexEndpoint: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -294,7 +296,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testUpdate(t *testin } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ + _, err := fx.Service().UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ IndexEndpoint: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -313,7 +315,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testUpdate(t *testin } fd := container.ProtoReflect().Descriptor().Fields().ByName("enable_private_service_connect") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ + _, err := fx.Service().UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ IndexEndpoint: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -332,7 +334,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testUpdate(t *testin } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ + _, err := fx.Service().UpdateIndexEndpoint(fx.Context(), &UpdateIndexEndpointRequest{ IndexEndpoint: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -351,7 +353,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testList(t *testing. // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListIndexEndpoints(fx.Context(), &ListIndexEndpointsRequest{ + _, err := fx.Service().ListIndexEndpoints(fx.Context(), &ListIndexEndpointsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -361,7 +363,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testList(t *testing. t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListIndexEndpoints(fx.Context(), &ListIndexEndpointsRequest{ + _, err := fx.Service().ListIndexEndpoints(fx.Context(), &ListIndexEndpointsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -372,7 +374,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testList(t *testing. t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListIndexEndpoints(fx.Context(), &ListIndexEndpointsRequest{ + _, err := fx.Service().ListIndexEndpoints(fx.Context(), &ListIndexEndpointsRequest{ Parent: parent, PageSize: -10, }) @@ -390,7 +392,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testList(t *testing. // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListIndexEndpoints(fx.Context(), &ListIndexEndpointsRequest{ + response, err := fx.Service().ListIndexEndpoints(fx.Context(), &ListIndexEndpointsRequest{ Parent: parent, PageSize: 999, }) @@ -409,7 +411,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testList(t *testing. // 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.ListIndexEndpoints(fx.Context(), &ListIndexEndpointsRequest{ + response, err := fx.Service().ListIndexEndpoints(fx.Context(), &ListIndexEndpointsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -420,7 +422,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testList(t *testing. // 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.ListIndexEndpoints(fx.Context(), &ListIndexEndpointsRequest{ + response, err := fx.Service().ListIndexEndpoints(fx.Context(), &ListIndexEndpointsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -434,7 +436,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testList(t *testing. msgs := make([]*IndexEndpoint, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListIndexEndpoints(fx.Context(), &ListIndexEndpointsRequest{ + response, err := fx.Service().ListIndexEndpoints(fx.Context(), &ListIndexEndpointsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -463,12 +465,12 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testList(t *testing. fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteIndexEndpoint(fx.Context(), &DeleteIndexEndpointRequest{ + _, err := fx.Service().DeleteIndexEndpoint(fx.Context(), &DeleteIndexEndpointRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListIndexEndpoints(fx.Context(), &ListIndexEndpointsRequest{ + response, err := fx.Service().ListIndexEndpoints(fx.Context(), &ListIndexEndpointsRequest{ Parent: parent, PageSize: 9999, }) @@ -491,7 +493,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testDelete(t *testin // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.DeleteIndexEndpoint(fx.Context(), &DeleteIndexEndpointRequest{ + _, err := fx.Service().DeleteIndexEndpoint(fx.Context(), &DeleteIndexEndpointRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -500,7 +502,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testDelete(t *testin // 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.DeleteIndexEndpoint(fx.Context(), &DeleteIndexEndpointRequest{ + _, err := fx.Service().DeleteIndexEndpoint(fx.Context(), &DeleteIndexEndpointRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -511,7 +513,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testDelete(t *testin fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteIndexEndpoint(fx.Context(), &DeleteIndexEndpointRequest{ + _, err := fx.Service().DeleteIndexEndpoint(fx.Context(), &DeleteIndexEndpointRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -522,7 +524,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testDelete(t *testin fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteIndexEndpoint(fx.Context(), &DeleteIndexEndpointRequest{ + _, err := fx.Service().DeleteIndexEndpoint(fx.Context(), &DeleteIndexEndpointRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -533,12 +535,12 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testDelete(t *testin fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteIndexEndpoint(fx.Context(), &DeleteIndexEndpointRequest{ + deleted, err := fx.Service().DeleteIndexEndpoint(fx.Context(), &DeleteIndexEndpointRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteIndexEndpoint(fx.Context(), &DeleteIndexEndpointRequest{ + _, err = fx.Service().DeleteIndexEndpoint(fx.Context(), &DeleteIndexEndpointRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -547,7 +549,7 @@ func (fx *IndexEndpointServiceIndexEndpointTestSuiteConfig) testDelete(t *testin // 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.DeleteIndexEndpoint(fx.Context(), &DeleteIndexEndpointRequest{ + _, err := fx.Service().DeleteIndexEndpoint(fx.Context(), &DeleteIndexEndpointRequest{ Name: "projects/-/locations/-/indexEndpoints/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) diff --git a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/index_service_aiptest.pb.go b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/index_service_aiptest.pb.go index c4f6012..d16ad79 100644 --- a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/index_service_aiptest.pb.go +++ b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/index_service_aiptest.pb.go @@ -24,15 +24,17 @@ type IndexServiceTestSuite struct { func (fx IndexServiceTestSuite) TestIndex(ctx context.Context, options IndexServiceIndexTestSuiteConfig) { fx.T.Run("Index", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() IndexServiceServer { return fx.Server } options.test(t) }) } type IndexServiceIndexTestSuiteConfig struct { - service IndexServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() IndexServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -67,7 +69,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) 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.CreateIndex(fx.Context(), &CreateIndexRequest{ + _, err := fx.Service().CreateIndex(fx.Context(), &CreateIndexRequest{ Parent: "", Index: fx.Create(fx.nextParent(t, false)), }) @@ -77,7 +79,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) 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.CreateIndex(fx.Context(), &CreateIndexRequest{ + _, err := fx.Service().CreateIndex(fx.Context(), &CreateIndexRequest{ Parent: "invalid resource name", Index: fx.Create(fx.nextParent(t, false)), }) @@ -98,7 +100,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateIndex(fx.Context(), &CreateIndexRequest{ + _, err := fx.Service().CreateIndex(fx.Context(), &CreateIndexRequest{ Parent: parent, Index: msg, }) @@ -114,7 +116,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateIndex(fx.Context(), &CreateIndexRequest{ + _, err := fx.Service().CreateIndex(fx.Context(), &CreateIndexRequest{ Parent: parent, Index: msg, }) @@ -129,7 +131,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) 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.GetIndex(fx.Context(), &GetIndexRequest{ + _, err := fx.Service().GetIndex(fx.Context(), &GetIndexRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -138,7 +140,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) 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.GetIndex(fx.Context(), &GetIndexRequest{ + _, err := fx.Service().GetIndex(fx.Context(), &GetIndexRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -149,7 +151,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetIndex(fx.Context(), &GetIndexRequest{ + msg, err := fx.Service().GetIndex(fx.Context(), &GetIndexRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -161,7 +163,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetIndex(fx.Context(), &GetIndexRequest{ + _, err := fx.Service().GetIndex(fx.Context(), &GetIndexRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -170,7 +172,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) 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.GetIndex(fx.Context(), &GetIndexRequest{ + _, err := fx.Service().GetIndex(fx.Context(), &GetIndexRequest{ Name: "projects/-/locations/-/indexes/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -186,7 +188,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateIndex(fx.Context(), &UpdateIndexRequest{ + _, err := fx.Service().UpdateIndex(fx.Context(), &UpdateIndexRequest{ Index: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -198,7 +200,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateIndex(fx.Context(), &UpdateIndexRequest{ + _, err := fx.Service().UpdateIndex(fx.Context(), &UpdateIndexRequest{ Index: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -211,7 +213,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateIndex(fx.Context(), &UpdateIndexRequest{ + _, err := fx.Service().UpdateIndex(fx.Context(), &UpdateIndexRequest{ Index: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -220,7 +222,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) 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.UpdateIndex(fx.Context(), &UpdateIndexRequest{ + _, err := fx.Service().UpdateIndex(fx.Context(), &UpdateIndexRequest{ Index: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -244,7 +246,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateIndex(fx.Context(), &UpdateIndexRequest{ + _, err := fx.Service().UpdateIndex(fx.Context(), &UpdateIndexRequest{ Index: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -263,7 +265,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateIndex(fx.Context(), &UpdateIndexRequest{ + _, err := fx.Service().UpdateIndex(fx.Context(), &UpdateIndexRequest{ Index: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -282,7 +284,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) 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.ListIndexes(fx.Context(), &ListIndexesRequest{ + _, err := fx.Service().ListIndexes(fx.Context(), &ListIndexesRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -292,7 +294,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListIndexes(fx.Context(), &ListIndexesRequest{ + _, err := fx.Service().ListIndexes(fx.Context(), &ListIndexesRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -303,7 +305,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListIndexes(fx.Context(), &ListIndexesRequest{ + _, err := fx.Service().ListIndexes(fx.Context(), &ListIndexesRequest{ Parent: parent, PageSize: -10, }) @@ -321,7 +323,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListIndexes(fx.Context(), &ListIndexesRequest{ + response, err := fx.Service().ListIndexes(fx.Context(), &ListIndexesRequest{ Parent: parent, PageSize: 999, }) @@ -340,7 +342,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) 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.ListIndexes(fx.Context(), &ListIndexesRequest{ + response, err := fx.Service().ListIndexes(fx.Context(), &ListIndexesRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -351,7 +353,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) 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.ListIndexes(fx.Context(), &ListIndexesRequest{ + response, err := fx.Service().ListIndexes(fx.Context(), &ListIndexesRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -365,7 +367,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Index, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListIndexes(fx.Context(), &ListIndexesRequest{ + response, err := fx.Service().ListIndexes(fx.Context(), &ListIndexesRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -394,12 +396,12 @@ func (fx *IndexServiceIndexTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteIndex(fx.Context(), &DeleteIndexRequest{ + _, err := fx.Service().DeleteIndex(fx.Context(), &DeleteIndexRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListIndexes(fx.Context(), &ListIndexesRequest{ + response, err := fx.Service().ListIndexes(fx.Context(), &ListIndexesRequest{ Parent: parent, PageSize: 9999, }) @@ -422,7 +424,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testDelete(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.DeleteIndex(fx.Context(), &DeleteIndexRequest{ + _, err := fx.Service().DeleteIndex(fx.Context(), &DeleteIndexRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -431,7 +433,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testDelete(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.DeleteIndex(fx.Context(), &DeleteIndexRequest{ + _, err := fx.Service().DeleteIndex(fx.Context(), &DeleteIndexRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -442,7 +444,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteIndex(fx.Context(), &DeleteIndexRequest{ + _, err := fx.Service().DeleteIndex(fx.Context(), &DeleteIndexRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -453,7 +455,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteIndex(fx.Context(), &DeleteIndexRequest{ + _, err := fx.Service().DeleteIndex(fx.Context(), &DeleteIndexRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -464,12 +466,12 @@ func (fx *IndexServiceIndexTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteIndex(fx.Context(), &DeleteIndexRequest{ + deleted, err := fx.Service().DeleteIndex(fx.Context(), &DeleteIndexRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteIndex(fx.Context(), &DeleteIndexRequest{ + _, err = fx.Service().DeleteIndex(fx.Context(), &DeleteIndexRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -478,7 +480,7 @@ func (fx *IndexServiceIndexTestSuiteConfig) testDelete(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.DeleteIndex(fx.Context(), &DeleteIndexRequest{ + _, err := fx.Service().DeleteIndex(fx.Context(), &DeleteIndexRequest{ Name: "projects/-/locations/-/indexes/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) diff --git a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/job_service_aiptest.pb.go b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/job_service_aiptest.pb.go index 87954c5..e149a15 100644 --- a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/job_service_aiptest.pb.go +++ b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/job_service_aiptest.pb.go @@ -25,7 +25,7 @@ type JobServiceTestSuite struct { func (fx JobServiceTestSuite) TestBatchPredictionJob(ctx context.Context, options JobServiceBatchPredictionJobTestSuiteConfig) { fx.T.Run("BatchPredictionJob", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() JobServiceServer { return fx.Server } options.test(t) }) } @@ -33,7 +33,7 @@ func (fx JobServiceTestSuite) TestBatchPredictionJob(ctx context.Context, option func (fx JobServiceTestSuite) TestCustomJob(ctx context.Context, options JobServiceCustomJobTestSuiteConfig) { fx.T.Run("CustomJob", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() JobServiceServer { return fx.Server } options.test(t) }) } @@ -41,7 +41,7 @@ func (fx JobServiceTestSuite) TestCustomJob(ctx context.Context, options JobServ func (fx JobServiceTestSuite) TestDataLabelingJob(ctx context.Context, options JobServiceDataLabelingJobTestSuiteConfig) { fx.T.Run("DataLabelingJob", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() JobServiceServer { return fx.Server } options.test(t) }) } @@ -49,7 +49,7 @@ func (fx JobServiceTestSuite) TestDataLabelingJob(ctx context.Context, options J func (fx JobServiceTestSuite) TestHyperparameterTuningJob(ctx context.Context, options JobServiceHyperparameterTuningJobTestSuiteConfig) { fx.T.Run("HyperparameterTuningJob", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() JobServiceServer { return fx.Server } options.test(t) }) } @@ -57,7 +57,7 @@ func (fx JobServiceTestSuite) TestHyperparameterTuningJob(ctx context.Context, o func (fx JobServiceTestSuite) TestModelDeploymentMonitoringJob(ctx context.Context, options JobServiceModelDeploymentMonitoringJobTestSuiteConfig) { fx.T.Run("ModelDeploymentMonitoringJob", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() JobServiceServer { return fx.Server } options.test(t) }) } @@ -65,7 +65,7 @@ func (fx JobServiceTestSuite) TestModelDeploymentMonitoringJob(ctx context.Conte func (fx JobServiceTestSuite) TestNasJob(ctx context.Context, options JobServiceNasJobTestSuiteConfig) { fx.T.Run("NasJob", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() JobServiceServer { return fx.Server } options.test(t) }) } @@ -73,15 +73,17 @@ func (fx JobServiceTestSuite) TestNasJob(ctx context.Context, options JobService func (fx JobServiceTestSuite) TestNasTrialDetail(ctx context.Context, options JobServiceNasTrialDetailTestSuiteConfig) { fx.T.Run("NasTrialDetail", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() JobServiceServer { return fx.Server } options.test(t) }) } type JobServiceBatchPredictionJobTestSuiteConfig struct { - service JobServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() JobServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -112,7 +114,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) 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.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: "", BatchPredictionJob: fx.Create(fx.nextParent(t, false)), }) @@ -122,7 +124,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) 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.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: "invalid resource name", BatchPredictionJob: fx.Create(fx.nextParent(t, false)), }) @@ -134,7 +136,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + msg, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: fx.Create(parent), }) @@ -148,12 +150,12 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + msg, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetBatchPredictionJob(fx.Context(), &GetBatchPredictionJobRequest{ + persisted, err := fx.Service().GetBatchPredictionJob(fx.Context(), &GetBatchPredictionJobRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -174,7 +176,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -190,7 +192,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("image_uri") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -206,7 +208,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("input_config") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -222,7 +224,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("uris") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -238,7 +240,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("input_uri") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -254,7 +256,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("instances_format") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -270,7 +272,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("output_config") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -286,7 +288,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("output_uri_prefix") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -302,7 +304,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("output_uri") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -318,7 +320,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("predictions_format") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -334,7 +336,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("machine_spec") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -350,7 +352,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("parameters") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -366,7 +368,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("path_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -382,7 +384,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("step_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -398,7 +400,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("step_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -414,7 +416,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("inputs") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -430,7 +432,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("outputs") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -446,7 +448,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -467,7 +469,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testCreate(t *testing.T) t.Skip("not reachable") } container.Model = "invalid resource name" - _, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + _, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: msg, }) @@ -482,7 +484,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) 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.GetBatchPredictionJob(fx.Context(), &GetBatchPredictionJobRequest{ + _, err := fx.Service().GetBatchPredictionJob(fx.Context(), &GetBatchPredictionJobRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -491,7 +493,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) 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.GetBatchPredictionJob(fx.Context(), &GetBatchPredictionJobRequest{ + _, err := fx.Service().GetBatchPredictionJob(fx.Context(), &GetBatchPredictionJobRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -502,7 +504,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetBatchPredictionJob(fx.Context(), &GetBatchPredictionJobRequest{ + msg, err := fx.Service().GetBatchPredictionJob(fx.Context(), &GetBatchPredictionJobRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -514,7 +516,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetBatchPredictionJob(fx.Context(), &GetBatchPredictionJobRequest{ + _, err := fx.Service().GetBatchPredictionJob(fx.Context(), &GetBatchPredictionJobRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -523,7 +525,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) 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.GetBatchPredictionJob(fx.Context(), &GetBatchPredictionJobRequest{ + _, err := fx.Service().GetBatchPredictionJob(fx.Context(), &GetBatchPredictionJobRequest{ Name: "projects/-/locations/-/batchPredictionJobs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -536,7 +538,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) 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.ListBatchPredictionJobs(fx.Context(), &ListBatchPredictionJobsRequest{ + _, err := fx.Service().ListBatchPredictionJobs(fx.Context(), &ListBatchPredictionJobsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -546,7 +548,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListBatchPredictionJobs(fx.Context(), &ListBatchPredictionJobsRequest{ + _, err := fx.Service().ListBatchPredictionJobs(fx.Context(), &ListBatchPredictionJobsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -557,7 +559,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListBatchPredictionJobs(fx.Context(), &ListBatchPredictionJobsRequest{ + _, err := fx.Service().ListBatchPredictionJobs(fx.Context(), &ListBatchPredictionJobsRequest{ Parent: parent, PageSize: -10, }) @@ -575,7 +577,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListBatchPredictionJobs(fx.Context(), &ListBatchPredictionJobsRequest{ + response, err := fx.Service().ListBatchPredictionJobs(fx.Context(), &ListBatchPredictionJobsRequest{ Parent: parent, PageSize: 999, }) @@ -594,7 +596,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) 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.ListBatchPredictionJobs(fx.Context(), &ListBatchPredictionJobsRequest{ + response, err := fx.Service().ListBatchPredictionJobs(fx.Context(), &ListBatchPredictionJobsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -605,7 +607,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) 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.ListBatchPredictionJobs(fx.Context(), &ListBatchPredictionJobsRequest{ + response, err := fx.Service().ListBatchPredictionJobs(fx.Context(), &ListBatchPredictionJobsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -619,7 +621,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testList(t *testing.T) { msgs := make([]*BatchPredictionJob, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListBatchPredictionJobs(fx.Context(), &ListBatchPredictionJobsRequest{ + response, err := fx.Service().ListBatchPredictionJobs(fx.Context(), &ListBatchPredictionJobsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -648,12 +650,12 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteBatchPredictionJob(fx.Context(), &DeleteBatchPredictionJobRequest{ + _, err := fx.Service().DeleteBatchPredictionJob(fx.Context(), &DeleteBatchPredictionJobRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListBatchPredictionJobs(fx.Context(), &ListBatchPredictionJobsRequest{ + response, err := fx.Service().ListBatchPredictionJobs(fx.Context(), &ListBatchPredictionJobsRequest{ Parent: parent, PageSize: 9999, }) @@ -676,7 +678,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testDelete(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.DeleteBatchPredictionJob(fx.Context(), &DeleteBatchPredictionJobRequest{ + _, err := fx.Service().DeleteBatchPredictionJob(fx.Context(), &DeleteBatchPredictionJobRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -685,7 +687,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testDelete(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.DeleteBatchPredictionJob(fx.Context(), &DeleteBatchPredictionJobRequest{ + _, err := fx.Service().DeleteBatchPredictionJob(fx.Context(), &DeleteBatchPredictionJobRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -696,7 +698,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteBatchPredictionJob(fx.Context(), &DeleteBatchPredictionJobRequest{ + _, err := fx.Service().DeleteBatchPredictionJob(fx.Context(), &DeleteBatchPredictionJobRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -707,7 +709,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteBatchPredictionJob(fx.Context(), &DeleteBatchPredictionJobRequest{ + _, err := fx.Service().DeleteBatchPredictionJob(fx.Context(), &DeleteBatchPredictionJobRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -718,12 +720,12 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteBatchPredictionJob(fx.Context(), &DeleteBatchPredictionJobRequest{ + deleted, err := fx.Service().DeleteBatchPredictionJob(fx.Context(), &DeleteBatchPredictionJobRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteBatchPredictionJob(fx.Context(), &DeleteBatchPredictionJobRequest{ + _, err = fx.Service().DeleteBatchPredictionJob(fx.Context(), &DeleteBatchPredictionJobRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -732,7 +734,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) testDelete(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.DeleteBatchPredictionJob(fx.Context(), &DeleteBatchPredictionJobRequest{ + _, err := fx.Service().DeleteBatchPredictionJob(fx.Context(), &DeleteBatchPredictionJobRequest{ Name: "projects/-/locations/-/batchPredictionJobs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -768,7 +770,7 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *JobServiceBatchPredictionJobTestSuiteConfig) create(t *testing.T, parent string) *BatchPredictionJob { t.Helper() - created, err := fx.service.CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ + created, err := fx.Service().CreateBatchPredictionJob(fx.Context(), &CreateBatchPredictionJobRequest{ Parent: parent, BatchPredictionJob: fx.Create(parent), }) @@ -777,9 +779,11 @@ func (fx *JobServiceBatchPredictionJobTestSuiteConfig) create(t *testing.T, pare } type JobServiceCustomJobTestSuiteConfig struct { - service JobServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() JobServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -810,7 +814,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) 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.CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ + _, err := fx.Service().CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ Parent: "", CustomJob: fx.Create(fx.nextParent(t, false)), }) @@ -820,7 +824,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) 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.CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ + _, err := fx.Service().CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ Parent: "invalid resource name", CustomJob: fx.Create(fx.nextParent(t, false)), }) @@ -832,7 +836,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testCreate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ + msg, err := fx.Service().CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ Parent: parent, CustomJob: fx.Create(parent), }) @@ -846,12 +850,12 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testCreate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ + msg, err := fx.Service().CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ Parent: parent, CustomJob: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetCustomJob(fx.Context(), &GetCustomJobRequest{ + persisted, err := fx.Service().GetCustomJob(fx.Context(), &GetCustomJobRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -872,7 +876,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ + _, err := fx.Service().CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ Parent: parent, CustomJob: msg, }) @@ -888,7 +892,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("job_spec") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ + _, err := fx.Service().CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ Parent: parent, CustomJob: msg, }) @@ -904,7 +908,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("worker_pool_specs") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ + _, err := fx.Service().CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ Parent: parent, CustomJob: msg, }) @@ -920,7 +924,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("output_uri_prefix") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ + _, err := fx.Service().CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ Parent: parent, CustomJob: msg, }) @@ -936,7 +940,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ + _, err := fx.Service().CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ Parent: parent, CustomJob: msg, }) @@ -957,7 +961,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Network = "invalid resource name" - _, err := fx.service.CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ + _, err := fx.Service().CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ Parent: parent, CustomJob: msg, }) @@ -972,7 +976,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Tensorboard = "invalid resource name" - _, err := fx.service.CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ + _, err := fx.Service().CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ Parent: parent, CustomJob: msg, }) @@ -987,7 +991,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Experiment = "invalid resource name" - _, err := fx.service.CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ + _, err := fx.Service().CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ Parent: parent, CustomJob: msg, }) @@ -1002,7 +1006,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.ExperimentRun = "invalid resource name" - _, err := fx.service.CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ + _, err := fx.Service().CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ Parent: parent, CustomJob: msg, }) @@ -1017,7 +1021,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Models = []string{"invalid resource name"} - _, err := fx.service.CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ + _, err := fx.Service().CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ Parent: parent, CustomJob: msg, }) @@ -1032,7 +1036,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) 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.GetCustomJob(fx.Context(), &GetCustomJobRequest{ + _, err := fx.Service().GetCustomJob(fx.Context(), &GetCustomJobRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1041,7 +1045,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) 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.GetCustomJob(fx.Context(), &GetCustomJobRequest{ + _, err := fx.Service().GetCustomJob(fx.Context(), &GetCustomJobRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1052,7 +1056,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetCustomJob(fx.Context(), &GetCustomJobRequest{ + msg, err := fx.Service().GetCustomJob(fx.Context(), &GetCustomJobRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1064,7 +1068,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetCustomJob(fx.Context(), &GetCustomJobRequest{ + _, err := fx.Service().GetCustomJob(fx.Context(), &GetCustomJobRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1073,7 +1077,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) 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.GetCustomJob(fx.Context(), &GetCustomJobRequest{ + _, err := fx.Service().GetCustomJob(fx.Context(), &GetCustomJobRequest{ Name: "projects/-/locations/-/customJobs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1086,7 +1090,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) 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.ListCustomJobs(fx.Context(), &ListCustomJobsRequest{ + _, err := fx.Service().ListCustomJobs(fx.Context(), &ListCustomJobsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1096,7 +1100,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListCustomJobs(fx.Context(), &ListCustomJobsRequest{ + _, err := fx.Service().ListCustomJobs(fx.Context(), &ListCustomJobsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -1107,7 +1111,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListCustomJobs(fx.Context(), &ListCustomJobsRequest{ + _, err := fx.Service().ListCustomJobs(fx.Context(), &ListCustomJobsRequest{ Parent: parent, PageSize: -10, }) @@ -1125,7 +1129,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListCustomJobs(fx.Context(), &ListCustomJobsRequest{ + response, err := fx.Service().ListCustomJobs(fx.Context(), &ListCustomJobsRequest{ Parent: parent, PageSize: 999, }) @@ -1144,7 +1148,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) 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.ListCustomJobs(fx.Context(), &ListCustomJobsRequest{ + response, err := fx.Service().ListCustomJobs(fx.Context(), &ListCustomJobsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -1155,7 +1159,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) 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.ListCustomJobs(fx.Context(), &ListCustomJobsRequest{ + response, err := fx.Service().ListCustomJobs(fx.Context(), &ListCustomJobsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -1169,7 +1173,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testList(t *testing.T) { msgs := make([]*CustomJob, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListCustomJobs(fx.Context(), &ListCustomJobsRequest{ + response, err := fx.Service().ListCustomJobs(fx.Context(), &ListCustomJobsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -1198,12 +1202,12 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteCustomJob(fx.Context(), &DeleteCustomJobRequest{ + _, err := fx.Service().DeleteCustomJob(fx.Context(), &DeleteCustomJobRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListCustomJobs(fx.Context(), &ListCustomJobsRequest{ + response, err := fx.Service().ListCustomJobs(fx.Context(), &ListCustomJobsRequest{ Parent: parent, PageSize: 9999, }) @@ -1226,7 +1230,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testDelete(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.DeleteCustomJob(fx.Context(), &DeleteCustomJobRequest{ + _, err := fx.Service().DeleteCustomJob(fx.Context(), &DeleteCustomJobRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1235,7 +1239,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testDelete(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.DeleteCustomJob(fx.Context(), &DeleteCustomJobRequest{ + _, err := fx.Service().DeleteCustomJob(fx.Context(), &DeleteCustomJobRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1246,7 +1250,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteCustomJob(fx.Context(), &DeleteCustomJobRequest{ + _, err := fx.Service().DeleteCustomJob(fx.Context(), &DeleteCustomJobRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1257,7 +1261,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteCustomJob(fx.Context(), &DeleteCustomJobRequest{ + _, err := fx.Service().DeleteCustomJob(fx.Context(), &DeleteCustomJobRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1268,12 +1272,12 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteCustomJob(fx.Context(), &DeleteCustomJobRequest{ + deleted, err := fx.Service().DeleteCustomJob(fx.Context(), &DeleteCustomJobRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteCustomJob(fx.Context(), &DeleteCustomJobRequest{ + _, err = fx.Service().DeleteCustomJob(fx.Context(), &DeleteCustomJobRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1282,7 +1286,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) testDelete(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.DeleteCustomJob(fx.Context(), &DeleteCustomJobRequest{ + _, err := fx.Service().DeleteCustomJob(fx.Context(), &DeleteCustomJobRequest{ Name: "projects/-/locations/-/customJobs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1318,7 +1322,7 @@ func (fx *JobServiceCustomJobTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *JobServiceCustomJobTestSuiteConfig) create(t *testing.T, parent string) *CustomJob { t.Helper() - created, err := fx.service.CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ + created, err := fx.Service().CreateCustomJob(fx.Context(), &CreateCustomJobRequest{ Parent: parent, CustomJob: fx.Create(parent), }) @@ -1327,9 +1331,11 @@ func (fx *JobServiceCustomJobTestSuiteConfig) create(t *testing.T, parent string } type JobServiceDataLabelingJobTestSuiteConfig struct { - service JobServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() JobServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -1360,7 +1366,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) 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.CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ + _, err := fx.Service().CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ Parent: "", DataLabelingJob: fx.Create(fx.nextParent(t, false)), }) @@ -1370,7 +1376,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) 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.CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ + _, err := fx.Service().CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ Parent: "invalid resource name", DataLabelingJob: fx.Create(fx.nextParent(t, false)), }) @@ -1382,7 +1388,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testCreate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ + msg, err := fx.Service().CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ Parent: parent, DataLabelingJob: fx.Create(parent), }) @@ -1396,12 +1402,12 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testCreate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ + msg, err := fx.Service().CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ Parent: parent, DataLabelingJob: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetDataLabelingJob(fx.Context(), &GetDataLabelingJobRequest{ + persisted, err := fx.Service().GetDataLabelingJob(fx.Context(), &GetDataLabelingJobRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -1422,7 +1428,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ + _, err := fx.Service().CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ Parent: parent, DataLabelingJob: msg, }) @@ -1438,7 +1444,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("datasets") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ + _, err := fx.Service().CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ Parent: parent, DataLabelingJob: msg, }) @@ -1454,7 +1460,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("labeler_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ + _, err := fx.Service().CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ Parent: parent, DataLabelingJob: msg, }) @@ -1470,7 +1476,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("instruction_uri") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ + _, err := fx.Service().CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ Parent: parent, DataLabelingJob: msg, }) @@ -1486,7 +1492,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("inputs_schema_uri") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ + _, err := fx.Service().CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ Parent: parent, DataLabelingJob: msg, }) @@ -1502,7 +1508,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("inputs") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ + _, err := fx.Service().CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ Parent: parent, DataLabelingJob: msg, }) @@ -1518,7 +1524,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ + _, err := fx.Service().CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ Parent: parent, DataLabelingJob: msg, }) @@ -1539,7 +1545,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Datasets = []string{"invalid resource name"} - _, err := fx.service.CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ + _, err := fx.Service().CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ Parent: parent, DataLabelingJob: msg, }) @@ -1554,7 +1560,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) 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.GetDataLabelingJob(fx.Context(), &GetDataLabelingJobRequest{ + _, err := fx.Service().GetDataLabelingJob(fx.Context(), &GetDataLabelingJobRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1563,7 +1569,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) 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.GetDataLabelingJob(fx.Context(), &GetDataLabelingJobRequest{ + _, err := fx.Service().GetDataLabelingJob(fx.Context(), &GetDataLabelingJobRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1574,7 +1580,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetDataLabelingJob(fx.Context(), &GetDataLabelingJobRequest{ + msg, err := fx.Service().GetDataLabelingJob(fx.Context(), &GetDataLabelingJobRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1586,7 +1592,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetDataLabelingJob(fx.Context(), &GetDataLabelingJobRequest{ + _, err := fx.Service().GetDataLabelingJob(fx.Context(), &GetDataLabelingJobRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1595,7 +1601,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) 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.GetDataLabelingJob(fx.Context(), &GetDataLabelingJobRequest{ + _, err := fx.Service().GetDataLabelingJob(fx.Context(), &GetDataLabelingJobRequest{ Name: "projects/-/locations/-/dataLabelingJobs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1608,7 +1614,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) 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.ListDataLabelingJobs(fx.Context(), &ListDataLabelingJobsRequest{ + _, err := fx.Service().ListDataLabelingJobs(fx.Context(), &ListDataLabelingJobsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1618,7 +1624,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListDataLabelingJobs(fx.Context(), &ListDataLabelingJobsRequest{ + _, err := fx.Service().ListDataLabelingJobs(fx.Context(), &ListDataLabelingJobsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -1629,7 +1635,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListDataLabelingJobs(fx.Context(), &ListDataLabelingJobsRequest{ + _, err := fx.Service().ListDataLabelingJobs(fx.Context(), &ListDataLabelingJobsRequest{ Parent: parent, PageSize: -10, }) @@ -1647,7 +1653,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListDataLabelingJobs(fx.Context(), &ListDataLabelingJobsRequest{ + response, err := fx.Service().ListDataLabelingJobs(fx.Context(), &ListDataLabelingJobsRequest{ Parent: parent, PageSize: 999, }) @@ -1666,7 +1672,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) 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.ListDataLabelingJobs(fx.Context(), &ListDataLabelingJobsRequest{ + response, err := fx.Service().ListDataLabelingJobs(fx.Context(), &ListDataLabelingJobsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -1677,7 +1683,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) 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.ListDataLabelingJobs(fx.Context(), &ListDataLabelingJobsRequest{ + response, err := fx.Service().ListDataLabelingJobs(fx.Context(), &ListDataLabelingJobsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -1691,7 +1697,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testList(t *testing.T) { msgs := make([]*DataLabelingJob, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListDataLabelingJobs(fx.Context(), &ListDataLabelingJobsRequest{ + response, err := fx.Service().ListDataLabelingJobs(fx.Context(), &ListDataLabelingJobsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -1720,12 +1726,12 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteDataLabelingJob(fx.Context(), &DeleteDataLabelingJobRequest{ + _, err := fx.Service().DeleteDataLabelingJob(fx.Context(), &DeleteDataLabelingJobRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListDataLabelingJobs(fx.Context(), &ListDataLabelingJobsRequest{ + response, err := fx.Service().ListDataLabelingJobs(fx.Context(), &ListDataLabelingJobsRequest{ Parent: parent, PageSize: 9999, }) @@ -1748,7 +1754,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testDelete(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.DeleteDataLabelingJob(fx.Context(), &DeleteDataLabelingJobRequest{ + _, err := fx.Service().DeleteDataLabelingJob(fx.Context(), &DeleteDataLabelingJobRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1757,7 +1763,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testDelete(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.DeleteDataLabelingJob(fx.Context(), &DeleteDataLabelingJobRequest{ + _, err := fx.Service().DeleteDataLabelingJob(fx.Context(), &DeleteDataLabelingJobRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1768,7 +1774,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteDataLabelingJob(fx.Context(), &DeleteDataLabelingJobRequest{ + _, err := fx.Service().DeleteDataLabelingJob(fx.Context(), &DeleteDataLabelingJobRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1779,7 +1785,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteDataLabelingJob(fx.Context(), &DeleteDataLabelingJobRequest{ + _, err := fx.Service().DeleteDataLabelingJob(fx.Context(), &DeleteDataLabelingJobRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1790,12 +1796,12 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteDataLabelingJob(fx.Context(), &DeleteDataLabelingJobRequest{ + deleted, err := fx.Service().DeleteDataLabelingJob(fx.Context(), &DeleteDataLabelingJobRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteDataLabelingJob(fx.Context(), &DeleteDataLabelingJobRequest{ + _, err = fx.Service().DeleteDataLabelingJob(fx.Context(), &DeleteDataLabelingJobRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1804,7 +1810,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) testDelete(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.DeleteDataLabelingJob(fx.Context(), &DeleteDataLabelingJobRequest{ + _, err := fx.Service().DeleteDataLabelingJob(fx.Context(), &DeleteDataLabelingJobRequest{ Name: "projects/-/locations/-/dataLabelingJobs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1840,7 +1846,7 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *JobServiceDataLabelingJobTestSuiteConfig) create(t *testing.T, parent string) *DataLabelingJob { t.Helper() - created, err := fx.service.CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ + created, err := fx.Service().CreateDataLabelingJob(fx.Context(), &CreateDataLabelingJobRequest{ Parent: parent, DataLabelingJob: fx.Create(parent), }) @@ -1849,9 +1855,11 @@ func (fx *JobServiceDataLabelingJobTestSuiteConfig) create(t *testing.T, parent } type JobServiceHyperparameterTuningJobTestSuiteConfig struct { - service JobServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() JobServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -1882,7 +1890,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin // Method should fail with InvalidArgument if no parent is provided. t.Run("missing parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + _, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: "", HyperparameterTuningJob: fx.Create(fx.nextParent(t, false)), }) @@ -1892,7 +1900,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + _, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: "invalid resource name", HyperparameterTuningJob: fx.Create(fx.nextParent(t, false)), }) @@ -1904,7 +1912,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + msg, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: fx.Create(parent), }) @@ -1918,12 +1926,12 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + msg, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetHyperparameterTuningJob(fx.Context(), &GetHyperparameterTuningJobRequest{ + persisted, err := fx.Service().GetHyperparameterTuningJob(fx.Context(), &GetHyperparameterTuningJobRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -1944,7 +1952,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + _, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: msg, }) @@ -1960,7 +1968,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin } fd := container.ProtoReflect().Descriptor().Fields().ByName("study_spec") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + _, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: msg, }) @@ -1976,7 +1984,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin } fd := container.ProtoReflect().Descriptor().Fields().ByName("metrics") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + _, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: msg, }) @@ -1992,7 +2000,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin } fd := container.ProtoReflect().Descriptor().Fields().ByName("parameters") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + _, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: msg, }) @@ -2008,7 +2016,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin } fd := container.ProtoReflect().Descriptor().Fields().ByName("max_trial_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + _, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: msg, }) @@ -2024,7 +2032,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin } fd := container.ProtoReflect().Descriptor().Fields().ByName("parallel_trial_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + _, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: msg, }) @@ -2040,7 +2048,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin } fd := container.ProtoReflect().Descriptor().Fields().ByName("trial_job_spec") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + _, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: msg, }) @@ -2056,7 +2064,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin } fd := container.ProtoReflect().Descriptor().Fields().ByName("worker_pool_specs") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + _, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: msg, }) @@ -2072,7 +2080,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin } fd := container.ProtoReflect().Descriptor().Fields().ByName("output_uri_prefix") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + _, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: msg, }) @@ -2088,7 +2096,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + _, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: msg, }) @@ -2109,7 +2117,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin t.Skip("not reachable") } container.Network = "invalid resource name" - _, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + _, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: msg, }) @@ -2124,7 +2132,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin t.Skip("not reachable") } container.Tensorboard = "invalid resource name" - _, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + _, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: msg, }) @@ -2139,7 +2147,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin t.Skip("not reachable") } container.Experiment = "invalid resource name" - _, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + _, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: msg, }) @@ -2154,7 +2162,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin t.Skip("not reachable") } container.ExperimentRun = "invalid resource name" - _, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + _, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: msg, }) @@ -2169,7 +2177,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testCreate(t *testin t.Skip("not reachable") } container.Models = []string{"invalid resource name"} - _, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + _, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: msg, }) @@ -2184,7 +2192,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) 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.GetHyperparameterTuningJob(fx.Context(), &GetHyperparameterTuningJobRequest{ + _, err := fx.Service().GetHyperparameterTuningJob(fx.Context(), &GetHyperparameterTuningJobRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -2193,7 +2201,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) 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.GetHyperparameterTuningJob(fx.Context(), &GetHyperparameterTuningJobRequest{ + _, err := fx.Service().GetHyperparameterTuningJob(fx.Context(), &GetHyperparameterTuningJobRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -2204,7 +2212,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testGet(t *testing.T fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetHyperparameterTuningJob(fx.Context(), &GetHyperparameterTuningJobRequest{ + msg, err := fx.Service().GetHyperparameterTuningJob(fx.Context(), &GetHyperparameterTuningJobRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -2216,7 +2224,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testGet(t *testing.T fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetHyperparameterTuningJob(fx.Context(), &GetHyperparameterTuningJobRequest{ + _, err := fx.Service().GetHyperparameterTuningJob(fx.Context(), &GetHyperparameterTuningJobRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -2225,7 +2233,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) 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.GetHyperparameterTuningJob(fx.Context(), &GetHyperparameterTuningJobRequest{ + _, err := fx.Service().GetHyperparameterTuningJob(fx.Context(), &GetHyperparameterTuningJobRequest{ Name: "projects/-/locations/-/hyperparameterTuningJobs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -2238,7 +2246,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testList(t *testing. // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListHyperparameterTuningJobs(fx.Context(), &ListHyperparameterTuningJobsRequest{ + _, err := fx.Service().ListHyperparameterTuningJobs(fx.Context(), &ListHyperparameterTuningJobsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -2248,7 +2256,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testList(t *testing. t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListHyperparameterTuningJobs(fx.Context(), &ListHyperparameterTuningJobsRequest{ + _, err := fx.Service().ListHyperparameterTuningJobs(fx.Context(), &ListHyperparameterTuningJobsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -2259,7 +2267,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testList(t *testing. t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListHyperparameterTuningJobs(fx.Context(), &ListHyperparameterTuningJobsRequest{ + _, err := fx.Service().ListHyperparameterTuningJobs(fx.Context(), &ListHyperparameterTuningJobsRequest{ Parent: parent, PageSize: -10, }) @@ -2277,7 +2285,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testList(t *testing. // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListHyperparameterTuningJobs(fx.Context(), &ListHyperparameterTuningJobsRequest{ + response, err := fx.Service().ListHyperparameterTuningJobs(fx.Context(), &ListHyperparameterTuningJobsRequest{ Parent: parent, PageSize: 999, }) @@ -2296,7 +2304,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testList(t *testing. // 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.ListHyperparameterTuningJobs(fx.Context(), &ListHyperparameterTuningJobsRequest{ + response, err := fx.Service().ListHyperparameterTuningJobs(fx.Context(), &ListHyperparameterTuningJobsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -2307,7 +2315,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testList(t *testing. // 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.ListHyperparameterTuningJobs(fx.Context(), &ListHyperparameterTuningJobsRequest{ + response, err := fx.Service().ListHyperparameterTuningJobs(fx.Context(), &ListHyperparameterTuningJobsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -2321,7 +2329,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testList(t *testing. msgs := make([]*HyperparameterTuningJob, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListHyperparameterTuningJobs(fx.Context(), &ListHyperparameterTuningJobsRequest{ + response, err := fx.Service().ListHyperparameterTuningJobs(fx.Context(), &ListHyperparameterTuningJobsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -2350,12 +2358,12 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testList(t *testing. fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteHyperparameterTuningJob(fx.Context(), &DeleteHyperparameterTuningJobRequest{ + _, err := fx.Service().DeleteHyperparameterTuningJob(fx.Context(), &DeleteHyperparameterTuningJobRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListHyperparameterTuningJobs(fx.Context(), &ListHyperparameterTuningJobsRequest{ + response, err := fx.Service().ListHyperparameterTuningJobs(fx.Context(), &ListHyperparameterTuningJobsRequest{ Parent: parent, PageSize: 9999, }) @@ -2378,7 +2386,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testDelete(t *testin // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.DeleteHyperparameterTuningJob(fx.Context(), &DeleteHyperparameterTuningJobRequest{ + _, err := fx.Service().DeleteHyperparameterTuningJob(fx.Context(), &DeleteHyperparameterTuningJobRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -2387,7 +2395,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testDelete(t *testin // 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.DeleteHyperparameterTuningJob(fx.Context(), &DeleteHyperparameterTuningJobRequest{ + _, err := fx.Service().DeleteHyperparameterTuningJob(fx.Context(), &DeleteHyperparameterTuningJobRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -2398,7 +2406,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testDelete(t *testin fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteHyperparameterTuningJob(fx.Context(), &DeleteHyperparameterTuningJobRequest{ + _, err := fx.Service().DeleteHyperparameterTuningJob(fx.Context(), &DeleteHyperparameterTuningJobRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -2409,7 +2417,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testDelete(t *testin fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteHyperparameterTuningJob(fx.Context(), &DeleteHyperparameterTuningJobRequest{ + _, err := fx.Service().DeleteHyperparameterTuningJob(fx.Context(), &DeleteHyperparameterTuningJobRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -2420,12 +2428,12 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testDelete(t *testin fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteHyperparameterTuningJob(fx.Context(), &DeleteHyperparameterTuningJobRequest{ + deleted, err := fx.Service().DeleteHyperparameterTuningJob(fx.Context(), &DeleteHyperparameterTuningJobRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteHyperparameterTuningJob(fx.Context(), &DeleteHyperparameterTuningJobRequest{ + _, err = fx.Service().DeleteHyperparameterTuningJob(fx.Context(), &DeleteHyperparameterTuningJobRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -2434,7 +2442,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) testDelete(t *testin // 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.DeleteHyperparameterTuningJob(fx.Context(), &DeleteHyperparameterTuningJobRequest{ + _, err := fx.Service().DeleteHyperparameterTuningJob(fx.Context(), &DeleteHyperparameterTuningJobRequest{ Name: "projects/-/locations/-/hyperparameterTuningJobs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -2470,7 +2478,7 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) maybeSkip(t *testing func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) create(t *testing.T, parent string) *HyperparameterTuningJob { t.Helper() - created, err := fx.service.CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ + created, err := fx.Service().CreateHyperparameterTuningJob(fx.Context(), &CreateHyperparameterTuningJobRequest{ Parent: parent, HyperparameterTuningJob: fx.Create(parent), }) @@ -2479,9 +2487,11 @@ func (fx *JobServiceHyperparameterTuningJobTestSuiteConfig) create(t *testing.T, } type JobServiceModelDeploymentMonitoringJobTestSuiteConfig struct { - service JobServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() JobServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -2516,7 +2526,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testCreate(t *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.CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ Parent: "", ModelDeploymentMonitoringJob: fx.Create(fx.nextParent(t, false)), }) @@ -2526,7 +2536,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testCreate(t *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.CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ Parent: "invalid resource name", ModelDeploymentMonitoringJob: fx.Create(fx.nextParent(t, false)), }) @@ -2538,7 +2548,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testCreate(t *t fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ + msg, err := fx.Service().CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ Parent: parent, ModelDeploymentMonitoringJob: fx.Create(parent), }) @@ -2552,12 +2562,12 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testCreate(t *t t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ + msg, err := fx.Service().CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ Parent: parent, ModelDeploymentMonitoringJob: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetModelDeploymentMonitoringJob(fx.Context(), &GetModelDeploymentMonitoringJobRequest{ + persisted, err := fx.Service().GetModelDeploymentMonitoringJob(fx.Context(), &GetModelDeploymentMonitoringJobRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -2578,7 +2588,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testCreate(t *t } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ Parent: parent, ModelDeploymentMonitoringJob: msg, }) @@ -2594,7 +2604,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testCreate(t *t } fd := container.ProtoReflect().Descriptor().Fields().ByName("endpoint") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ Parent: parent, ModelDeploymentMonitoringJob: msg, }) @@ -2610,7 +2620,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testCreate(t *t } fd := container.ProtoReflect().Descriptor().Fields().ByName("model_deployment_monitoring_objective_configs") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ Parent: parent, ModelDeploymentMonitoringJob: msg, }) @@ -2626,7 +2636,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testCreate(t *t } fd := container.ProtoReflect().Descriptor().Fields().ByName("model_deployment_monitoring_schedule_config") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ Parent: parent, ModelDeploymentMonitoringJob: msg, }) @@ -2642,7 +2652,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testCreate(t *t } fd := container.ProtoReflect().Descriptor().Fields().ByName("monitor_interval") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ Parent: parent, ModelDeploymentMonitoringJob: msg, }) @@ -2658,7 +2668,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testCreate(t *t } fd := container.ProtoReflect().Descriptor().Fields().ByName("logging_sampling_strategy") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ Parent: parent, ModelDeploymentMonitoringJob: msg, }) @@ -2674,7 +2684,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testCreate(t *t } fd := container.ProtoReflect().Descriptor().Fields().ByName("output_uri_prefix") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ Parent: parent, ModelDeploymentMonitoringJob: msg, }) @@ -2690,7 +2700,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testCreate(t *t } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ Parent: parent, ModelDeploymentMonitoringJob: msg, }) @@ -2711,7 +2721,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testCreate(t *t t.Skip("not reachable") } container.Endpoint = "invalid resource name" - _, err := fx.service.CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ Parent: parent, ModelDeploymentMonitoringJob: msg, }) @@ -2726,7 +2736,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testCreate(t *t t.Skip("not reachable") } container.NotificationChannels = []string{"invalid resource name"} - _, err := fx.service.CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ Parent: parent, ModelDeploymentMonitoringJob: msg, }) @@ -2741,7 +2751,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testGet(t *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.GetModelDeploymentMonitoringJob(fx.Context(), &GetModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().GetModelDeploymentMonitoringJob(fx.Context(), &GetModelDeploymentMonitoringJobRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -2750,7 +2760,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testGet(t *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.GetModelDeploymentMonitoringJob(fx.Context(), &GetModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().GetModelDeploymentMonitoringJob(fx.Context(), &GetModelDeploymentMonitoringJobRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -2761,7 +2771,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testGet(t *test fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetModelDeploymentMonitoringJob(fx.Context(), &GetModelDeploymentMonitoringJobRequest{ + msg, err := fx.Service().GetModelDeploymentMonitoringJob(fx.Context(), &GetModelDeploymentMonitoringJobRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -2773,7 +2783,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testGet(t *test fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetModelDeploymentMonitoringJob(fx.Context(), &GetModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().GetModelDeploymentMonitoringJob(fx.Context(), &GetModelDeploymentMonitoringJobRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -2782,7 +2792,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testGet(t *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.GetModelDeploymentMonitoringJob(fx.Context(), &GetModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().GetModelDeploymentMonitoringJob(fx.Context(), &GetModelDeploymentMonitoringJobRequest{ Name: "projects/-/locations/-/modelDeploymentMonitoringJobs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -2798,7 +2808,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testUpdate(t *t parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ ModelDeploymentMonitoringJob: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -2810,7 +2820,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testUpdate(t *t parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ ModelDeploymentMonitoringJob: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -2823,7 +2833,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testUpdate(t *t fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ ModelDeploymentMonitoringJob: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -2832,7 +2842,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testUpdate(t *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.UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ ModelDeploymentMonitoringJob: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -2856,7 +2866,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testUpdate(t *t } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ ModelDeploymentMonitoringJob: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -2875,7 +2885,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testUpdate(t *t } fd := container.ProtoReflect().Descriptor().Fields().ByName("endpoint") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ ModelDeploymentMonitoringJob: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -2894,7 +2904,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testUpdate(t *t } fd := container.ProtoReflect().Descriptor().Fields().ByName("model_deployment_monitoring_objective_configs") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ ModelDeploymentMonitoringJob: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -2913,7 +2923,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testUpdate(t *t } fd := container.ProtoReflect().Descriptor().Fields().ByName("model_deployment_monitoring_schedule_config") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ ModelDeploymentMonitoringJob: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -2932,7 +2942,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testUpdate(t *t } fd := container.ProtoReflect().Descriptor().Fields().ByName("monitor_interval") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ ModelDeploymentMonitoringJob: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -2951,7 +2961,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testUpdate(t *t } fd := container.ProtoReflect().Descriptor().Fields().ByName("logging_sampling_strategy") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ ModelDeploymentMonitoringJob: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -2970,7 +2980,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testUpdate(t *t } fd := container.ProtoReflect().Descriptor().Fields().ByName("output_uri_prefix") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ ModelDeploymentMonitoringJob: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -2989,7 +2999,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testUpdate(t *t } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().UpdateModelDeploymentMonitoringJob(fx.Context(), &UpdateModelDeploymentMonitoringJobRequest{ ModelDeploymentMonitoringJob: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -3008,7 +3018,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testList(t *tes // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListModelDeploymentMonitoringJobs(fx.Context(), &ListModelDeploymentMonitoringJobsRequest{ + _, err := fx.Service().ListModelDeploymentMonitoringJobs(fx.Context(), &ListModelDeploymentMonitoringJobsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -3018,7 +3028,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testList(t *tes t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListModelDeploymentMonitoringJobs(fx.Context(), &ListModelDeploymentMonitoringJobsRequest{ + _, err := fx.Service().ListModelDeploymentMonitoringJobs(fx.Context(), &ListModelDeploymentMonitoringJobsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -3029,7 +3039,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testList(t *tes t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListModelDeploymentMonitoringJobs(fx.Context(), &ListModelDeploymentMonitoringJobsRequest{ + _, err := fx.Service().ListModelDeploymentMonitoringJobs(fx.Context(), &ListModelDeploymentMonitoringJobsRequest{ Parent: parent, PageSize: -10, }) @@ -3047,7 +3057,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testList(t *tes // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListModelDeploymentMonitoringJobs(fx.Context(), &ListModelDeploymentMonitoringJobsRequest{ + response, err := fx.Service().ListModelDeploymentMonitoringJobs(fx.Context(), &ListModelDeploymentMonitoringJobsRequest{ Parent: parent, PageSize: 999, }) @@ -3066,7 +3076,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testList(t *tes // 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.ListModelDeploymentMonitoringJobs(fx.Context(), &ListModelDeploymentMonitoringJobsRequest{ + response, err := fx.Service().ListModelDeploymentMonitoringJobs(fx.Context(), &ListModelDeploymentMonitoringJobsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -3077,7 +3087,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testList(t *tes // 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.ListModelDeploymentMonitoringJobs(fx.Context(), &ListModelDeploymentMonitoringJobsRequest{ + response, err := fx.Service().ListModelDeploymentMonitoringJobs(fx.Context(), &ListModelDeploymentMonitoringJobsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -3091,7 +3101,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testList(t *tes msgs := make([]*ModelDeploymentMonitoringJob, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListModelDeploymentMonitoringJobs(fx.Context(), &ListModelDeploymentMonitoringJobsRequest{ + response, err := fx.Service().ListModelDeploymentMonitoringJobs(fx.Context(), &ListModelDeploymentMonitoringJobsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -3120,12 +3130,12 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testList(t *tes fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteModelDeploymentMonitoringJob(fx.Context(), &DeleteModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().DeleteModelDeploymentMonitoringJob(fx.Context(), &DeleteModelDeploymentMonitoringJobRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListModelDeploymentMonitoringJobs(fx.Context(), &ListModelDeploymentMonitoringJobsRequest{ + response, err := fx.Service().ListModelDeploymentMonitoringJobs(fx.Context(), &ListModelDeploymentMonitoringJobsRequest{ Parent: parent, PageSize: 9999, }) @@ -3148,7 +3158,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testDelete(t *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.DeleteModelDeploymentMonitoringJob(fx.Context(), &DeleteModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().DeleteModelDeploymentMonitoringJob(fx.Context(), &DeleteModelDeploymentMonitoringJobRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -3157,7 +3167,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testDelete(t *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.DeleteModelDeploymentMonitoringJob(fx.Context(), &DeleteModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().DeleteModelDeploymentMonitoringJob(fx.Context(), &DeleteModelDeploymentMonitoringJobRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -3168,7 +3178,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testDelete(t *t fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteModelDeploymentMonitoringJob(fx.Context(), &DeleteModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().DeleteModelDeploymentMonitoringJob(fx.Context(), &DeleteModelDeploymentMonitoringJobRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -3179,7 +3189,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testDelete(t *t fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteModelDeploymentMonitoringJob(fx.Context(), &DeleteModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().DeleteModelDeploymentMonitoringJob(fx.Context(), &DeleteModelDeploymentMonitoringJobRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -3190,12 +3200,12 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testDelete(t *t fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteModelDeploymentMonitoringJob(fx.Context(), &DeleteModelDeploymentMonitoringJobRequest{ + deleted, err := fx.Service().DeleteModelDeploymentMonitoringJob(fx.Context(), &DeleteModelDeploymentMonitoringJobRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteModelDeploymentMonitoringJob(fx.Context(), &DeleteModelDeploymentMonitoringJobRequest{ + _, err = fx.Service().DeleteModelDeploymentMonitoringJob(fx.Context(), &DeleteModelDeploymentMonitoringJobRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -3204,7 +3214,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) testDelete(t *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.DeleteModelDeploymentMonitoringJob(fx.Context(), &DeleteModelDeploymentMonitoringJobRequest{ + _, err := fx.Service().DeleteModelDeploymentMonitoringJob(fx.Context(), &DeleteModelDeploymentMonitoringJobRequest{ Name: "projects/-/locations/-/modelDeploymentMonitoringJobs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -3240,7 +3250,7 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) maybeSkip(t *te func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) create(t *testing.T, parent string) *ModelDeploymentMonitoringJob { t.Helper() - created, err := fx.service.CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ + created, err := fx.Service().CreateModelDeploymentMonitoringJob(fx.Context(), &CreateModelDeploymentMonitoringJobRequest{ Parent: parent, ModelDeploymentMonitoringJob: fx.Create(parent), }) @@ -3249,9 +3259,11 @@ func (fx *JobServiceModelDeploymentMonitoringJobTestSuiteConfig) create(t *testi } type JobServiceNasJobTestSuiteConfig struct { - service JobServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() JobServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -3282,7 +3294,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) 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.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: "", NasJob: fx.Create(fx.nextParent(t, false)), }) @@ -3292,7 +3304,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) 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.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: "invalid resource name", NasJob: fx.Create(fx.nextParent(t, false)), }) @@ -3304,7 +3316,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + msg, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: fx.Create(parent), }) @@ -3318,12 +3330,12 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + msg, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetNasJob(fx.Context(), &GetNasJobRequest{ + persisted, err := fx.Service().GetNasJob(fx.Context(), &GetNasJobRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -3344,7 +3356,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3360,7 +3372,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("nas_job_spec") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3376,7 +3388,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("metric_id") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3392,7 +3404,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("goal") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3408,7 +3420,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("search_trial_spec") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3424,7 +3436,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("search_trial_job_spec") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3440,7 +3452,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("worker_pool_specs") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3456,7 +3468,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("output_uri_prefix") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3472,7 +3484,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("max_trial_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3488,7 +3500,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("max_parallel_trial_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3504,7 +3516,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("train_trial_job_spec") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3520,7 +3532,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("max_parallel_trial_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3536,7 +3548,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("frequency") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3552,7 +3564,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3573,7 +3585,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Network = "invalid resource name" - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3588,7 +3600,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Tensorboard = "invalid resource name" - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3603,7 +3615,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Experiment = "invalid resource name" - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3618,7 +3630,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.ExperimentRun = "invalid resource name" - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3633,7 +3645,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Models = []string{"invalid resource name"} - _, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + _, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: msg, }) @@ -3648,7 +3660,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) 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.GetNasJob(fx.Context(), &GetNasJobRequest{ + _, err := fx.Service().GetNasJob(fx.Context(), &GetNasJobRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -3657,7 +3669,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) 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.GetNasJob(fx.Context(), &GetNasJobRequest{ + _, err := fx.Service().GetNasJob(fx.Context(), &GetNasJobRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -3668,7 +3680,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetNasJob(fx.Context(), &GetNasJobRequest{ + msg, err := fx.Service().GetNasJob(fx.Context(), &GetNasJobRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -3680,7 +3692,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetNasJob(fx.Context(), &GetNasJobRequest{ + _, err := fx.Service().GetNasJob(fx.Context(), &GetNasJobRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -3689,7 +3701,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) 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.GetNasJob(fx.Context(), &GetNasJobRequest{ + _, err := fx.Service().GetNasJob(fx.Context(), &GetNasJobRequest{ Name: "projects/-/locations/-/nasJobs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -3702,7 +3714,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) 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.ListNasJobs(fx.Context(), &ListNasJobsRequest{ + _, err := fx.Service().ListNasJobs(fx.Context(), &ListNasJobsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -3712,7 +3724,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListNasJobs(fx.Context(), &ListNasJobsRequest{ + _, err := fx.Service().ListNasJobs(fx.Context(), &ListNasJobsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -3723,7 +3735,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListNasJobs(fx.Context(), &ListNasJobsRequest{ + _, err := fx.Service().ListNasJobs(fx.Context(), &ListNasJobsRequest{ Parent: parent, PageSize: -10, }) @@ -3741,7 +3753,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListNasJobs(fx.Context(), &ListNasJobsRequest{ + response, err := fx.Service().ListNasJobs(fx.Context(), &ListNasJobsRequest{ Parent: parent, PageSize: 999, }) @@ -3760,7 +3772,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) 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.ListNasJobs(fx.Context(), &ListNasJobsRequest{ + response, err := fx.Service().ListNasJobs(fx.Context(), &ListNasJobsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -3771,7 +3783,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) 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.ListNasJobs(fx.Context(), &ListNasJobsRequest{ + response, err := fx.Service().ListNasJobs(fx.Context(), &ListNasJobsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -3785,7 +3797,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testList(t *testing.T) { msgs := make([]*NasJob, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListNasJobs(fx.Context(), &ListNasJobsRequest{ + response, err := fx.Service().ListNasJobs(fx.Context(), &ListNasJobsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -3814,12 +3826,12 @@ func (fx *JobServiceNasJobTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteNasJob(fx.Context(), &DeleteNasJobRequest{ + _, err := fx.Service().DeleteNasJob(fx.Context(), &DeleteNasJobRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListNasJobs(fx.Context(), &ListNasJobsRequest{ + response, err := fx.Service().ListNasJobs(fx.Context(), &ListNasJobsRequest{ Parent: parent, PageSize: 9999, }) @@ -3842,7 +3854,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testDelete(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.DeleteNasJob(fx.Context(), &DeleteNasJobRequest{ + _, err := fx.Service().DeleteNasJob(fx.Context(), &DeleteNasJobRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -3851,7 +3863,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testDelete(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.DeleteNasJob(fx.Context(), &DeleteNasJobRequest{ + _, err := fx.Service().DeleteNasJob(fx.Context(), &DeleteNasJobRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -3862,7 +3874,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteNasJob(fx.Context(), &DeleteNasJobRequest{ + _, err := fx.Service().DeleteNasJob(fx.Context(), &DeleteNasJobRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -3873,7 +3885,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteNasJob(fx.Context(), &DeleteNasJobRequest{ + _, err := fx.Service().DeleteNasJob(fx.Context(), &DeleteNasJobRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -3884,12 +3896,12 @@ func (fx *JobServiceNasJobTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteNasJob(fx.Context(), &DeleteNasJobRequest{ + deleted, err := fx.Service().DeleteNasJob(fx.Context(), &DeleteNasJobRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteNasJob(fx.Context(), &DeleteNasJobRequest{ + _, err = fx.Service().DeleteNasJob(fx.Context(), &DeleteNasJobRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -3898,7 +3910,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) testDelete(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.DeleteNasJob(fx.Context(), &DeleteNasJobRequest{ + _, err := fx.Service().DeleteNasJob(fx.Context(), &DeleteNasJobRequest{ Name: "projects/-/locations/-/nasJobs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -3934,7 +3946,7 @@ func (fx *JobServiceNasJobTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *JobServiceNasJobTestSuiteConfig) create(t *testing.T, parent string) *NasJob { t.Helper() - created, err := fx.service.CreateNasJob(fx.Context(), &CreateNasJobRequest{ + created, err := fx.Service().CreateNasJob(fx.Context(), &CreateNasJobRequest{ Parent: parent, NasJob: fx.Create(parent), }) @@ -3943,9 +3955,11 @@ func (fx *JobServiceNasJobTestSuiteConfig) create(t *testing.T, parent string) * } type JobServiceNasTrialDetailTestSuiteConfig struct { - service JobServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() JobServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -3977,7 +3991,7 @@ func (fx *JobServiceNasTrialDetailTestSuiteConfig) 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.GetNasTrialDetail(fx.Context(), &GetNasTrialDetailRequest{ + _, err := fx.Service().GetNasTrialDetail(fx.Context(), &GetNasTrialDetailRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -3986,7 +4000,7 @@ func (fx *JobServiceNasTrialDetailTestSuiteConfig) 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.GetNasTrialDetail(fx.Context(), &GetNasTrialDetailRequest{ + _, err := fx.Service().GetNasTrialDetail(fx.Context(), &GetNasTrialDetailRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -3997,7 +4011,7 @@ func (fx *JobServiceNasTrialDetailTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetNasTrialDetail(fx.Context(), &GetNasTrialDetailRequest{ + msg, err := fx.Service().GetNasTrialDetail(fx.Context(), &GetNasTrialDetailRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -4009,7 +4023,7 @@ func (fx *JobServiceNasTrialDetailTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetNasTrialDetail(fx.Context(), &GetNasTrialDetailRequest{ + _, err := fx.Service().GetNasTrialDetail(fx.Context(), &GetNasTrialDetailRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -4018,7 +4032,7 @@ func (fx *JobServiceNasTrialDetailTestSuiteConfig) 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.GetNasTrialDetail(fx.Context(), &GetNasTrialDetailRequest{ + _, err := fx.Service().GetNasTrialDetail(fx.Context(), &GetNasTrialDetailRequest{ Name: "projects/-/locations/-/nasJobs/-/nasTrialDetails/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -4031,7 +4045,7 @@ func (fx *JobServiceNasTrialDetailTestSuiteConfig) 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.ListNasTrialDetails(fx.Context(), &ListNasTrialDetailsRequest{ + _, err := fx.Service().ListNasTrialDetails(fx.Context(), &ListNasTrialDetailsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -4041,7 +4055,7 @@ func (fx *JobServiceNasTrialDetailTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListNasTrialDetails(fx.Context(), &ListNasTrialDetailsRequest{ + _, err := fx.Service().ListNasTrialDetails(fx.Context(), &ListNasTrialDetailsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -4052,7 +4066,7 @@ func (fx *JobServiceNasTrialDetailTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListNasTrialDetails(fx.Context(), &ListNasTrialDetailsRequest{ + _, err := fx.Service().ListNasTrialDetails(fx.Context(), &ListNasTrialDetailsRequest{ Parent: parent, PageSize: -10, }) @@ -4070,7 +4084,7 @@ func (fx *JobServiceNasTrialDetailTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListNasTrialDetails(fx.Context(), &ListNasTrialDetailsRequest{ + response, err := fx.Service().ListNasTrialDetails(fx.Context(), &ListNasTrialDetailsRequest{ Parent: parent, PageSize: 999, }) @@ -4089,7 +4103,7 @@ func (fx *JobServiceNasTrialDetailTestSuiteConfig) 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.ListNasTrialDetails(fx.Context(), &ListNasTrialDetailsRequest{ + response, err := fx.Service().ListNasTrialDetails(fx.Context(), &ListNasTrialDetailsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -4100,7 +4114,7 @@ func (fx *JobServiceNasTrialDetailTestSuiteConfig) 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.ListNasTrialDetails(fx.Context(), &ListNasTrialDetailsRequest{ + response, err := fx.Service().ListNasTrialDetails(fx.Context(), &ListNasTrialDetailsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -4114,7 +4128,7 @@ func (fx *JobServiceNasTrialDetailTestSuiteConfig) testList(t *testing.T) { msgs := make([]*NasTrialDetail, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListNasTrialDetails(fx.Context(), &ListNasTrialDetailsRequest{ + response, err := fx.Service().ListNasTrialDetails(fx.Context(), &ListNasTrialDetailsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, diff --git a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/metadata_service_aiptest.pb.go b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/metadata_service_aiptest.pb.go index d43ad24..d5c4562 100644 --- a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/metadata_service_aiptest.pb.go +++ b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/metadata_service_aiptest.pb.go @@ -24,7 +24,7 @@ type MetadataServiceTestSuite struct { func (fx MetadataServiceTestSuite) TestArtifact(ctx context.Context, options MetadataServiceArtifactTestSuiteConfig) { fx.T.Run("Artifact", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() MetadataServiceServer { return fx.Server } options.test(t) }) } @@ -32,7 +32,7 @@ func (fx MetadataServiceTestSuite) TestArtifact(ctx context.Context, options Met func (fx MetadataServiceTestSuite) TestContext(ctx context.Context, options MetadataServiceContextTestSuiteConfig) { fx.T.Run("Context", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() MetadataServiceServer { return fx.Server } options.test(t) }) } @@ -40,7 +40,7 @@ func (fx MetadataServiceTestSuite) TestContext(ctx context.Context, options Meta func (fx MetadataServiceTestSuite) TestExecution(ctx context.Context, options MetadataServiceExecutionTestSuiteConfig) { fx.T.Run("Execution", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() MetadataServiceServer { return fx.Server } options.test(t) }) } @@ -48,7 +48,7 @@ func (fx MetadataServiceTestSuite) TestExecution(ctx context.Context, options Me func (fx MetadataServiceTestSuite) TestMetadataSchema(ctx context.Context, options MetadataServiceMetadataSchemaTestSuiteConfig) { fx.T.Run("MetadataSchema", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() MetadataServiceServer { return fx.Server } options.test(t) }) } @@ -56,15 +56,17 @@ func (fx MetadataServiceTestSuite) TestMetadataSchema(ctx context.Context, optio func (fx MetadataServiceTestSuite) TestMetadataStore(ctx context.Context, options MetadataServiceMetadataStoreTestSuiteConfig) { fx.T.Run("MetadataStore", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() MetadataServiceServer { return fx.Server } options.test(t) }) } type MetadataServiceArtifactTestSuiteConfig struct { - service MetadataServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() MetadataServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -99,7 +101,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) 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.CreateArtifact(fx.Context(), &CreateArtifactRequest{ + _, err := fx.Service().CreateArtifact(fx.Context(), &CreateArtifactRequest{ Parent: "", Artifact: fx.Create(fx.nextParent(t, false)), }) @@ -109,7 +111,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) 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.CreateArtifact(fx.Context(), &CreateArtifactRequest{ + _, err := fx.Service().CreateArtifact(fx.Context(), &CreateArtifactRequest{ Parent: "invalid resource name", Artifact: fx.Create(fx.nextParent(t, false)), }) @@ -121,7 +123,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testCreate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateArtifact(fx.Context(), &CreateArtifactRequest{ + msg, err := fx.Service().CreateArtifact(fx.Context(), &CreateArtifactRequest{ Parent: parent, Artifact: fx.Create(parent), }) @@ -135,12 +137,12 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testCreate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateArtifact(fx.Context(), &CreateArtifactRequest{ + msg, err := fx.Service().CreateArtifact(fx.Context(), &CreateArtifactRequest{ Parent: parent, Artifact: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetArtifact(fx.Context(), &GetArtifactRequest{ + persisted, err := fx.Service().GetArtifact(fx.Context(), &GetArtifactRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -151,7 +153,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testCreate(t *testing.T) { t.Run("etag populated", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - created, _ := fx.service.CreateArtifact(fx.Context(), &CreateArtifactRequest{ + created, _ := fx.Service().CreateArtifact(fx.Context(), &CreateArtifactRequest{ Parent: parent, Artifact: fx.Create(parent), }) @@ -165,7 +167,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) 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.GetArtifact(fx.Context(), &GetArtifactRequest{ + _, err := fx.Service().GetArtifact(fx.Context(), &GetArtifactRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -174,7 +176,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) 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.GetArtifact(fx.Context(), &GetArtifactRequest{ + _, err := fx.Service().GetArtifact(fx.Context(), &GetArtifactRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -185,7 +187,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetArtifact(fx.Context(), &GetArtifactRequest{ + msg, err := fx.Service().GetArtifact(fx.Context(), &GetArtifactRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -197,7 +199,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetArtifact(fx.Context(), &GetArtifactRequest{ + _, err := fx.Service().GetArtifact(fx.Context(), &GetArtifactRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -206,7 +208,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) 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.GetArtifact(fx.Context(), &GetArtifactRequest{ + _, err := fx.Service().GetArtifact(fx.Context(), &GetArtifactRequest{ Name: "projects/-/locations/-/metadataStores/-/artifacts/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -222,7 +224,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateArtifact(fx.Context(), &UpdateArtifactRequest{ + _, err := fx.Service().UpdateArtifact(fx.Context(), &UpdateArtifactRequest{ Artifact: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -234,7 +236,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateArtifact(fx.Context(), &UpdateArtifactRequest{ + _, err := fx.Service().UpdateArtifact(fx.Context(), &UpdateArtifactRequest{ Artifact: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -245,7 +247,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateArtifact(fx.Context(), &UpdateArtifactRequest{ + updated, err := fx.Service().UpdateArtifact(fx.Context(), &UpdateArtifactRequest{ Artifact: created, }) assert.NilError(t, err) @@ -257,11 +259,11 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateArtifact(fx.Context(), &UpdateArtifactRequest{ + updated, err := fx.Service().UpdateArtifact(fx.Context(), &UpdateArtifactRequest{ Artifact: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetArtifact(fx.Context(), &GetArtifactRequest{ + persisted, err := fx.Service().GetArtifact(fx.Context(), &GetArtifactRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -275,7 +277,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateArtifact(fx.Context(), &UpdateArtifactRequest{ + _, err := fx.Service().UpdateArtifact(fx.Context(), &UpdateArtifactRequest{ Artifact: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -284,7 +286,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) 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.UpdateArtifact(fx.Context(), &UpdateArtifactRequest{ + _, err := fx.Service().UpdateArtifact(fx.Context(), &UpdateArtifactRequest{ Artifact: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -302,7 +304,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) 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.ListArtifacts(fx.Context(), &ListArtifactsRequest{ + _, err := fx.Service().ListArtifacts(fx.Context(), &ListArtifactsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -312,7 +314,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListArtifacts(fx.Context(), &ListArtifactsRequest{ + _, err := fx.Service().ListArtifacts(fx.Context(), &ListArtifactsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -323,7 +325,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListArtifacts(fx.Context(), &ListArtifactsRequest{ + _, err := fx.Service().ListArtifacts(fx.Context(), &ListArtifactsRequest{ Parent: parent, PageSize: -10, }) @@ -341,7 +343,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListArtifacts(fx.Context(), &ListArtifactsRequest{ + response, err := fx.Service().ListArtifacts(fx.Context(), &ListArtifactsRequest{ Parent: parent, PageSize: 999, }) @@ -360,7 +362,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) 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.ListArtifacts(fx.Context(), &ListArtifactsRequest{ + response, err := fx.Service().ListArtifacts(fx.Context(), &ListArtifactsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -371,7 +373,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) 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.ListArtifacts(fx.Context(), &ListArtifactsRequest{ + response, err := fx.Service().ListArtifacts(fx.Context(), &ListArtifactsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -385,7 +387,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Artifact, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListArtifacts(fx.Context(), &ListArtifactsRequest{ + response, err := fx.Service().ListArtifacts(fx.Context(), &ListArtifactsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -414,12 +416,12 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ + _, err := fx.Service().DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListArtifacts(fx.Context(), &ListArtifactsRequest{ + response, err := fx.Service().ListArtifacts(fx.Context(), &ListArtifactsRequest{ Parent: parent, PageSize: 9999, }) @@ -442,7 +444,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testDelete(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.DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ + _, err := fx.Service().DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -451,7 +453,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testDelete(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.DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ + _, err := fx.Service().DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -462,7 +464,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ + _, err := fx.Service().DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -473,7 +475,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ + _, err := fx.Service().DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -484,12 +486,12 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ + deleted, err := fx.Service().DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ + _, err = fx.Service().DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -498,7 +500,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testDelete(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.DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ + _, err := fx.Service().DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ Name: "projects/-/locations/-/metadataStores/-/artifacts/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -509,7 +511,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ + _, err := fx.Service().DeleteArtifact(fx.Context(), &DeleteArtifactRequest{ Name: created.Name, Etag: `"99999"`, }) @@ -546,7 +548,7 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *MetadataServiceArtifactTestSuiteConfig) create(t *testing.T, parent string) *Artifact { t.Helper() - created, err := fx.service.CreateArtifact(fx.Context(), &CreateArtifactRequest{ + created, err := fx.Service().CreateArtifact(fx.Context(), &CreateArtifactRequest{ Parent: parent, Artifact: fx.Create(parent), }) @@ -555,9 +557,11 @@ func (fx *MetadataServiceArtifactTestSuiteConfig) create(t *testing.T, parent st } type MetadataServiceContextTestSuiteConfig struct { - service MetadataServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() MetadataServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -592,7 +596,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) 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.CreateContext(fx.Context(), &CreateContextRequest{ + _, err := fx.Service().CreateContext(fx.Context(), &CreateContextRequest{ Parent: "", Context: fx.Create(fx.nextParent(t, false)), }) @@ -602,7 +606,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) 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.CreateContext(fx.Context(), &CreateContextRequest{ + _, err := fx.Service().CreateContext(fx.Context(), &CreateContextRequest{ Parent: "invalid resource name", Context: fx.Create(fx.nextParent(t, false)), }) @@ -614,7 +618,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testCreate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateContext(fx.Context(), &CreateContextRequest{ + msg, err := fx.Service().CreateContext(fx.Context(), &CreateContextRequest{ Parent: parent, Context: fx.Create(parent), }) @@ -628,12 +632,12 @@ func (fx *MetadataServiceContextTestSuiteConfig) testCreate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateContext(fx.Context(), &CreateContextRequest{ + msg, err := fx.Service().CreateContext(fx.Context(), &CreateContextRequest{ Parent: parent, Context: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetContext(fx.Context(), &GetContextRequest{ + persisted, err := fx.Service().GetContext(fx.Context(), &GetContextRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -644,7 +648,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testCreate(t *testing.T) { t.Run("etag populated", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - created, _ := fx.service.CreateContext(fx.Context(), &CreateContextRequest{ + created, _ := fx.Service().CreateContext(fx.Context(), &CreateContextRequest{ Parent: parent, Context: fx.Create(parent), }) @@ -658,7 +662,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) 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.GetContext(fx.Context(), &GetContextRequest{ + _, err := fx.Service().GetContext(fx.Context(), &GetContextRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -667,7 +671,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) 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.GetContext(fx.Context(), &GetContextRequest{ + _, err := fx.Service().GetContext(fx.Context(), &GetContextRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -678,7 +682,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetContext(fx.Context(), &GetContextRequest{ + msg, err := fx.Service().GetContext(fx.Context(), &GetContextRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -690,7 +694,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetContext(fx.Context(), &GetContextRequest{ + _, err := fx.Service().GetContext(fx.Context(), &GetContextRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -699,7 +703,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) 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.GetContext(fx.Context(), &GetContextRequest{ + _, err := fx.Service().GetContext(fx.Context(), &GetContextRequest{ Name: "projects/-/locations/-/metadataStores/-/contexts/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -715,7 +719,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateContext(fx.Context(), &UpdateContextRequest{ + _, err := fx.Service().UpdateContext(fx.Context(), &UpdateContextRequest{ Context: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -727,7 +731,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateContext(fx.Context(), &UpdateContextRequest{ + _, err := fx.Service().UpdateContext(fx.Context(), &UpdateContextRequest{ Context: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -738,7 +742,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateContext(fx.Context(), &UpdateContextRequest{ + updated, err := fx.Service().UpdateContext(fx.Context(), &UpdateContextRequest{ Context: created, }) assert.NilError(t, err) @@ -750,11 +754,11 @@ func (fx *MetadataServiceContextTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateContext(fx.Context(), &UpdateContextRequest{ + updated, err := fx.Service().UpdateContext(fx.Context(), &UpdateContextRequest{ Context: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetContext(fx.Context(), &GetContextRequest{ + persisted, err := fx.Service().GetContext(fx.Context(), &GetContextRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -768,7 +772,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateContext(fx.Context(), &UpdateContextRequest{ + _, err := fx.Service().UpdateContext(fx.Context(), &UpdateContextRequest{ Context: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -777,7 +781,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) 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.UpdateContext(fx.Context(), &UpdateContextRequest{ + _, err := fx.Service().UpdateContext(fx.Context(), &UpdateContextRequest{ Context: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -795,7 +799,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) 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.ListContexts(fx.Context(), &ListContextsRequest{ + _, err := fx.Service().ListContexts(fx.Context(), &ListContextsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -805,7 +809,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListContexts(fx.Context(), &ListContextsRequest{ + _, err := fx.Service().ListContexts(fx.Context(), &ListContextsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -816,7 +820,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListContexts(fx.Context(), &ListContextsRequest{ + _, err := fx.Service().ListContexts(fx.Context(), &ListContextsRequest{ Parent: parent, PageSize: -10, }) @@ -834,7 +838,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListContexts(fx.Context(), &ListContextsRequest{ + response, err := fx.Service().ListContexts(fx.Context(), &ListContextsRequest{ Parent: parent, PageSize: 999, }) @@ -853,7 +857,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) 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.ListContexts(fx.Context(), &ListContextsRequest{ + response, err := fx.Service().ListContexts(fx.Context(), &ListContextsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -864,7 +868,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) 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.ListContexts(fx.Context(), &ListContextsRequest{ + response, err := fx.Service().ListContexts(fx.Context(), &ListContextsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -878,7 +882,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Context, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListContexts(fx.Context(), &ListContextsRequest{ + response, err := fx.Service().ListContexts(fx.Context(), &ListContextsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -907,12 +911,12 @@ func (fx *MetadataServiceContextTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteContext(fx.Context(), &DeleteContextRequest{ + _, err := fx.Service().DeleteContext(fx.Context(), &DeleteContextRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListContexts(fx.Context(), &ListContextsRequest{ + response, err := fx.Service().ListContexts(fx.Context(), &ListContextsRequest{ Parent: parent, PageSize: 9999, }) @@ -935,7 +939,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testDelete(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.DeleteContext(fx.Context(), &DeleteContextRequest{ + _, err := fx.Service().DeleteContext(fx.Context(), &DeleteContextRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -944,7 +948,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testDelete(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.DeleteContext(fx.Context(), &DeleteContextRequest{ + _, err := fx.Service().DeleteContext(fx.Context(), &DeleteContextRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -955,7 +959,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteContext(fx.Context(), &DeleteContextRequest{ + _, err := fx.Service().DeleteContext(fx.Context(), &DeleteContextRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -966,7 +970,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteContext(fx.Context(), &DeleteContextRequest{ + _, err := fx.Service().DeleteContext(fx.Context(), &DeleteContextRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -977,12 +981,12 @@ func (fx *MetadataServiceContextTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteContext(fx.Context(), &DeleteContextRequest{ + deleted, err := fx.Service().DeleteContext(fx.Context(), &DeleteContextRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteContext(fx.Context(), &DeleteContextRequest{ + _, err = fx.Service().DeleteContext(fx.Context(), &DeleteContextRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -991,7 +995,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testDelete(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.DeleteContext(fx.Context(), &DeleteContextRequest{ + _, err := fx.Service().DeleteContext(fx.Context(), &DeleteContextRequest{ Name: "projects/-/locations/-/metadataStores/-/contexts/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1002,7 +1006,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteContext(fx.Context(), &DeleteContextRequest{ + _, err := fx.Service().DeleteContext(fx.Context(), &DeleteContextRequest{ Name: created.Name, Etag: `"99999"`, }) @@ -1039,7 +1043,7 @@ func (fx *MetadataServiceContextTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *MetadataServiceContextTestSuiteConfig) create(t *testing.T, parent string) *Context { t.Helper() - created, err := fx.service.CreateContext(fx.Context(), &CreateContextRequest{ + created, err := fx.Service().CreateContext(fx.Context(), &CreateContextRequest{ Parent: parent, Context: fx.Create(parent), }) @@ -1048,9 +1052,11 @@ func (fx *MetadataServiceContextTestSuiteConfig) create(t *testing.T, parent str } type MetadataServiceExecutionTestSuiteConfig struct { - service MetadataServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() MetadataServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -1085,7 +1091,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) 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.CreateExecution(fx.Context(), &CreateExecutionRequest{ + _, err := fx.Service().CreateExecution(fx.Context(), &CreateExecutionRequest{ Parent: "", Execution: fx.Create(fx.nextParent(t, false)), }) @@ -1095,7 +1101,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) 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.CreateExecution(fx.Context(), &CreateExecutionRequest{ + _, err := fx.Service().CreateExecution(fx.Context(), &CreateExecutionRequest{ Parent: "invalid resource name", Execution: fx.Create(fx.nextParent(t, false)), }) @@ -1107,7 +1113,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testCreate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateExecution(fx.Context(), &CreateExecutionRequest{ + msg, err := fx.Service().CreateExecution(fx.Context(), &CreateExecutionRequest{ Parent: parent, Execution: fx.Create(parent), }) @@ -1121,12 +1127,12 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testCreate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateExecution(fx.Context(), &CreateExecutionRequest{ + msg, err := fx.Service().CreateExecution(fx.Context(), &CreateExecutionRequest{ Parent: parent, Execution: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetExecution(fx.Context(), &GetExecutionRequest{ + persisted, err := fx.Service().GetExecution(fx.Context(), &GetExecutionRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -1137,7 +1143,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testCreate(t *testing.T) { t.Run("etag populated", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - created, _ := fx.service.CreateExecution(fx.Context(), &CreateExecutionRequest{ + created, _ := fx.Service().CreateExecution(fx.Context(), &CreateExecutionRequest{ Parent: parent, Execution: fx.Create(parent), }) @@ -1151,7 +1157,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) 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.GetExecution(fx.Context(), &GetExecutionRequest{ + _, err := fx.Service().GetExecution(fx.Context(), &GetExecutionRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1160,7 +1166,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) 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.GetExecution(fx.Context(), &GetExecutionRequest{ + _, err := fx.Service().GetExecution(fx.Context(), &GetExecutionRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1171,7 +1177,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetExecution(fx.Context(), &GetExecutionRequest{ + msg, err := fx.Service().GetExecution(fx.Context(), &GetExecutionRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1183,7 +1189,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetExecution(fx.Context(), &GetExecutionRequest{ + _, err := fx.Service().GetExecution(fx.Context(), &GetExecutionRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1192,7 +1198,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) 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.GetExecution(fx.Context(), &GetExecutionRequest{ + _, err := fx.Service().GetExecution(fx.Context(), &GetExecutionRequest{ Name: "projects/-/locations/-/metadataStores/-/executions/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1208,7 +1214,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateExecution(fx.Context(), &UpdateExecutionRequest{ + _, err := fx.Service().UpdateExecution(fx.Context(), &UpdateExecutionRequest{ Execution: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1220,7 +1226,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateExecution(fx.Context(), &UpdateExecutionRequest{ + _, err := fx.Service().UpdateExecution(fx.Context(), &UpdateExecutionRequest{ Execution: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1231,7 +1237,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateExecution(fx.Context(), &UpdateExecutionRequest{ + updated, err := fx.Service().UpdateExecution(fx.Context(), &UpdateExecutionRequest{ Execution: created, }) assert.NilError(t, err) @@ -1243,11 +1249,11 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateExecution(fx.Context(), &UpdateExecutionRequest{ + updated, err := fx.Service().UpdateExecution(fx.Context(), &UpdateExecutionRequest{ Execution: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetExecution(fx.Context(), &GetExecutionRequest{ + persisted, err := fx.Service().GetExecution(fx.Context(), &GetExecutionRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -1261,7 +1267,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateExecution(fx.Context(), &UpdateExecutionRequest{ + _, err := fx.Service().UpdateExecution(fx.Context(), &UpdateExecutionRequest{ Execution: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1270,7 +1276,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) 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.UpdateExecution(fx.Context(), &UpdateExecutionRequest{ + _, err := fx.Service().UpdateExecution(fx.Context(), &UpdateExecutionRequest{ Execution: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -1288,7 +1294,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) 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.ListExecutions(fx.Context(), &ListExecutionsRequest{ + _, err := fx.Service().ListExecutions(fx.Context(), &ListExecutionsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1298,7 +1304,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListExecutions(fx.Context(), &ListExecutionsRequest{ + _, err := fx.Service().ListExecutions(fx.Context(), &ListExecutionsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -1309,7 +1315,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListExecutions(fx.Context(), &ListExecutionsRequest{ + _, err := fx.Service().ListExecutions(fx.Context(), &ListExecutionsRequest{ Parent: parent, PageSize: -10, }) @@ -1327,7 +1333,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListExecutions(fx.Context(), &ListExecutionsRequest{ + response, err := fx.Service().ListExecutions(fx.Context(), &ListExecutionsRequest{ Parent: parent, PageSize: 999, }) @@ -1346,7 +1352,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) 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.ListExecutions(fx.Context(), &ListExecutionsRequest{ + response, err := fx.Service().ListExecutions(fx.Context(), &ListExecutionsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -1357,7 +1363,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) 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.ListExecutions(fx.Context(), &ListExecutionsRequest{ + response, err := fx.Service().ListExecutions(fx.Context(), &ListExecutionsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -1371,7 +1377,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Execution, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListExecutions(fx.Context(), &ListExecutionsRequest{ + response, err := fx.Service().ListExecutions(fx.Context(), &ListExecutionsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -1400,12 +1406,12 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteExecution(fx.Context(), &DeleteExecutionRequest{ + _, err := fx.Service().DeleteExecution(fx.Context(), &DeleteExecutionRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListExecutions(fx.Context(), &ListExecutionsRequest{ + response, err := fx.Service().ListExecutions(fx.Context(), &ListExecutionsRequest{ Parent: parent, PageSize: 9999, }) @@ -1428,7 +1434,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testDelete(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.DeleteExecution(fx.Context(), &DeleteExecutionRequest{ + _, err := fx.Service().DeleteExecution(fx.Context(), &DeleteExecutionRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1437,7 +1443,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testDelete(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.DeleteExecution(fx.Context(), &DeleteExecutionRequest{ + _, err := fx.Service().DeleteExecution(fx.Context(), &DeleteExecutionRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1448,7 +1454,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteExecution(fx.Context(), &DeleteExecutionRequest{ + _, err := fx.Service().DeleteExecution(fx.Context(), &DeleteExecutionRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1459,7 +1465,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteExecution(fx.Context(), &DeleteExecutionRequest{ + _, err := fx.Service().DeleteExecution(fx.Context(), &DeleteExecutionRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1470,12 +1476,12 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteExecution(fx.Context(), &DeleteExecutionRequest{ + deleted, err := fx.Service().DeleteExecution(fx.Context(), &DeleteExecutionRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteExecution(fx.Context(), &DeleteExecutionRequest{ + _, err = fx.Service().DeleteExecution(fx.Context(), &DeleteExecutionRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1484,7 +1490,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testDelete(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.DeleteExecution(fx.Context(), &DeleteExecutionRequest{ + _, err := fx.Service().DeleteExecution(fx.Context(), &DeleteExecutionRequest{ Name: "projects/-/locations/-/metadataStores/-/executions/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1495,7 +1501,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteExecution(fx.Context(), &DeleteExecutionRequest{ + _, err := fx.Service().DeleteExecution(fx.Context(), &DeleteExecutionRequest{ Name: created.Name, Etag: `"99999"`, }) @@ -1532,7 +1538,7 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *MetadataServiceExecutionTestSuiteConfig) create(t *testing.T, parent string) *Execution { t.Helper() - created, err := fx.service.CreateExecution(fx.Context(), &CreateExecutionRequest{ + created, err := fx.Service().CreateExecution(fx.Context(), &CreateExecutionRequest{ Parent: parent, Execution: fx.Create(parent), }) @@ -1541,9 +1547,11 @@ func (fx *MetadataServiceExecutionTestSuiteConfig) create(t *testing.T, parent s } type MetadataServiceMetadataSchemaTestSuiteConfig struct { - service MetadataServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() MetadataServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -1573,7 +1581,7 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) 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.CreateMetadataSchema(fx.Context(), &CreateMetadataSchemaRequest{ + _, err := fx.Service().CreateMetadataSchema(fx.Context(), &CreateMetadataSchemaRequest{ Parent: "", MetadataSchema: fx.Create(fx.nextParent(t, false)), }) @@ -1583,7 +1591,7 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) 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.CreateMetadataSchema(fx.Context(), &CreateMetadataSchemaRequest{ + _, err := fx.Service().CreateMetadataSchema(fx.Context(), &CreateMetadataSchemaRequest{ Parent: "invalid resource name", MetadataSchema: fx.Create(fx.nextParent(t, false)), }) @@ -1595,7 +1603,7 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) testCreate(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateMetadataSchema(fx.Context(), &CreateMetadataSchemaRequest{ + msg, err := fx.Service().CreateMetadataSchema(fx.Context(), &CreateMetadataSchemaRequest{ Parent: parent, MetadataSchema: fx.Create(parent), }) @@ -1609,12 +1617,12 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) testCreate(t *testing.T) t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateMetadataSchema(fx.Context(), &CreateMetadataSchemaRequest{ + msg, err := fx.Service().CreateMetadataSchema(fx.Context(), &CreateMetadataSchemaRequest{ Parent: parent, MetadataSchema: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetMetadataSchema(fx.Context(), &GetMetadataSchemaRequest{ + persisted, err := fx.Service().GetMetadataSchema(fx.Context(), &GetMetadataSchemaRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -1635,7 +1643,7 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("schema") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateMetadataSchema(fx.Context(), &CreateMetadataSchemaRequest{ + _, err := fx.Service().CreateMetadataSchema(fx.Context(), &CreateMetadataSchemaRequest{ Parent: parent, MetadataSchema: msg, }) @@ -1650,7 +1658,7 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) 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.GetMetadataSchema(fx.Context(), &GetMetadataSchemaRequest{ + _, err := fx.Service().GetMetadataSchema(fx.Context(), &GetMetadataSchemaRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1659,7 +1667,7 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) 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.GetMetadataSchema(fx.Context(), &GetMetadataSchemaRequest{ + _, err := fx.Service().GetMetadataSchema(fx.Context(), &GetMetadataSchemaRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1670,7 +1678,7 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetMetadataSchema(fx.Context(), &GetMetadataSchemaRequest{ + msg, err := fx.Service().GetMetadataSchema(fx.Context(), &GetMetadataSchemaRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1682,7 +1690,7 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetMetadataSchema(fx.Context(), &GetMetadataSchemaRequest{ + _, err := fx.Service().GetMetadataSchema(fx.Context(), &GetMetadataSchemaRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1691,7 +1699,7 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) 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.GetMetadataSchema(fx.Context(), &GetMetadataSchemaRequest{ + _, err := fx.Service().GetMetadataSchema(fx.Context(), &GetMetadataSchemaRequest{ Name: "projects/-/locations/-/metadataStores/-/metadataSchemas/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1704,7 +1712,7 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) 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.ListMetadataSchemas(fx.Context(), &ListMetadataSchemasRequest{ + _, err := fx.Service().ListMetadataSchemas(fx.Context(), &ListMetadataSchemasRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1714,7 +1722,7 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListMetadataSchemas(fx.Context(), &ListMetadataSchemasRequest{ + _, err := fx.Service().ListMetadataSchemas(fx.Context(), &ListMetadataSchemasRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -1725,7 +1733,7 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListMetadataSchemas(fx.Context(), &ListMetadataSchemasRequest{ + _, err := fx.Service().ListMetadataSchemas(fx.Context(), &ListMetadataSchemasRequest{ Parent: parent, PageSize: -10, }) @@ -1743,7 +1751,7 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListMetadataSchemas(fx.Context(), &ListMetadataSchemasRequest{ + response, err := fx.Service().ListMetadataSchemas(fx.Context(), &ListMetadataSchemasRequest{ Parent: parent, PageSize: 999, }) @@ -1762,7 +1770,7 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) 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.ListMetadataSchemas(fx.Context(), &ListMetadataSchemasRequest{ + response, err := fx.Service().ListMetadataSchemas(fx.Context(), &ListMetadataSchemasRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -1773,7 +1781,7 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) 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.ListMetadataSchemas(fx.Context(), &ListMetadataSchemasRequest{ + response, err := fx.Service().ListMetadataSchemas(fx.Context(), &ListMetadataSchemasRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -1787,7 +1795,7 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) testList(t *testing.T) { msgs := make([]*MetadataSchema, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListMetadataSchemas(fx.Context(), &ListMetadataSchemasRequest{ + response, err := fx.Service().ListMetadataSchemas(fx.Context(), &ListMetadataSchemasRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -1841,7 +1849,7 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) maybeSkip(t *testing.T) func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) create(t *testing.T, parent string) *MetadataSchema { t.Helper() - created, err := fx.service.CreateMetadataSchema(fx.Context(), &CreateMetadataSchemaRequest{ + created, err := fx.Service().CreateMetadataSchema(fx.Context(), &CreateMetadataSchemaRequest{ Parent: parent, MetadataSchema: fx.Create(parent), }) @@ -1850,9 +1858,11 @@ func (fx *MetadataServiceMetadataSchemaTestSuiteConfig) create(t *testing.T, par } type MetadataServiceMetadataStoreTestSuiteConfig struct { - service MetadataServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() MetadataServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -1883,7 +1893,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) 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.CreateMetadataStore(fx.Context(), &CreateMetadataStoreRequest{ + _, err := fx.Service().CreateMetadataStore(fx.Context(), &CreateMetadataStoreRequest{ Parent: "", MetadataStore: fx.Create(fx.nextParent(t, false)), }) @@ -1893,7 +1903,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) 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.CreateMetadataStore(fx.Context(), &CreateMetadataStoreRequest{ + _, err := fx.Service().CreateMetadataStore(fx.Context(), &CreateMetadataStoreRequest{ Parent: "invalid resource name", MetadataStore: fx.Create(fx.nextParent(t, false)), }) @@ -1914,7 +1924,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateMetadataStore(fx.Context(), &CreateMetadataStoreRequest{ + _, err := fx.Service().CreateMetadataStore(fx.Context(), &CreateMetadataStoreRequest{ Parent: parent, MetadataStore: msg, }) @@ -1929,7 +1939,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) 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.GetMetadataStore(fx.Context(), &GetMetadataStoreRequest{ + _, err := fx.Service().GetMetadataStore(fx.Context(), &GetMetadataStoreRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1938,7 +1948,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) 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.GetMetadataStore(fx.Context(), &GetMetadataStoreRequest{ + _, err := fx.Service().GetMetadataStore(fx.Context(), &GetMetadataStoreRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1949,7 +1959,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetMetadataStore(fx.Context(), &GetMetadataStoreRequest{ + msg, err := fx.Service().GetMetadataStore(fx.Context(), &GetMetadataStoreRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1961,7 +1971,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetMetadataStore(fx.Context(), &GetMetadataStoreRequest{ + _, err := fx.Service().GetMetadataStore(fx.Context(), &GetMetadataStoreRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1970,7 +1980,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) 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.GetMetadataStore(fx.Context(), &GetMetadataStoreRequest{ + _, err := fx.Service().GetMetadataStore(fx.Context(), &GetMetadataStoreRequest{ Name: "projects/-/locations/-/metadataStores/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1983,7 +1993,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) 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.ListMetadataStores(fx.Context(), &ListMetadataStoresRequest{ + _, err := fx.Service().ListMetadataStores(fx.Context(), &ListMetadataStoresRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1993,7 +2003,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListMetadataStores(fx.Context(), &ListMetadataStoresRequest{ + _, err := fx.Service().ListMetadataStores(fx.Context(), &ListMetadataStoresRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -2004,7 +2014,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListMetadataStores(fx.Context(), &ListMetadataStoresRequest{ + _, err := fx.Service().ListMetadataStores(fx.Context(), &ListMetadataStoresRequest{ Parent: parent, PageSize: -10, }) @@ -2022,7 +2032,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListMetadataStores(fx.Context(), &ListMetadataStoresRequest{ + response, err := fx.Service().ListMetadataStores(fx.Context(), &ListMetadataStoresRequest{ Parent: parent, PageSize: 999, }) @@ -2041,7 +2051,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) 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.ListMetadataStores(fx.Context(), &ListMetadataStoresRequest{ + response, err := fx.Service().ListMetadataStores(fx.Context(), &ListMetadataStoresRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -2052,7 +2062,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) 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.ListMetadataStores(fx.Context(), &ListMetadataStoresRequest{ + response, err := fx.Service().ListMetadataStores(fx.Context(), &ListMetadataStoresRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -2066,7 +2076,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) testList(t *testing.T) { msgs := make([]*MetadataStore, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListMetadataStores(fx.Context(), &ListMetadataStoresRequest{ + response, err := fx.Service().ListMetadataStores(fx.Context(), &ListMetadataStoresRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -2095,12 +2105,12 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteMetadataStore(fx.Context(), &DeleteMetadataStoreRequest{ + _, err := fx.Service().DeleteMetadataStore(fx.Context(), &DeleteMetadataStoreRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListMetadataStores(fx.Context(), &ListMetadataStoresRequest{ + response, err := fx.Service().ListMetadataStores(fx.Context(), &ListMetadataStoresRequest{ Parent: parent, PageSize: 9999, }) @@ -2123,7 +2133,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) testDelete(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.DeleteMetadataStore(fx.Context(), &DeleteMetadataStoreRequest{ + _, err := fx.Service().DeleteMetadataStore(fx.Context(), &DeleteMetadataStoreRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -2132,7 +2142,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) testDelete(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.DeleteMetadataStore(fx.Context(), &DeleteMetadataStoreRequest{ + _, err := fx.Service().DeleteMetadataStore(fx.Context(), &DeleteMetadataStoreRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -2143,7 +2153,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteMetadataStore(fx.Context(), &DeleteMetadataStoreRequest{ + _, err := fx.Service().DeleteMetadataStore(fx.Context(), &DeleteMetadataStoreRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -2154,7 +2164,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteMetadataStore(fx.Context(), &DeleteMetadataStoreRequest{ + _, err := fx.Service().DeleteMetadataStore(fx.Context(), &DeleteMetadataStoreRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -2165,12 +2175,12 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteMetadataStore(fx.Context(), &DeleteMetadataStoreRequest{ + deleted, err := fx.Service().DeleteMetadataStore(fx.Context(), &DeleteMetadataStoreRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteMetadataStore(fx.Context(), &DeleteMetadataStoreRequest{ + _, err = fx.Service().DeleteMetadataStore(fx.Context(), &DeleteMetadataStoreRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -2179,7 +2189,7 @@ func (fx *MetadataServiceMetadataStoreTestSuiteConfig) testDelete(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.DeleteMetadataStore(fx.Context(), &DeleteMetadataStoreRequest{ + _, err := fx.Service().DeleteMetadataStore(fx.Context(), &DeleteMetadataStoreRequest{ Name: "projects/-/locations/-/metadataStores/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) diff --git a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/model_garden_service_aiptest.pb.go b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/model_garden_service_aiptest.pb.go index 17f6437..f5ffe72 100644 --- a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/model_garden_service_aiptest.pb.go +++ b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/model_garden_service_aiptest.pb.go @@ -21,15 +21,17 @@ type ModelGardenServiceTestSuite struct { func (fx ModelGardenServiceTestSuite) TestPublisherModel(ctx context.Context, options ModelGardenServicePublisherModelTestSuiteConfig) { fx.T.Run("PublisherModel", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() ModelGardenServiceServer { return fx.Server } options.test(t) }) } type ModelGardenServicePublisherModelTestSuiteConfig struct { - service ModelGardenServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() ModelGardenServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -60,7 +62,7 @@ func (fx *ModelGardenServicePublisherModelTestSuiteConfig) 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.GetPublisherModel(fx.Context(), &GetPublisherModelRequest{ + _, err := fx.Service().GetPublisherModel(fx.Context(), &GetPublisherModelRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -69,7 +71,7 @@ func (fx *ModelGardenServicePublisherModelTestSuiteConfig) 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.GetPublisherModel(fx.Context(), &GetPublisherModelRequest{ + _, err := fx.Service().GetPublisherModel(fx.Context(), &GetPublisherModelRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -80,7 +82,7 @@ func (fx *ModelGardenServicePublisherModelTestSuiteConfig) testGet(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetPublisherModel(fx.Context(), &GetPublisherModelRequest{ + msg, err := fx.Service().GetPublisherModel(fx.Context(), &GetPublisherModelRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -92,7 +94,7 @@ func (fx *ModelGardenServicePublisherModelTestSuiteConfig) testGet(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetPublisherModel(fx.Context(), &GetPublisherModelRequest{ + _, err := fx.Service().GetPublisherModel(fx.Context(), &GetPublisherModelRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -101,7 +103,7 @@ func (fx *ModelGardenServicePublisherModelTestSuiteConfig) 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.GetPublisherModel(fx.Context(), &GetPublisherModelRequest{ + _, err := fx.Service().GetPublisherModel(fx.Context(), &GetPublisherModelRequest{ Name: "publishers/-/models/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) diff --git a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/model_service_aiptest.pb.go b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/model_service_aiptest.pb.go index 8145c8a..40bf751 100644 --- a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/model_service_aiptest.pb.go +++ b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/model_service_aiptest.pb.go @@ -24,7 +24,7 @@ type ModelServiceTestSuite struct { func (fx ModelServiceTestSuite) TestModel(ctx context.Context, options ModelServiceModelTestSuiteConfig) { fx.T.Run("Model", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() ModelServiceServer { return fx.Server } options.test(t) }) } @@ -32,7 +32,7 @@ func (fx ModelServiceTestSuite) TestModel(ctx context.Context, options ModelServ func (fx ModelServiceTestSuite) TestModelEvaluation(ctx context.Context, options ModelServiceModelEvaluationTestSuiteConfig) { fx.T.Run("ModelEvaluation", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() ModelServiceServer { return fx.Server } options.test(t) }) } @@ -40,15 +40,17 @@ func (fx ModelServiceTestSuite) TestModelEvaluation(ctx context.Context, options func (fx ModelServiceTestSuite) TestModelEvaluationSlice(ctx context.Context, options ModelServiceModelEvaluationSliceTestSuiteConfig) { fx.T.Run("ModelEvaluationSlice", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() ModelServiceServer { return fx.Server } options.test(t) }) } type ModelServiceModelTestSuiteConfig struct { - service ModelServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() ModelServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -85,7 +87,7 @@ func (fx *ModelServiceModelTestSuiteConfig) 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.GetModel(fx.Context(), &GetModelRequest{ + _, err := fx.Service().GetModel(fx.Context(), &GetModelRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -94,7 +96,7 @@ func (fx *ModelServiceModelTestSuiteConfig) 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.GetModel(fx.Context(), &GetModelRequest{ + _, err := fx.Service().GetModel(fx.Context(), &GetModelRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -105,7 +107,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetModel(fx.Context(), &GetModelRequest{ + msg, err := fx.Service().GetModel(fx.Context(), &GetModelRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -117,7 +119,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetModel(fx.Context(), &GetModelRequest{ + _, err := fx.Service().GetModel(fx.Context(), &GetModelRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -126,7 +128,7 @@ func (fx *ModelServiceModelTestSuiteConfig) 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.GetModel(fx.Context(), &GetModelRequest{ + _, err := fx.Service().GetModel(fx.Context(), &GetModelRequest{ Name: "projects/-/locations/-/models/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -142,7 +144,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateModel(fx.Context(), &UpdateModelRequest{ + _, err := fx.Service().UpdateModel(fx.Context(), &UpdateModelRequest{ Model: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -154,7 +156,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateModel(fx.Context(), &UpdateModelRequest{ + _, err := fx.Service().UpdateModel(fx.Context(), &UpdateModelRequest{ Model: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -165,11 +167,11 @@ func (fx *ModelServiceModelTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateModel(fx.Context(), &UpdateModelRequest{ + updated, err := fx.Service().UpdateModel(fx.Context(), &UpdateModelRequest{ Model: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetModel(fx.Context(), &GetModelRequest{ + persisted, err := fx.Service().GetModel(fx.Context(), &GetModelRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -182,7 +184,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) created := fx.create(t, parent) originalCreateTime := created.CreateTime - updated, err := fx.service.UpdateModel(fx.Context(), &UpdateModelRequest{ + updated, err := fx.Service().UpdateModel(fx.Context(), &UpdateModelRequest{ Model: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -201,7 +203,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateModel(fx.Context(), &UpdateModelRequest{ + _, err := fx.Service().UpdateModel(fx.Context(), &UpdateModelRequest{ Model: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -210,7 +212,7 @@ func (fx *ModelServiceModelTestSuiteConfig) 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.UpdateModel(fx.Context(), &UpdateModelRequest{ + _, err := fx.Service().UpdateModel(fx.Context(), &UpdateModelRequest{ Model: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -234,7 +236,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateModel(fx.Context(), &UpdateModelRequest{ + _, err := fx.Service().UpdateModel(fx.Context(), &UpdateModelRequest{ Model: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -253,7 +255,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("parameters") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateModel(fx.Context(), &UpdateModelRequest{ + _, err := fx.Service().UpdateModel(fx.Context(), &UpdateModelRequest{ Model: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -272,7 +274,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("path_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateModel(fx.Context(), &UpdateModelRequest{ + _, err := fx.Service().UpdateModel(fx.Context(), &UpdateModelRequest{ Model: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -291,7 +293,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("step_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateModel(fx.Context(), &UpdateModelRequest{ + _, err := fx.Service().UpdateModel(fx.Context(), &UpdateModelRequest{ Model: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -310,7 +312,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("step_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateModel(fx.Context(), &UpdateModelRequest{ + _, err := fx.Service().UpdateModel(fx.Context(), &UpdateModelRequest{ Model: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -329,7 +331,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("uris") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateModel(fx.Context(), &UpdateModelRequest{ + _, err := fx.Service().UpdateModel(fx.Context(), &UpdateModelRequest{ Model: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -348,7 +350,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("inputs") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateModel(fx.Context(), &UpdateModelRequest{ + _, err := fx.Service().UpdateModel(fx.Context(), &UpdateModelRequest{ Model: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -367,7 +369,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("outputs") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateModel(fx.Context(), &UpdateModelRequest{ + _, err := fx.Service().UpdateModel(fx.Context(), &UpdateModelRequest{ Model: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -386,7 +388,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateModel(fx.Context(), &UpdateModelRequest{ + _, err := fx.Service().UpdateModel(fx.Context(), &UpdateModelRequest{ Model: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -405,7 +407,7 @@ func (fx *ModelServiceModelTestSuiteConfig) 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.ListModels(fx.Context(), &ListModelsRequest{ + _, err := fx.Service().ListModels(fx.Context(), &ListModelsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -415,7 +417,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListModels(fx.Context(), &ListModelsRequest{ + _, err := fx.Service().ListModels(fx.Context(), &ListModelsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -426,7 +428,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListModels(fx.Context(), &ListModelsRequest{ + _, err := fx.Service().ListModels(fx.Context(), &ListModelsRequest{ Parent: parent, PageSize: -10, }) @@ -444,7 +446,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListModels(fx.Context(), &ListModelsRequest{ + response, err := fx.Service().ListModels(fx.Context(), &ListModelsRequest{ Parent: parent, PageSize: 999, }) @@ -463,7 +465,7 @@ func (fx *ModelServiceModelTestSuiteConfig) 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.ListModels(fx.Context(), &ListModelsRequest{ + response, err := fx.Service().ListModels(fx.Context(), &ListModelsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -474,7 +476,7 @@ func (fx *ModelServiceModelTestSuiteConfig) 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.ListModels(fx.Context(), &ListModelsRequest{ + response, err := fx.Service().ListModels(fx.Context(), &ListModelsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -488,7 +490,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Model, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListModels(fx.Context(), &ListModelsRequest{ + response, err := fx.Service().ListModels(fx.Context(), &ListModelsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -517,12 +519,12 @@ func (fx *ModelServiceModelTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteModel(fx.Context(), &DeleteModelRequest{ + _, err := fx.Service().DeleteModel(fx.Context(), &DeleteModelRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListModels(fx.Context(), &ListModelsRequest{ + response, err := fx.Service().ListModels(fx.Context(), &ListModelsRequest{ Parent: parent, PageSize: 9999, }) @@ -545,7 +547,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testDelete(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.DeleteModel(fx.Context(), &DeleteModelRequest{ + _, err := fx.Service().DeleteModel(fx.Context(), &DeleteModelRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -554,7 +556,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testDelete(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.DeleteModel(fx.Context(), &DeleteModelRequest{ + _, err := fx.Service().DeleteModel(fx.Context(), &DeleteModelRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -565,7 +567,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteModel(fx.Context(), &DeleteModelRequest{ + _, err := fx.Service().DeleteModel(fx.Context(), &DeleteModelRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -576,7 +578,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteModel(fx.Context(), &DeleteModelRequest{ + _, err := fx.Service().DeleteModel(fx.Context(), &DeleteModelRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -587,12 +589,12 @@ func (fx *ModelServiceModelTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteModel(fx.Context(), &DeleteModelRequest{ + deleted, err := fx.Service().DeleteModel(fx.Context(), &DeleteModelRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteModel(fx.Context(), &DeleteModelRequest{ + _, err = fx.Service().DeleteModel(fx.Context(), &DeleteModelRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -601,7 +603,7 @@ func (fx *ModelServiceModelTestSuiteConfig) testDelete(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.DeleteModel(fx.Context(), &DeleteModelRequest{ + _, err := fx.Service().DeleteModel(fx.Context(), &DeleteModelRequest{ Name: "projects/-/locations/-/models/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -646,9 +648,11 @@ func (fx *ModelServiceModelTestSuiteConfig) create(t *testing.T, parent string) } type ModelServiceModelEvaluationTestSuiteConfig struct { - service ModelServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() ModelServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -680,7 +684,7 @@ func (fx *ModelServiceModelEvaluationTestSuiteConfig) 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.GetModelEvaluation(fx.Context(), &GetModelEvaluationRequest{ + _, err := fx.Service().GetModelEvaluation(fx.Context(), &GetModelEvaluationRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -689,7 +693,7 @@ func (fx *ModelServiceModelEvaluationTestSuiteConfig) 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.GetModelEvaluation(fx.Context(), &GetModelEvaluationRequest{ + _, err := fx.Service().GetModelEvaluation(fx.Context(), &GetModelEvaluationRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -700,7 +704,7 @@ func (fx *ModelServiceModelEvaluationTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetModelEvaluation(fx.Context(), &GetModelEvaluationRequest{ + msg, err := fx.Service().GetModelEvaluation(fx.Context(), &GetModelEvaluationRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -712,7 +716,7 @@ func (fx *ModelServiceModelEvaluationTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetModelEvaluation(fx.Context(), &GetModelEvaluationRequest{ + _, err := fx.Service().GetModelEvaluation(fx.Context(), &GetModelEvaluationRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -721,7 +725,7 @@ func (fx *ModelServiceModelEvaluationTestSuiteConfig) 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.GetModelEvaluation(fx.Context(), &GetModelEvaluationRequest{ + _, err := fx.Service().GetModelEvaluation(fx.Context(), &GetModelEvaluationRequest{ Name: "projects/-/locations/-/models/-/evaluations/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -734,7 +738,7 @@ func (fx *ModelServiceModelEvaluationTestSuiteConfig) 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.ListModelEvaluations(fx.Context(), &ListModelEvaluationsRequest{ + _, err := fx.Service().ListModelEvaluations(fx.Context(), &ListModelEvaluationsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -744,7 +748,7 @@ func (fx *ModelServiceModelEvaluationTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListModelEvaluations(fx.Context(), &ListModelEvaluationsRequest{ + _, err := fx.Service().ListModelEvaluations(fx.Context(), &ListModelEvaluationsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -755,7 +759,7 @@ func (fx *ModelServiceModelEvaluationTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListModelEvaluations(fx.Context(), &ListModelEvaluationsRequest{ + _, err := fx.Service().ListModelEvaluations(fx.Context(), &ListModelEvaluationsRequest{ Parent: parent, PageSize: -10, }) @@ -773,7 +777,7 @@ func (fx *ModelServiceModelEvaluationTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListModelEvaluations(fx.Context(), &ListModelEvaluationsRequest{ + response, err := fx.Service().ListModelEvaluations(fx.Context(), &ListModelEvaluationsRequest{ Parent: parent, PageSize: 999, }) @@ -792,7 +796,7 @@ func (fx *ModelServiceModelEvaluationTestSuiteConfig) 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.ListModelEvaluations(fx.Context(), &ListModelEvaluationsRequest{ + response, err := fx.Service().ListModelEvaluations(fx.Context(), &ListModelEvaluationsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -803,7 +807,7 @@ func (fx *ModelServiceModelEvaluationTestSuiteConfig) 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.ListModelEvaluations(fx.Context(), &ListModelEvaluationsRequest{ + response, err := fx.Service().ListModelEvaluations(fx.Context(), &ListModelEvaluationsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -817,7 +821,7 @@ func (fx *ModelServiceModelEvaluationTestSuiteConfig) testList(t *testing.T) { msgs := make([]*ModelEvaluation, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListModelEvaluations(fx.Context(), &ListModelEvaluationsRequest{ + response, err := fx.Service().ListModelEvaluations(fx.Context(), &ListModelEvaluationsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -880,9 +884,11 @@ func (fx *ModelServiceModelEvaluationTestSuiteConfig) create(t *testing.T, paren } type ModelServiceModelEvaluationSliceTestSuiteConfig struct { - service ModelServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() ModelServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -914,7 +920,7 @@ func (fx *ModelServiceModelEvaluationSliceTestSuiteConfig) 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.GetModelEvaluationSlice(fx.Context(), &GetModelEvaluationSliceRequest{ + _, err := fx.Service().GetModelEvaluationSlice(fx.Context(), &GetModelEvaluationSliceRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -923,7 +929,7 @@ func (fx *ModelServiceModelEvaluationSliceTestSuiteConfig) 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.GetModelEvaluationSlice(fx.Context(), &GetModelEvaluationSliceRequest{ + _, err := fx.Service().GetModelEvaluationSlice(fx.Context(), &GetModelEvaluationSliceRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -934,7 +940,7 @@ func (fx *ModelServiceModelEvaluationSliceTestSuiteConfig) testGet(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetModelEvaluationSlice(fx.Context(), &GetModelEvaluationSliceRequest{ + msg, err := fx.Service().GetModelEvaluationSlice(fx.Context(), &GetModelEvaluationSliceRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -946,7 +952,7 @@ func (fx *ModelServiceModelEvaluationSliceTestSuiteConfig) testGet(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetModelEvaluationSlice(fx.Context(), &GetModelEvaluationSliceRequest{ + _, err := fx.Service().GetModelEvaluationSlice(fx.Context(), &GetModelEvaluationSliceRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -955,7 +961,7 @@ func (fx *ModelServiceModelEvaluationSliceTestSuiteConfig) 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.GetModelEvaluationSlice(fx.Context(), &GetModelEvaluationSliceRequest{ + _, err := fx.Service().GetModelEvaluationSlice(fx.Context(), &GetModelEvaluationSliceRequest{ Name: "projects/-/locations/-/models/-/evaluations/-/slices/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -968,7 +974,7 @@ func (fx *ModelServiceModelEvaluationSliceTestSuiteConfig) 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.ListModelEvaluationSlices(fx.Context(), &ListModelEvaluationSlicesRequest{ + _, err := fx.Service().ListModelEvaluationSlices(fx.Context(), &ListModelEvaluationSlicesRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -978,7 +984,7 @@ func (fx *ModelServiceModelEvaluationSliceTestSuiteConfig) testList(t *testing.T t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListModelEvaluationSlices(fx.Context(), &ListModelEvaluationSlicesRequest{ + _, err := fx.Service().ListModelEvaluationSlices(fx.Context(), &ListModelEvaluationSlicesRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -989,7 +995,7 @@ func (fx *ModelServiceModelEvaluationSliceTestSuiteConfig) testList(t *testing.T t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListModelEvaluationSlices(fx.Context(), &ListModelEvaluationSlicesRequest{ + _, err := fx.Service().ListModelEvaluationSlices(fx.Context(), &ListModelEvaluationSlicesRequest{ Parent: parent, PageSize: -10, }) @@ -1007,7 +1013,7 @@ func (fx *ModelServiceModelEvaluationSliceTestSuiteConfig) testList(t *testing.T // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListModelEvaluationSlices(fx.Context(), &ListModelEvaluationSlicesRequest{ + response, err := fx.Service().ListModelEvaluationSlices(fx.Context(), &ListModelEvaluationSlicesRequest{ Parent: parent, PageSize: 999, }) @@ -1026,7 +1032,7 @@ func (fx *ModelServiceModelEvaluationSliceTestSuiteConfig) 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.ListModelEvaluationSlices(fx.Context(), &ListModelEvaluationSlicesRequest{ + response, err := fx.Service().ListModelEvaluationSlices(fx.Context(), &ListModelEvaluationSlicesRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -1037,7 +1043,7 @@ func (fx *ModelServiceModelEvaluationSliceTestSuiteConfig) 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.ListModelEvaluationSlices(fx.Context(), &ListModelEvaluationSlicesRequest{ + response, err := fx.Service().ListModelEvaluationSlices(fx.Context(), &ListModelEvaluationSlicesRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -1051,7 +1057,7 @@ func (fx *ModelServiceModelEvaluationSliceTestSuiteConfig) testList(t *testing.T msgs := make([]*ModelEvaluationSlice, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListModelEvaluationSlices(fx.Context(), &ListModelEvaluationSlicesRequest{ + response, err := fx.Service().ListModelEvaluationSlices(fx.Context(), &ListModelEvaluationSlicesRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, diff --git a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/pipeline_service_aiptest.pb.go b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/pipeline_service_aiptest.pb.go index 6f78328..a8188c8 100644 --- a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/pipeline_service_aiptest.pb.go +++ b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/pipeline_service_aiptest.pb.go @@ -23,7 +23,7 @@ type PipelineServiceTestSuite struct { func (fx PipelineServiceTestSuite) TestPipelineJob(ctx context.Context, options PipelineServicePipelineJobTestSuiteConfig) { fx.T.Run("PipelineJob", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() PipelineServiceServer { return fx.Server } options.test(t) }) } @@ -31,15 +31,17 @@ func (fx PipelineServiceTestSuite) TestPipelineJob(ctx context.Context, options func (fx PipelineServiceTestSuite) TestTrainingPipeline(ctx context.Context, options PipelineServiceTrainingPipelineTestSuiteConfig) { fx.T.Run("TrainingPipeline", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() PipelineServiceServer { return fx.Server } options.test(t) }) } type PipelineServicePipelineJobTestSuiteConfig struct { - service PipelineServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() PipelineServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -70,7 +72,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) 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.CreatePipelineJob(fx.Context(), &CreatePipelineJobRequest{ + _, err := fx.Service().CreatePipelineJob(fx.Context(), &CreatePipelineJobRequest{ Parent: "", PipelineJob: fx.Create(fx.nextParent(t, false)), }) @@ -80,7 +82,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) 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.CreatePipelineJob(fx.Context(), &CreatePipelineJobRequest{ + _, err := fx.Service().CreatePipelineJob(fx.Context(), &CreatePipelineJobRequest{ Parent: "invalid resource name", PipelineJob: fx.Create(fx.nextParent(t, false)), }) @@ -92,7 +94,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testCreate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreatePipelineJob(fx.Context(), &CreatePipelineJobRequest{ + msg, err := fx.Service().CreatePipelineJob(fx.Context(), &CreatePipelineJobRequest{ Parent: parent, PipelineJob: fx.Create(parent), }) @@ -106,12 +108,12 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testCreate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreatePipelineJob(fx.Context(), &CreatePipelineJobRequest{ + msg, err := fx.Service().CreatePipelineJob(fx.Context(), &CreatePipelineJobRequest{ Parent: parent, PipelineJob: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetPipelineJob(fx.Context(), &GetPipelineJobRequest{ + persisted, err := fx.Service().GetPipelineJob(fx.Context(), &GetPipelineJobRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -132,7 +134,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("gcs_output_directory") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreatePipelineJob(fx.Context(), &CreatePipelineJobRequest{ + _, err := fx.Service().CreatePipelineJob(fx.Context(), &CreatePipelineJobRequest{ Parent: parent, PipelineJob: msg, }) @@ -148,7 +150,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreatePipelineJob(fx.Context(), &CreatePipelineJobRequest{ + _, err := fx.Service().CreatePipelineJob(fx.Context(), &CreatePipelineJobRequest{ Parent: parent, PipelineJob: msg, }) @@ -169,7 +171,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Network = "invalid resource name" - _, err := fx.service.CreatePipelineJob(fx.Context(), &CreatePipelineJobRequest{ + _, err := fx.Service().CreatePipelineJob(fx.Context(), &CreatePipelineJobRequest{ Parent: parent, PipelineJob: msg, }) @@ -184,7 +186,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) 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.GetPipelineJob(fx.Context(), &GetPipelineJobRequest{ + _, err := fx.Service().GetPipelineJob(fx.Context(), &GetPipelineJobRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -193,7 +195,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) 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.GetPipelineJob(fx.Context(), &GetPipelineJobRequest{ + _, err := fx.Service().GetPipelineJob(fx.Context(), &GetPipelineJobRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -204,7 +206,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetPipelineJob(fx.Context(), &GetPipelineJobRequest{ + msg, err := fx.Service().GetPipelineJob(fx.Context(), &GetPipelineJobRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -216,7 +218,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetPipelineJob(fx.Context(), &GetPipelineJobRequest{ + _, err := fx.Service().GetPipelineJob(fx.Context(), &GetPipelineJobRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -225,7 +227,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) 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.GetPipelineJob(fx.Context(), &GetPipelineJobRequest{ + _, err := fx.Service().GetPipelineJob(fx.Context(), &GetPipelineJobRequest{ Name: "projects/-/locations/-/pipelineJobs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -238,7 +240,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) 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.ListPipelineJobs(fx.Context(), &ListPipelineJobsRequest{ + _, err := fx.Service().ListPipelineJobs(fx.Context(), &ListPipelineJobsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -248,7 +250,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListPipelineJobs(fx.Context(), &ListPipelineJobsRequest{ + _, err := fx.Service().ListPipelineJobs(fx.Context(), &ListPipelineJobsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -259,7 +261,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListPipelineJobs(fx.Context(), &ListPipelineJobsRequest{ + _, err := fx.Service().ListPipelineJobs(fx.Context(), &ListPipelineJobsRequest{ Parent: parent, PageSize: -10, }) @@ -277,7 +279,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListPipelineJobs(fx.Context(), &ListPipelineJobsRequest{ + response, err := fx.Service().ListPipelineJobs(fx.Context(), &ListPipelineJobsRequest{ Parent: parent, PageSize: 999, }) @@ -296,7 +298,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) 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.ListPipelineJobs(fx.Context(), &ListPipelineJobsRequest{ + response, err := fx.Service().ListPipelineJobs(fx.Context(), &ListPipelineJobsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -307,7 +309,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) 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.ListPipelineJobs(fx.Context(), &ListPipelineJobsRequest{ + response, err := fx.Service().ListPipelineJobs(fx.Context(), &ListPipelineJobsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -321,7 +323,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testList(t *testing.T) { msgs := make([]*PipelineJob, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListPipelineJobs(fx.Context(), &ListPipelineJobsRequest{ + response, err := fx.Service().ListPipelineJobs(fx.Context(), &ListPipelineJobsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -350,12 +352,12 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeletePipelineJob(fx.Context(), &DeletePipelineJobRequest{ + _, err := fx.Service().DeletePipelineJob(fx.Context(), &DeletePipelineJobRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListPipelineJobs(fx.Context(), &ListPipelineJobsRequest{ + response, err := fx.Service().ListPipelineJobs(fx.Context(), &ListPipelineJobsRequest{ Parent: parent, PageSize: 9999, }) @@ -378,7 +380,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testDelete(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.DeletePipelineJob(fx.Context(), &DeletePipelineJobRequest{ + _, err := fx.Service().DeletePipelineJob(fx.Context(), &DeletePipelineJobRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -387,7 +389,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testDelete(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.DeletePipelineJob(fx.Context(), &DeletePipelineJobRequest{ + _, err := fx.Service().DeletePipelineJob(fx.Context(), &DeletePipelineJobRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -398,7 +400,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeletePipelineJob(fx.Context(), &DeletePipelineJobRequest{ + _, err := fx.Service().DeletePipelineJob(fx.Context(), &DeletePipelineJobRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -409,7 +411,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeletePipelineJob(fx.Context(), &DeletePipelineJobRequest{ + _, err := fx.Service().DeletePipelineJob(fx.Context(), &DeletePipelineJobRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -420,12 +422,12 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeletePipelineJob(fx.Context(), &DeletePipelineJobRequest{ + deleted, err := fx.Service().DeletePipelineJob(fx.Context(), &DeletePipelineJobRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeletePipelineJob(fx.Context(), &DeletePipelineJobRequest{ + _, err = fx.Service().DeletePipelineJob(fx.Context(), &DeletePipelineJobRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -434,7 +436,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) testDelete(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.DeletePipelineJob(fx.Context(), &DeletePipelineJobRequest{ + _, err := fx.Service().DeletePipelineJob(fx.Context(), &DeletePipelineJobRequest{ Name: "projects/-/locations/-/pipelineJobs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -470,7 +472,7 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *PipelineServicePipelineJobTestSuiteConfig) create(t *testing.T, parent string) *PipelineJob { t.Helper() - created, err := fx.service.CreatePipelineJob(fx.Context(), &CreatePipelineJobRequest{ + created, err := fx.Service().CreatePipelineJob(fx.Context(), &CreatePipelineJobRequest{ Parent: parent, PipelineJob: fx.Create(parent), }) @@ -479,9 +481,11 @@ func (fx *PipelineServicePipelineJobTestSuiteConfig) create(t *testing.T, parent } type PipelineServiceTrainingPipelineTestSuiteConfig struct { - service PipelineServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() PipelineServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -512,7 +516,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. // Method should fail with InvalidArgument if no parent is provided. t.Run("missing parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: "", TrainingPipeline: fx.Create(fx.nextParent(t, false)), }) @@ -522,7 +526,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: "invalid resource name", TrainingPipeline: fx.Create(fx.nextParent(t, false)), }) @@ -534,7 +538,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + msg, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: fx.Create(parent), }) @@ -548,12 +552,12 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + msg, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetTrainingPipeline(fx.Context(), &GetTrainingPipelineRequest{ + persisted, err := fx.Service().GetTrainingPipeline(fx.Context(), &GetTrainingPipelineRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -574,7 +578,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -590,7 +594,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("training_filter") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -606,7 +610,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("validation_filter") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -622,7 +626,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("test_filter") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -638,7 +642,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("key") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -654,7 +658,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("key") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -670,7 +674,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("key") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -686,7 +690,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("output_uri_prefix") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -702,7 +706,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("output_uri") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -718,7 +722,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("dataset_id") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -734,7 +738,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("training_task_definition") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -750,7 +754,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("training_task_inputs") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -766,7 +770,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -782,7 +786,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("image_uri") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -798,7 +802,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("parameters") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -814,7 +818,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("path_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -830,7 +834,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("step_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -846,7 +850,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("step_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -862,7 +866,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("uris") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -878,7 +882,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("inputs") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -894,7 +898,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("outputs") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -910,7 +914,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -931,7 +935,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testCreate(t *testing. t.Skip("not reachable") } container.PipelineJob = "invalid resource name" - _, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + _, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: msg, }) @@ -946,7 +950,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) 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.GetTrainingPipeline(fx.Context(), &GetTrainingPipelineRequest{ + _, err := fx.Service().GetTrainingPipeline(fx.Context(), &GetTrainingPipelineRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -955,7 +959,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) 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.GetTrainingPipeline(fx.Context(), &GetTrainingPipelineRequest{ + _, err := fx.Service().GetTrainingPipeline(fx.Context(), &GetTrainingPipelineRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -966,7 +970,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testGet(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetTrainingPipeline(fx.Context(), &GetTrainingPipelineRequest{ + msg, err := fx.Service().GetTrainingPipeline(fx.Context(), &GetTrainingPipelineRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -978,7 +982,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testGet(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetTrainingPipeline(fx.Context(), &GetTrainingPipelineRequest{ + _, err := fx.Service().GetTrainingPipeline(fx.Context(), &GetTrainingPipelineRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -987,7 +991,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) 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.GetTrainingPipeline(fx.Context(), &GetTrainingPipelineRequest{ + _, err := fx.Service().GetTrainingPipeline(fx.Context(), &GetTrainingPipelineRequest{ Name: "projects/-/locations/-/trainingPipelines/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1000,7 +1004,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) 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.ListTrainingPipelines(fx.Context(), &ListTrainingPipelinesRequest{ + _, err := fx.Service().ListTrainingPipelines(fx.Context(), &ListTrainingPipelinesRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1010,7 +1014,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testList(t *testing.T) t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListTrainingPipelines(fx.Context(), &ListTrainingPipelinesRequest{ + _, err := fx.Service().ListTrainingPipelines(fx.Context(), &ListTrainingPipelinesRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -1021,7 +1025,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testList(t *testing.T) t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListTrainingPipelines(fx.Context(), &ListTrainingPipelinesRequest{ + _, err := fx.Service().ListTrainingPipelines(fx.Context(), &ListTrainingPipelinesRequest{ Parent: parent, PageSize: -10, }) @@ -1039,7 +1043,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testList(t *testing.T) // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListTrainingPipelines(fx.Context(), &ListTrainingPipelinesRequest{ + response, err := fx.Service().ListTrainingPipelines(fx.Context(), &ListTrainingPipelinesRequest{ Parent: parent, PageSize: 999, }) @@ -1058,7 +1062,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) 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.ListTrainingPipelines(fx.Context(), &ListTrainingPipelinesRequest{ + response, err := fx.Service().ListTrainingPipelines(fx.Context(), &ListTrainingPipelinesRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -1069,7 +1073,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) 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.ListTrainingPipelines(fx.Context(), &ListTrainingPipelinesRequest{ + response, err := fx.Service().ListTrainingPipelines(fx.Context(), &ListTrainingPipelinesRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -1083,7 +1087,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testList(t *testing.T) msgs := make([]*TrainingPipeline, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListTrainingPipelines(fx.Context(), &ListTrainingPipelinesRequest{ + response, err := fx.Service().ListTrainingPipelines(fx.Context(), &ListTrainingPipelinesRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -1112,12 +1116,12 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testList(t *testing.T) fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteTrainingPipeline(fx.Context(), &DeleteTrainingPipelineRequest{ + _, err := fx.Service().DeleteTrainingPipeline(fx.Context(), &DeleteTrainingPipelineRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListTrainingPipelines(fx.Context(), &ListTrainingPipelinesRequest{ + response, err := fx.Service().ListTrainingPipelines(fx.Context(), &ListTrainingPipelinesRequest{ Parent: parent, PageSize: 9999, }) @@ -1140,7 +1144,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testDelete(t *testing. // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.DeleteTrainingPipeline(fx.Context(), &DeleteTrainingPipelineRequest{ + _, err := fx.Service().DeleteTrainingPipeline(fx.Context(), &DeleteTrainingPipelineRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1149,7 +1153,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testDelete(t *testing. // 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.DeleteTrainingPipeline(fx.Context(), &DeleteTrainingPipelineRequest{ + _, err := fx.Service().DeleteTrainingPipeline(fx.Context(), &DeleteTrainingPipelineRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1160,7 +1164,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testDelete(t *testing. fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteTrainingPipeline(fx.Context(), &DeleteTrainingPipelineRequest{ + _, err := fx.Service().DeleteTrainingPipeline(fx.Context(), &DeleteTrainingPipelineRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1171,7 +1175,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testDelete(t *testing. fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteTrainingPipeline(fx.Context(), &DeleteTrainingPipelineRequest{ + _, err := fx.Service().DeleteTrainingPipeline(fx.Context(), &DeleteTrainingPipelineRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1182,12 +1186,12 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testDelete(t *testing. fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteTrainingPipeline(fx.Context(), &DeleteTrainingPipelineRequest{ + deleted, err := fx.Service().DeleteTrainingPipeline(fx.Context(), &DeleteTrainingPipelineRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteTrainingPipeline(fx.Context(), &DeleteTrainingPipelineRequest{ + _, err = fx.Service().DeleteTrainingPipeline(fx.Context(), &DeleteTrainingPipelineRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1196,7 +1200,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) testDelete(t *testing. // 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.DeleteTrainingPipeline(fx.Context(), &DeleteTrainingPipelineRequest{ + _, err := fx.Service().DeleteTrainingPipeline(fx.Context(), &DeleteTrainingPipelineRequest{ Name: "projects/-/locations/-/trainingPipelines/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1232,7 +1236,7 @@ func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) maybeSkip(t *testing.T func (fx *PipelineServiceTrainingPipelineTestSuiteConfig) create(t *testing.T, parent string) *TrainingPipeline { t.Helper() - created, err := fx.service.CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ + created, err := fx.Service().CreateTrainingPipeline(fx.Context(), &CreateTrainingPipelineRequest{ Parent: parent, TrainingPipeline: fx.Create(parent), }) diff --git a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/schedule_service_aiptest.pb.go b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/schedule_service_aiptest.pb.go index b3ff192..4eba534 100644 --- a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/schedule_service_aiptest.pb.go +++ b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/schedule_service_aiptest.pb.go @@ -25,15 +25,17 @@ type ScheduleServiceTestSuite struct { func (fx ScheduleServiceTestSuite) TestSchedule(ctx context.Context, options ScheduleServiceScheduleTestSuiteConfig) { fx.T.Run("Schedule", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() ScheduleServiceServer { return fx.Server } options.test(t) }) } type ScheduleServiceScheduleTestSuiteConfig struct { - service ScheduleServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() ScheduleServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -68,7 +70,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) 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.CreateSchedule(fx.Context(), &CreateScheduleRequest{ + _, err := fx.Service().CreateSchedule(fx.Context(), &CreateScheduleRequest{ Parent: "", Schedule: fx.Create(fx.nextParent(t, false)), }) @@ -78,7 +80,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) 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.CreateSchedule(fx.Context(), &CreateScheduleRequest{ + _, err := fx.Service().CreateSchedule(fx.Context(), &CreateScheduleRequest{ Parent: "invalid resource name", Schedule: fx.Create(fx.nextParent(t, false)), }) @@ -90,7 +92,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testCreate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateSchedule(fx.Context(), &CreateScheduleRequest{ + msg, err := fx.Service().CreateSchedule(fx.Context(), &CreateScheduleRequest{ Parent: parent, Schedule: fx.Create(parent), }) @@ -104,12 +106,12 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testCreate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateSchedule(fx.Context(), &CreateScheduleRequest{ + msg, err := fx.Service().CreateSchedule(fx.Context(), &CreateScheduleRequest{ Parent: parent, Schedule: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetSchedule(fx.Context(), &GetScheduleRequest{ + persisted, err := fx.Service().GetSchedule(fx.Context(), &GetScheduleRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -130,7 +132,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("parent") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateSchedule(fx.Context(), &CreateScheduleRequest{ + _, err := fx.Service().CreateSchedule(fx.Context(), &CreateScheduleRequest{ Parent: parent, Schedule: msg, }) @@ -146,7 +148,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("pipeline_job") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateSchedule(fx.Context(), &CreateScheduleRequest{ + _, err := fx.Service().CreateSchedule(fx.Context(), &CreateScheduleRequest{ Parent: parent, Schedule: msg, }) @@ -162,7 +164,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("gcs_output_directory") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateSchedule(fx.Context(), &CreateScheduleRequest{ + _, err := fx.Service().CreateSchedule(fx.Context(), &CreateScheduleRequest{ Parent: parent, Schedule: msg, }) @@ -178,7 +180,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateSchedule(fx.Context(), &CreateScheduleRequest{ + _, err := fx.Service().CreateSchedule(fx.Context(), &CreateScheduleRequest{ Parent: parent, Schedule: msg, }) @@ -194,7 +196,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateSchedule(fx.Context(), &CreateScheduleRequest{ + _, err := fx.Service().CreateSchedule(fx.Context(), &CreateScheduleRequest{ Parent: parent, Schedule: msg, }) @@ -210,7 +212,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("max_concurrent_run_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateSchedule(fx.Context(), &CreateScheduleRequest{ + _, err := fx.Service().CreateSchedule(fx.Context(), &CreateScheduleRequest{ Parent: parent, Schedule: msg, }) @@ -231,7 +233,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Parent = "invalid resource name" - _, err := fx.service.CreateSchedule(fx.Context(), &CreateScheduleRequest{ + _, err := fx.Service().CreateSchedule(fx.Context(), &CreateScheduleRequest{ Parent: parent, Schedule: msg, }) @@ -246,7 +248,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Network = "invalid resource name" - _, err := fx.service.CreateSchedule(fx.Context(), &CreateScheduleRequest{ + _, err := fx.Service().CreateSchedule(fx.Context(), &CreateScheduleRequest{ Parent: parent, Schedule: msg, }) @@ -261,7 +263,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) 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.GetSchedule(fx.Context(), &GetScheduleRequest{ + _, err := fx.Service().GetSchedule(fx.Context(), &GetScheduleRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -270,7 +272,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) 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.GetSchedule(fx.Context(), &GetScheduleRequest{ + _, err := fx.Service().GetSchedule(fx.Context(), &GetScheduleRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -281,7 +283,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetSchedule(fx.Context(), &GetScheduleRequest{ + msg, err := fx.Service().GetSchedule(fx.Context(), &GetScheduleRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -293,7 +295,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetSchedule(fx.Context(), &GetScheduleRequest{ + _, err := fx.Service().GetSchedule(fx.Context(), &GetScheduleRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -302,7 +304,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) 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.GetSchedule(fx.Context(), &GetScheduleRequest{ + _, err := fx.Service().GetSchedule(fx.Context(), &GetScheduleRequest{ Name: "projects/-/locations/-/schedules/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -318,7 +320,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ + _, err := fx.Service().UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ Schedule: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -330,7 +332,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ + _, err := fx.Service().UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ Schedule: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -341,7 +343,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ + updated, err := fx.Service().UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ Schedule: created, }) assert.NilError(t, err) @@ -353,11 +355,11 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ + updated, err := fx.Service().UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ Schedule: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetSchedule(fx.Context(), &GetScheduleRequest{ + persisted, err := fx.Service().GetSchedule(fx.Context(), &GetScheduleRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -370,7 +372,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) created := fx.create(t, parent) originalCreateTime := created.CreateTime - updated, err := fx.service.UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ + updated, err := fx.Service().UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ Schedule: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -389,7 +391,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ + _, err := fx.Service().UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ Schedule: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -398,7 +400,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) 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.UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ + _, err := fx.Service().UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ Schedule: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -422,7 +424,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("parent") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ + _, err := fx.Service().UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ Schedule: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -441,7 +443,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("pipeline_job") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ + _, err := fx.Service().UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ Schedule: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -460,7 +462,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("gcs_output_directory") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ + _, err := fx.Service().UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ Schedule: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -479,7 +481,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ + _, err := fx.Service().UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ Schedule: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -498,7 +500,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ + _, err := fx.Service().UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ Schedule: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -517,7 +519,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("max_concurrent_run_count") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ + _, err := fx.Service().UpdateSchedule(fx.Context(), &UpdateScheduleRequest{ Schedule: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -536,7 +538,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) 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.ListSchedules(fx.Context(), &ListSchedulesRequest{ + _, err := fx.Service().ListSchedules(fx.Context(), &ListSchedulesRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -546,7 +548,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListSchedules(fx.Context(), &ListSchedulesRequest{ + _, err := fx.Service().ListSchedules(fx.Context(), &ListSchedulesRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -557,7 +559,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListSchedules(fx.Context(), &ListSchedulesRequest{ + _, err := fx.Service().ListSchedules(fx.Context(), &ListSchedulesRequest{ Parent: parent, PageSize: -10, }) @@ -575,7 +577,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListSchedules(fx.Context(), &ListSchedulesRequest{ + response, err := fx.Service().ListSchedules(fx.Context(), &ListSchedulesRequest{ Parent: parent, PageSize: 999, }) @@ -594,7 +596,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) 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.ListSchedules(fx.Context(), &ListSchedulesRequest{ + response, err := fx.Service().ListSchedules(fx.Context(), &ListSchedulesRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -605,7 +607,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) 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.ListSchedules(fx.Context(), &ListSchedulesRequest{ + response, err := fx.Service().ListSchedules(fx.Context(), &ListSchedulesRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -619,7 +621,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Schedule, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListSchedules(fx.Context(), &ListSchedulesRequest{ + response, err := fx.Service().ListSchedules(fx.Context(), &ListSchedulesRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -648,12 +650,12 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteSchedule(fx.Context(), &DeleteScheduleRequest{ + _, err := fx.Service().DeleteSchedule(fx.Context(), &DeleteScheduleRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListSchedules(fx.Context(), &ListSchedulesRequest{ + response, err := fx.Service().ListSchedules(fx.Context(), &ListSchedulesRequest{ Parent: parent, PageSize: 9999, }) @@ -676,7 +678,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testDelete(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.DeleteSchedule(fx.Context(), &DeleteScheduleRequest{ + _, err := fx.Service().DeleteSchedule(fx.Context(), &DeleteScheduleRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -685,7 +687,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testDelete(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.DeleteSchedule(fx.Context(), &DeleteScheduleRequest{ + _, err := fx.Service().DeleteSchedule(fx.Context(), &DeleteScheduleRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -696,7 +698,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteSchedule(fx.Context(), &DeleteScheduleRequest{ + _, err := fx.Service().DeleteSchedule(fx.Context(), &DeleteScheduleRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -707,7 +709,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteSchedule(fx.Context(), &DeleteScheduleRequest{ + _, err := fx.Service().DeleteSchedule(fx.Context(), &DeleteScheduleRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -718,12 +720,12 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteSchedule(fx.Context(), &DeleteScheduleRequest{ + deleted, err := fx.Service().DeleteSchedule(fx.Context(), &DeleteScheduleRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteSchedule(fx.Context(), &DeleteScheduleRequest{ + _, err = fx.Service().DeleteSchedule(fx.Context(), &DeleteScheduleRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -732,7 +734,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) testDelete(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.DeleteSchedule(fx.Context(), &DeleteScheduleRequest{ + _, err := fx.Service().DeleteSchedule(fx.Context(), &DeleteScheduleRequest{ Name: "projects/-/locations/-/schedules/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -768,7 +770,7 @@ func (fx *ScheduleServiceScheduleTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *ScheduleServiceScheduleTestSuiteConfig) create(t *testing.T, parent string) *Schedule { t.Helper() - created, err := fx.service.CreateSchedule(fx.Context(), &CreateScheduleRequest{ + created, err := fx.Service().CreateSchedule(fx.Context(), &CreateScheduleRequest{ Parent: parent, Schedule: fx.Create(parent), }) diff --git a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/specialist_pool_service_aiptest.pb.go b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/specialist_pool_service_aiptest.pb.go index ba4f22f..455e6a1 100644 --- a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/specialist_pool_service_aiptest.pb.go +++ b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/specialist_pool_service_aiptest.pb.go @@ -24,15 +24,17 @@ type SpecialistPoolServiceTestSuite struct { func (fx SpecialistPoolServiceTestSuite) TestSpecialistPool(ctx context.Context, options SpecialistPoolServiceSpecialistPoolTestSuiteConfig) { fx.T.Run("SpecialistPool", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() SpecialistPoolServiceServer { return fx.Server } options.test(t) }) } type SpecialistPoolServiceSpecialistPoolTestSuiteConfig struct { - service SpecialistPoolServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() SpecialistPoolServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -67,7 +69,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testCreate(t *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.CreateSpecialistPool(fx.Context(), &CreateSpecialistPoolRequest{ + _, err := fx.Service().CreateSpecialistPool(fx.Context(), &CreateSpecialistPoolRequest{ Parent: "", SpecialistPool: fx.Create(fx.nextParent(t, false)), }) @@ -77,7 +79,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testCreate(t *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.CreateSpecialistPool(fx.Context(), &CreateSpecialistPoolRequest{ + _, err := fx.Service().CreateSpecialistPool(fx.Context(), &CreateSpecialistPoolRequest{ Parent: "invalid resource name", SpecialistPool: fx.Create(fx.nextParent(t, false)), }) @@ -98,7 +100,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testCreate(t *test } fd := container.ProtoReflect().Descriptor().Fields().ByName("name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateSpecialistPool(fx.Context(), &CreateSpecialistPoolRequest{ + _, err := fx.Service().CreateSpecialistPool(fx.Context(), &CreateSpecialistPoolRequest{ Parent: parent, SpecialistPool: msg, }) @@ -114,7 +116,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testCreate(t *test } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateSpecialistPool(fx.Context(), &CreateSpecialistPoolRequest{ + _, err := fx.Service().CreateSpecialistPool(fx.Context(), &CreateSpecialistPoolRequest{ Parent: parent, SpecialistPool: msg, }) @@ -129,7 +131,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testGet(t *testing // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.GetSpecialistPool(fx.Context(), &GetSpecialistPoolRequest{ + _, err := fx.Service().GetSpecialistPool(fx.Context(), &GetSpecialistPoolRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -138,7 +140,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testGet(t *testing // 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.GetSpecialistPool(fx.Context(), &GetSpecialistPoolRequest{ + _, err := fx.Service().GetSpecialistPool(fx.Context(), &GetSpecialistPoolRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -149,7 +151,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testGet(t *testing fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetSpecialistPool(fx.Context(), &GetSpecialistPoolRequest{ + msg, err := fx.Service().GetSpecialistPool(fx.Context(), &GetSpecialistPoolRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -161,7 +163,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testGet(t *testing fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetSpecialistPool(fx.Context(), &GetSpecialistPoolRequest{ + _, err := fx.Service().GetSpecialistPool(fx.Context(), &GetSpecialistPoolRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -170,7 +172,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testGet(t *testing // 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.GetSpecialistPool(fx.Context(), &GetSpecialistPoolRequest{ + _, err := fx.Service().GetSpecialistPool(fx.Context(), &GetSpecialistPoolRequest{ Name: "projects/-/locations/-/specialistPools/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -186,7 +188,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testUpdate(t *test parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateSpecialistPool(fx.Context(), &UpdateSpecialistPoolRequest{ + _, err := fx.Service().UpdateSpecialistPool(fx.Context(), &UpdateSpecialistPoolRequest{ SpecialistPool: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -198,7 +200,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testUpdate(t *test parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateSpecialistPool(fx.Context(), &UpdateSpecialistPoolRequest{ + _, err := fx.Service().UpdateSpecialistPool(fx.Context(), &UpdateSpecialistPoolRequest{ SpecialistPool: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -211,7 +213,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testUpdate(t *test fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateSpecialistPool(fx.Context(), &UpdateSpecialistPoolRequest{ + _, err := fx.Service().UpdateSpecialistPool(fx.Context(), &UpdateSpecialistPoolRequest{ SpecialistPool: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -220,7 +222,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testUpdate(t *test // 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.UpdateSpecialistPool(fx.Context(), &UpdateSpecialistPoolRequest{ + _, err := fx.Service().UpdateSpecialistPool(fx.Context(), &UpdateSpecialistPoolRequest{ SpecialistPool: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -244,7 +246,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testUpdate(t *test } fd := container.ProtoReflect().Descriptor().Fields().ByName("name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateSpecialistPool(fx.Context(), &UpdateSpecialistPoolRequest{ + _, err := fx.Service().UpdateSpecialistPool(fx.Context(), &UpdateSpecialistPoolRequest{ SpecialistPool: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -263,7 +265,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testUpdate(t *test } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateSpecialistPool(fx.Context(), &UpdateSpecialistPoolRequest{ + _, err := fx.Service().UpdateSpecialistPool(fx.Context(), &UpdateSpecialistPoolRequest{ SpecialistPool: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -282,7 +284,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testList(t *testin // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListSpecialistPools(fx.Context(), &ListSpecialistPoolsRequest{ + _, err := fx.Service().ListSpecialistPools(fx.Context(), &ListSpecialistPoolsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -292,7 +294,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testList(t *testin t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListSpecialistPools(fx.Context(), &ListSpecialistPoolsRequest{ + _, err := fx.Service().ListSpecialistPools(fx.Context(), &ListSpecialistPoolsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -303,7 +305,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testList(t *testin t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListSpecialistPools(fx.Context(), &ListSpecialistPoolsRequest{ + _, err := fx.Service().ListSpecialistPools(fx.Context(), &ListSpecialistPoolsRequest{ Parent: parent, PageSize: -10, }) @@ -321,7 +323,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testList(t *testin // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListSpecialistPools(fx.Context(), &ListSpecialistPoolsRequest{ + response, err := fx.Service().ListSpecialistPools(fx.Context(), &ListSpecialistPoolsRequest{ Parent: parent, PageSize: 999, }) @@ -340,7 +342,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testList(t *testin // 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.ListSpecialistPools(fx.Context(), &ListSpecialistPoolsRequest{ + response, err := fx.Service().ListSpecialistPools(fx.Context(), &ListSpecialistPoolsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -351,7 +353,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testList(t *testin // 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.ListSpecialistPools(fx.Context(), &ListSpecialistPoolsRequest{ + response, err := fx.Service().ListSpecialistPools(fx.Context(), &ListSpecialistPoolsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -365,7 +367,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testList(t *testin msgs := make([]*SpecialistPool, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListSpecialistPools(fx.Context(), &ListSpecialistPoolsRequest{ + response, err := fx.Service().ListSpecialistPools(fx.Context(), &ListSpecialistPoolsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -394,12 +396,12 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testList(t *testin fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteSpecialistPool(fx.Context(), &DeleteSpecialistPoolRequest{ + _, err := fx.Service().DeleteSpecialistPool(fx.Context(), &DeleteSpecialistPoolRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListSpecialistPools(fx.Context(), &ListSpecialistPoolsRequest{ + response, err := fx.Service().ListSpecialistPools(fx.Context(), &ListSpecialistPoolsRequest{ Parent: parent, PageSize: 9999, }) @@ -422,7 +424,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testDelete(t *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.DeleteSpecialistPool(fx.Context(), &DeleteSpecialistPoolRequest{ + _, err := fx.Service().DeleteSpecialistPool(fx.Context(), &DeleteSpecialistPoolRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -431,7 +433,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testDelete(t *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.DeleteSpecialistPool(fx.Context(), &DeleteSpecialistPoolRequest{ + _, err := fx.Service().DeleteSpecialistPool(fx.Context(), &DeleteSpecialistPoolRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -442,7 +444,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testDelete(t *test fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteSpecialistPool(fx.Context(), &DeleteSpecialistPoolRequest{ + _, err := fx.Service().DeleteSpecialistPool(fx.Context(), &DeleteSpecialistPoolRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -453,7 +455,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testDelete(t *test fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteSpecialistPool(fx.Context(), &DeleteSpecialistPoolRequest{ + _, err := fx.Service().DeleteSpecialistPool(fx.Context(), &DeleteSpecialistPoolRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -464,12 +466,12 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testDelete(t *test fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteSpecialistPool(fx.Context(), &DeleteSpecialistPoolRequest{ + deleted, err := fx.Service().DeleteSpecialistPool(fx.Context(), &DeleteSpecialistPoolRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteSpecialistPool(fx.Context(), &DeleteSpecialistPoolRequest{ + _, err = fx.Service().DeleteSpecialistPool(fx.Context(), &DeleteSpecialistPoolRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -478,7 +480,7 @@ func (fx *SpecialistPoolServiceSpecialistPoolTestSuiteConfig) testDelete(t *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.DeleteSpecialistPool(fx.Context(), &DeleteSpecialistPoolRequest{ + _, err := fx.Service().DeleteSpecialistPool(fx.Context(), &DeleteSpecialistPoolRequest{ Name: "projects/-/locations/-/specialistPools/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) diff --git a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/tensorboard_service_aiptest.pb.go b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/tensorboard_service_aiptest.pb.go index 1fdb1e1..316db2e 100644 --- a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/tensorboard_service_aiptest.pb.go +++ b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/tensorboard_service_aiptest.pb.go @@ -25,7 +25,7 @@ type TensorboardServiceTestSuite struct { func (fx TensorboardServiceTestSuite) TestTensorboard(ctx context.Context, options TensorboardServiceTensorboardTestSuiteConfig) { fx.T.Run("Tensorboard", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() TensorboardServiceServer { return fx.Server } options.test(t) }) } @@ -33,7 +33,7 @@ func (fx TensorboardServiceTestSuite) TestTensorboard(ctx context.Context, optio func (fx TensorboardServiceTestSuite) TestTensorboardExperiment(ctx context.Context, options TensorboardServiceTensorboardExperimentTestSuiteConfig) { fx.T.Run("TensorboardExperiment", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() TensorboardServiceServer { return fx.Server } options.test(t) }) } @@ -41,7 +41,7 @@ func (fx TensorboardServiceTestSuite) TestTensorboardExperiment(ctx context.Cont func (fx TensorboardServiceTestSuite) TestTensorboardRun(ctx context.Context, options TensorboardServiceTensorboardRunTestSuiteConfig) { fx.T.Run("TensorboardRun", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() TensorboardServiceServer { return fx.Server } options.test(t) }) } @@ -49,15 +49,17 @@ func (fx TensorboardServiceTestSuite) TestTensorboardRun(ctx context.Context, op func (fx TensorboardServiceTestSuite) TestTensorboardTimeSeries(ctx context.Context, options TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) { fx.T.Run("TensorboardTimeSeries", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() TensorboardServiceServer { return fx.Server } options.test(t) }) } type TensorboardServiceTensorboardTestSuiteConfig struct { - service TensorboardServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() TensorboardServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -92,7 +94,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) 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.CreateTensorboard(fx.Context(), &CreateTensorboardRequest{ + _, err := fx.Service().CreateTensorboard(fx.Context(), &CreateTensorboardRequest{ Parent: "", Tensorboard: fx.Create(fx.nextParent(t, false)), }) @@ -102,7 +104,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) 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.CreateTensorboard(fx.Context(), &CreateTensorboardRequest{ + _, err := fx.Service().CreateTensorboard(fx.Context(), &CreateTensorboardRequest{ Parent: "invalid resource name", Tensorboard: fx.Create(fx.nextParent(t, false)), }) @@ -123,7 +125,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTensorboard(fx.Context(), &CreateTensorboardRequest{ + _, err := fx.Service().CreateTensorboard(fx.Context(), &CreateTensorboardRequest{ Parent: parent, Tensorboard: msg, }) @@ -139,7 +141,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testCreate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTensorboard(fx.Context(), &CreateTensorboardRequest{ + _, err := fx.Service().CreateTensorboard(fx.Context(), &CreateTensorboardRequest{ Parent: parent, Tensorboard: msg, }) @@ -154,7 +156,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) 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.GetTensorboard(fx.Context(), &GetTensorboardRequest{ + _, err := fx.Service().GetTensorboard(fx.Context(), &GetTensorboardRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -163,7 +165,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) 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.GetTensorboard(fx.Context(), &GetTensorboardRequest{ + _, err := fx.Service().GetTensorboard(fx.Context(), &GetTensorboardRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -174,7 +176,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetTensorboard(fx.Context(), &GetTensorboardRequest{ + msg, err := fx.Service().GetTensorboard(fx.Context(), &GetTensorboardRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -186,7 +188,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetTensorboard(fx.Context(), &GetTensorboardRequest{ + _, err := fx.Service().GetTensorboard(fx.Context(), &GetTensorboardRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -195,7 +197,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) 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.GetTensorboard(fx.Context(), &GetTensorboardRequest{ + _, err := fx.Service().GetTensorboard(fx.Context(), &GetTensorboardRequest{ Name: "projects/-/locations/-/tensorboards/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -211,7 +213,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testUpdate(t *testing.T) parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateTensorboard(fx.Context(), &UpdateTensorboardRequest{ + _, err := fx.Service().UpdateTensorboard(fx.Context(), &UpdateTensorboardRequest{ Tensorboard: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -223,7 +225,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testUpdate(t *testing.T) parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateTensorboard(fx.Context(), &UpdateTensorboardRequest{ + _, err := fx.Service().UpdateTensorboard(fx.Context(), &UpdateTensorboardRequest{ Tensorboard: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -236,7 +238,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testUpdate(t *testing.T) fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateTensorboard(fx.Context(), &UpdateTensorboardRequest{ + _, err := fx.Service().UpdateTensorboard(fx.Context(), &UpdateTensorboardRequest{ Tensorboard: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -245,7 +247,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) 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.UpdateTensorboard(fx.Context(), &UpdateTensorboardRequest{ + _, err := fx.Service().UpdateTensorboard(fx.Context(), &UpdateTensorboardRequest{ Tensorboard: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -269,7 +271,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testUpdate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateTensorboard(fx.Context(), &UpdateTensorboardRequest{ + _, err := fx.Service().UpdateTensorboard(fx.Context(), &UpdateTensorboardRequest{ Tensorboard: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -288,7 +290,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testUpdate(t *testing.T) } fd := container.ProtoReflect().Descriptor().Fields().ByName("kms_key_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateTensorboard(fx.Context(), &UpdateTensorboardRequest{ + _, err := fx.Service().UpdateTensorboard(fx.Context(), &UpdateTensorboardRequest{ Tensorboard: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -307,7 +309,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) 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.ListTensorboards(fx.Context(), &ListTensorboardsRequest{ + _, err := fx.Service().ListTensorboards(fx.Context(), &ListTensorboardsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -317,7 +319,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListTensorboards(fx.Context(), &ListTensorboardsRequest{ + _, err := fx.Service().ListTensorboards(fx.Context(), &ListTensorboardsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -328,7 +330,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListTensorboards(fx.Context(), &ListTensorboardsRequest{ + _, err := fx.Service().ListTensorboards(fx.Context(), &ListTensorboardsRequest{ Parent: parent, PageSize: -10, }) @@ -346,7 +348,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListTensorboards(fx.Context(), &ListTensorboardsRequest{ + response, err := fx.Service().ListTensorboards(fx.Context(), &ListTensorboardsRequest{ Parent: parent, PageSize: 999, }) @@ -365,7 +367,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) 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.ListTensorboards(fx.Context(), &ListTensorboardsRequest{ + response, err := fx.Service().ListTensorboards(fx.Context(), &ListTensorboardsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -376,7 +378,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) 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.ListTensorboards(fx.Context(), &ListTensorboardsRequest{ + response, err := fx.Service().ListTensorboards(fx.Context(), &ListTensorboardsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -390,7 +392,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Tensorboard, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListTensorboards(fx.Context(), &ListTensorboardsRequest{ + response, err := fx.Service().ListTensorboards(fx.Context(), &ListTensorboardsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -419,12 +421,12 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteTensorboard(fx.Context(), &DeleteTensorboardRequest{ + _, err := fx.Service().DeleteTensorboard(fx.Context(), &DeleteTensorboardRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListTensorboards(fx.Context(), &ListTensorboardsRequest{ + response, err := fx.Service().ListTensorboards(fx.Context(), &ListTensorboardsRequest{ Parent: parent, PageSize: 9999, }) @@ -447,7 +449,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testDelete(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.DeleteTensorboard(fx.Context(), &DeleteTensorboardRequest{ + _, err := fx.Service().DeleteTensorboard(fx.Context(), &DeleteTensorboardRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -456,7 +458,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testDelete(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.DeleteTensorboard(fx.Context(), &DeleteTensorboardRequest{ + _, err := fx.Service().DeleteTensorboard(fx.Context(), &DeleteTensorboardRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -467,7 +469,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteTensorboard(fx.Context(), &DeleteTensorboardRequest{ + _, err := fx.Service().DeleteTensorboard(fx.Context(), &DeleteTensorboardRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -478,7 +480,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteTensorboard(fx.Context(), &DeleteTensorboardRequest{ + _, err := fx.Service().DeleteTensorboard(fx.Context(), &DeleteTensorboardRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -489,12 +491,12 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testDelete(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteTensorboard(fx.Context(), &DeleteTensorboardRequest{ + deleted, err := fx.Service().DeleteTensorboard(fx.Context(), &DeleteTensorboardRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteTensorboard(fx.Context(), &DeleteTensorboardRequest{ + _, err = fx.Service().DeleteTensorboard(fx.Context(), &DeleteTensorboardRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -503,7 +505,7 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) testDelete(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.DeleteTensorboard(fx.Context(), &DeleteTensorboardRequest{ + _, err := fx.Service().DeleteTensorboard(fx.Context(), &DeleteTensorboardRequest{ Name: "projects/-/locations/-/tensorboards/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -544,9 +546,11 @@ func (fx *TensorboardServiceTensorboardTestSuiteConfig) create(t *testing.T, par } type TensorboardServiceTensorboardExperimentTestSuiteConfig struct { - service TensorboardServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() TensorboardServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -581,7 +585,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testCreate(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.CreateTensorboardExperiment(fx.Context(), &CreateTensorboardExperimentRequest{ + _, err := fx.Service().CreateTensorboardExperiment(fx.Context(), &CreateTensorboardExperimentRequest{ Parent: "", TensorboardExperiment: fx.Create(fx.nextParent(t, false)), }) @@ -591,7 +595,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testCreate(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.CreateTensorboardExperiment(fx.Context(), &CreateTensorboardExperimentRequest{ + _, err := fx.Service().CreateTensorboardExperiment(fx.Context(), &CreateTensorboardExperimentRequest{ Parent: "invalid resource name", TensorboardExperiment: fx.Create(fx.nextParent(t, false)), }) @@ -603,7 +607,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testCreate(t * fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateTensorboardExperiment(fx.Context(), &CreateTensorboardExperimentRequest{ + msg, err := fx.Service().CreateTensorboardExperiment(fx.Context(), &CreateTensorboardExperimentRequest{ Parent: parent, TensorboardExperiment: fx.Create(parent), }) @@ -617,12 +621,12 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testCreate(t * t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateTensorboardExperiment(fx.Context(), &CreateTensorboardExperimentRequest{ + msg, err := fx.Service().CreateTensorboardExperiment(fx.Context(), &CreateTensorboardExperimentRequest{ Parent: parent, TensorboardExperiment: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetTensorboardExperiment(fx.Context(), &GetTensorboardExperimentRequest{ + persisted, err := fx.Service().GetTensorboardExperiment(fx.Context(), &GetTensorboardExperimentRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -633,7 +637,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testCreate(t * t.Run("etag populated", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - created, _ := fx.service.CreateTensorboardExperiment(fx.Context(), &CreateTensorboardExperimentRequest{ + created, _ := fx.Service().CreateTensorboardExperiment(fx.Context(), &CreateTensorboardExperimentRequest{ Parent: parent, TensorboardExperiment: fx.Create(parent), }) @@ -647,7 +651,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testGet(t *tes // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.GetTensorboardExperiment(fx.Context(), &GetTensorboardExperimentRequest{ + _, err := fx.Service().GetTensorboardExperiment(fx.Context(), &GetTensorboardExperimentRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -656,7 +660,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testGet(t *tes // 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.GetTensorboardExperiment(fx.Context(), &GetTensorboardExperimentRequest{ + _, err := fx.Service().GetTensorboardExperiment(fx.Context(), &GetTensorboardExperimentRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -667,7 +671,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testGet(t *tes fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetTensorboardExperiment(fx.Context(), &GetTensorboardExperimentRequest{ + msg, err := fx.Service().GetTensorboardExperiment(fx.Context(), &GetTensorboardExperimentRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -679,7 +683,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testGet(t *tes fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetTensorboardExperiment(fx.Context(), &GetTensorboardExperimentRequest{ + _, err := fx.Service().GetTensorboardExperiment(fx.Context(), &GetTensorboardExperimentRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -688,7 +692,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testGet(t *tes // 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.GetTensorboardExperiment(fx.Context(), &GetTensorboardExperimentRequest{ + _, err := fx.Service().GetTensorboardExperiment(fx.Context(), &GetTensorboardExperimentRequest{ Name: "projects/-/locations/-/tensorboards/-/experiments/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -704,7 +708,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testUpdate(t * parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateTensorboardExperiment(fx.Context(), &UpdateTensorboardExperimentRequest{ + _, err := fx.Service().UpdateTensorboardExperiment(fx.Context(), &UpdateTensorboardExperimentRequest{ TensorboardExperiment: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -716,7 +720,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testUpdate(t * parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateTensorboardExperiment(fx.Context(), &UpdateTensorboardExperimentRequest{ + _, err := fx.Service().UpdateTensorboardExperiment(fx.Context(), &UpdateTensorboardExperimentRequest{ TensorboardExperiment: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -727,7 +731,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testUpdate(t * fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateTensorboardExperiment(fx.Context(), &UpdateTensorboardExperimentRequest{ + updated, err := fx.Service().UpdateTensorboardExperiment(fx.Context(), &UpdateTensorboardExperimentRequest{ TensorboardExperiment: created, }) assert.NilError(t, err) @@ -739,11 +743,11 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testUpdate(t * fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateTensorboardExperiment(fx.Context(), &UpdateTensorboardExperimentRequest{ + updated, err := fx.Service().UpdateTensorboardExperiment(fx.Context(), &UpdateTensorboardExperimentRequest{ TensorboardExperiment: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetTensorboardExperiment(fx.Context(), &GetTensorboardExperimentRequest{ + persisted, err := fx.Service().GetTensorboardExperiment(fx.Context(), &GetTensorboardExperimentRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -757,7 +761,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testUpdate(t * fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateTensorboardExperiment(fx.Context(), &UpdateTensorboardExperimentRequest{ + _, err := fx.Service().UpdateTensorboardExperiment(fx.Context(), &UpdateTensorboardExperimentRequest{ TensorboardExperiment: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -766,7 +770,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testUpdate(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.UpdateTensorboardExperiment(fx.Context(), &UpdateTensorboardExperimentRequest{ + _, err := fx.Service().UpdateTensorboardExperiment(fx.Context(), &UpdateTensorboardExperimentRequest{ TensorboardExperiment: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -784,7 +788,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testList(t *te // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListTensorboardExperiments(fx.Context(), &ListTensorboardExperimentsRequest{ + _, err := fx.Service().ListTensorboardExperiments(fx.Context(), &ListTensorboardExperimentsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -794,7 +798,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testList(t *te t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListTensorboardExperiments(fx.Context(), &ListTensorboardExperimentsRequest{ + _, err := fx.Service().ListTensorboardExperiments(fx.Context(), &ListTensorboardExperimentsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -805,7 +809,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testList(t *te t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListTensorboardExperiments(fx.Context(), &ListTensorboardExperimentsRequest{ + _, err := fx.Service().ListTensorboardExperiments(fx.Context(), &ListTensorboardExperimentsRequest{ Parent: parent, PageSize: -10, }) @@ -823,7 +827,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testList(t *te // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListTensorboardExperiments(fx.Context(), &ListTensorboardExperimentsRequest{ + response, err := fx.Service().ListTensorboardExperiments(fx.Context(), &ListTensorboardExperimentsRequest{ Parent: parent, PageSize: 999, }) @@ -842,7 +846,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testList(t *te // 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.ListTensorboardExperiments(fx.Context(), &ListTensorboardExperimentsRequest{ + response, err := fx.Service().ListTensorboardExperiments(fx.Context(), &ListTensorboardExperimentsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -853,7 +857,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testList(t *te // 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.ListTensorboardExperiments(fx.Context(), &ListTensorboardExperimentsRequest{ + response, err := fx.Service().ListTensorboardExperiments(fx.Context(), &ListTensorboardExperimentsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -867,7 +871,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testList(t *te msgs := make([]*TensorboardExperiment, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListTensorboardExperiments(fx.Context(), &ListTensorboardExperimentsRequest{ + response, err := fx.Service().ListTensorboardExperiments(fx.Context(), &ListTensorboardExperimentsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -896,12 +900,12 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testList(t *te fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteTensorboardExperiment(fx.Context(), &DeleteTensorboardExperimentRequest{ + _, err := fx.Service().DeleteTensorboardExperiment(fx.Context(), &DeleteTensorboardExperimentRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListTensorboardExperiments(fx.Context(), &ListTensorboardExperimentsRequest{ + response, err := fx.Service().ListTensorboardExperiments(fx.Context(), &ListTensorboardExperimentsRequest{ Parent: parent, PageSize: 9999, }) @@ -924,7 +928,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testDelete(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.DeleteTensorboardExperiment(fx.Context(), &DeleteTensorboardExperimentRequest{ + _, err := fx.Service().DeleteTensorboardExperiment(fx.Context(), &DeleteTensorboardExperimentRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -933,7 +937,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testDelete(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.DeleteTensorboardExperiment(fx.Context(), &DeleteTensorboardExperimentRequest{ + _, err := fx.Service().DeleteTensorboardExperiment(fx.Context(), &DeleteTensorboardExperimentRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -944,7 +948,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testDelete(t * fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteTensorboardExperiment(fx.Context(), &DeleteTensorboardExperimentRequest{ + _, err := fx.Service().DeleteTensorboardExperiment(fx.Context(), &DeleteTensorboardExperimentRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -955,7 +959,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testDelete(t * fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteTensorboardExperiment(fx.Context(), &DeleteTensorboardExperimentRequest{ + _, err := fx.Service().DeleteTensorboardExperiment(fx.Context(), &DeleteTensorboardExperimentRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -966,12 +970,12 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testDelete(t * fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteTensorboardExperiment(fx.Context(), &DeleteTensorboardExperimentRequest{ + deleted, err := fx.Service().DeleteTensorboardExperiment(fx.Context(), &DeleteTensorboardExperimentRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteTensorboardExperiment(fx.Context(), &DeleteTensorboardExperimentRequest{ + _, err = fx.Service().DeleteTensorboardExperiment(fx.Context(), &DeleteTensorboardExperimentRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -980,7 +984,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) testDelete(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.DeleteTensorboardExperiment(fx.Context(), &DeleteTensorboardExperimentRequest{ + _, err := fx.Service().DeleteTensorboardExperiment(fx.Context(), &DeleteTensorboardExperimentRequest{ Name: "projects/-/locations/-/tensorboards/-/experiments/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1016,7 +1020,7 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) maybeSkip(t *t func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) create(t *testing.T, parent string) *TensorboardExperiment { t.Helper() - created, err := fx.service.CreateTensorboardExperiment(fx.Context(), &CreateTensorboardExperimentRequest{ + created, err := fx.Service().CreateTensorboardExperiment(fx.Context(), &CreateTensorboardExperimentRequest{ Parent: parent, TensorboardExperiment: fx.Create(parent), }) @@ -1025,9 +1029,11 @@ func (fx *TensorboardServiceTensorboardExperimentTestSuiteConfig) create(t *test } type TensorboardServiceTensorboardRunTestSuiteConfig struct { - service TensorboardServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() TensorboardServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -1062,7 +1068,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testCreate(t *testing // Method should fail with InvalidArgument if no parent is provided. t.Run("missing parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateTensorboardRun(fx.Context(), &CreateTensorboardRunRequest{ + _, err := fx.Service().CreateTensorboardRun(fx.Context(), &CreateTensorboardRunRequest{ Parent: "", TensorboardRun: fx.Create(fx.nextParent(t, false)), }) @@ -1072,7 +1078,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testCreate(t *testing // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.CreateTensorboardRun(fx.Context(), &CreateTensorboardRunRequest{ + _, err := fx.Service().CreateTensorboardRun(fx.Context(), &CreateTensorboardRunRequest{ Parent: "invalid resource name", TensorboardRun: fx.Create(fx.nextParent(t, false)), }) @@ -1084,7 +1090,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testCreate(t *testing fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateTensorboardRun(fx.Context(), &CreateTensorboardRunRequest{ + msg, err := fx.Service().CreateTensorboardRun(fx.Context(), &CreateTensorboardRunRequest{ Parent: parent, TensorboardRun: fx.Create(parent), }) @@ -1098,12 +1104,12 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testCreate(t *testing t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateTensorboardRun(fx.Context(), &CreateTensorboardRunRequest{ + msg, err := fx.Service().CreateTensorboardRun(fx.Context(), &CreateTensorboardRunRequest{ Parent: parent, TensorboardRun: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetTensorboardRun(fx.Context(), &GetTensorboardRunRequest{ + persisted, err := fx.Service().GetTensorboardRun(fx.Context(), &GetTensorboardRunRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -1124,7 +1130,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testCreate(t *testing } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTensorboardRun(fx.Context(), &CreateTensorboardRunRequest{ + _, err := fx.Service().CreateTensorboardRun(fx.Context(), &CreateTensorboardRunRequest{ Parent: parent, TensorboardRun: msg, }) @@ -1136,7 +1142,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testCreate(t *testing t.Run("etag populated", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - created, _ := fx.service.CreateTensorboardRun(fx.Context(), &CreateTensorboardRunRequest{ + created, _ := fx.Service().CreateTensorboardRun(fx.Context(), &CreateTensorboardRunRequest{ Parent: parent, TensorboardRun: fx.Create(parent), }) @@ -1150,7 +1156,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) 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.GetTensorboardRun(fx.Context(), &GetTensorboardRunRequest{ + _, err := fx.Service().GetTensorboardRun(fx.Context(), &GetTensorboardRunRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1159,7 +1165,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) 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.GetTensorboardRun(fx.Context(), &GetTensorboardRunRequest{ + _, err := fx.Service().GetTensorboardRun(fx.Context(), &GetTensorboardRunRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1170,7 +1176,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testGet(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetTensorboardRun(fx.Context(), &GetTensorboardRunRequest{ + msg, err := fx.Service().GetTensorboardRun(fx.Context(), &GetTensorboardRunRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1182,7 +1188,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testGet(t *testing.T) fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetTensorboardRun(fx.Context(), &GetTensorboardRunRequest{ + _, err := fx.Service().GetTensorboardRun(fx.Context(), &GetTensorboardRunRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1191,7 +1197,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) 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.GetTensorboardRun(fx.Context(), &GetTensorboardRunRequest{ + _, err := fx.Service().GetTensorboardRun(fx.Context(), &GetTensorboardRunRequest{ Name: "projects/-/locations/-/tensorboards/-/experiments/-/runs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1207,7 +1213,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testUpdate(t *testing parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateTensorboardRun(fx.Context(), &UpdateTensorboardRunRequest{ + _, err := fx.Service().UpdateTensorboardRun(fx.Context(), &UpdateTensorboardRunRequest{ TensorboardRun: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1219,7 +1225,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testUpdate(t *testing parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateTensorboardRun(fx.Context(), &UpdateTensorboardRunRequest{ + _, err := fx.Service().UpdateTensorboardRun(fx.Context(), &UpdateTensorboardRunRequest{ TensorboardRun: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1230,7 +1236,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testUpdate(t *testing fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateTensorboardRun(fx.Context(), &UpdateTensorboardRunRequest{ + updated, err := fx.Service().UpdateTensorboardRun(fx.Context(), &UpdateTensorboardRunRequest{ TensorboardRun: created, }) assert.NilError(t, err) @@ -1242,11 +1248,11 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testUpdate(t *testing fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateTensorboardRun(fx.Context(), &UpdateTensorboardRunRequest{ + updated, err := fx.Service().UpdateTensorboardRun(fx.Context(), &UpdateTensorboardRunRequest{ TensorboardRun: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetTensorboardRun(fx.Context(), &GetTensorboardRunRequest{ + persisted, err := fx.Service().GetTensorboardRun(fx.Context(), &GetTensorboardRunRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -1259,7 +1265,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testUpdate(t *testing parent := fx.nextParent(t, false) created := fx.create(t, parent) originalCreateTime := created.CreateTime - updated, err := fx.service.UpdateTensorboardRun(fx.Context(), &UpdateTensorboardRunRequest{ + updated, err := fx.Service().UpdateTensorboardRun(fx.Context(), &UpdateTensorboardRunRequest{ TensorboardRun: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -1278,7 +1284,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testUpdate(t *testing fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateTensorboardRun(fx.Context(), &UpdateTensorboardRunRequest{ + _, err := fx.Service().UpdateTensorboardRun(fx.Context(), &UpdateTensorboardRunRequest{ TensorboardRun: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1287,7 +1293,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testUpdate(t *testing // 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.UpdateTensorboardRun(fx.Context(), &UpdateTensorboardRunRequest{ + _, err := fx.Service().UpdateTensorboardRun(fx.Context(), &UpdateTensorboardRunRequest{ TensorboardRun: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -1311,7 +1317,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testUpdate(t *testing } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateTensorboardRun(fx.Context(), &UpdateTensorboardRunRequest{ + _, err := fx.Service().UpdateTensorboardRun(fx.Context(), &UpdateTensorboardRunRequest{ TensorboardRun: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -1330,7 +1336,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) 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.ListTensorboardRuns(fx.Context(), &ListTensorboardRunsRequest{ + _, err := fx.Service().ListTensorboardRuns(fx.Context(), &ListTensorboardRunsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1340,7 +1346,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testList(t *testing.T t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListTensorboardRuns(fx.Context(), &ListTensorboardRunsRequest{ + _, err := fx.Service().ListTensorboardRuns(fx.Context(), &ListTensorboardRunsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -1351,7 +1357,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testList(t *testing.T t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListTensorboardRuns(fx.Context(), &ListTensorboardRunsRequest{ + _, err := fx.Service().ListTensorboardRuns(fx.Context(), &ListTensorboardRunsRequest{ Parent: parent, PageSize: -10, }) @@ -1369,7 +1375,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testList(t *testing.T // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListTensorboardRuns(fx.Context(), &ListTensorboardRunsRequest{ + response, err := fx.Service().ListTensorboardRuns(fx.Context(), &ListTensorboardRunsRequest{ Parent: parent, PageSize: 999, }) @@ -1388,7 +1394,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) 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.ListTensorboardRuns(fx.Context(), &ListTensorboardRunsRequest{ + response, err := fx.Service().ListTensorboardRuns(fx.Context(), &ListTensorboardRunsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -1399,7 +1405,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) 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.ListTensorboardRuns(fx.Context(), &ListTensorboardRunsRequest{ + response, err := fx.Service().ListTensorboardRuns(fx.Context(), &ListTensorboardRunsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -1413,7 +1419,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testList(t *testing.T msgs := make([]*TensorboardRun, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListTensorboardRuns(fx.Context(), &ListTensorboardRunsRequest{ + response, err := fx.Service().ListTensorboardRuns(fx.Context(), &ListTensorboardRunsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -1442,12 +1448,12 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testList(t *testing.T fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteTensorboardRun(fx.Context(), &DeleteTensorboardRunRequest{ + _, err := fx.Service().DeleteTensorboardRun(fx.Context(), &DeleteTensorboardRunRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListTensorboardRuns(fx.Context(), &ListTensorboardRunsRequest{ + response, err := fx.Service().ListTensorboardRuns(fx.Context(), &ListTensorboardRunsRequest{ Parent: parent, PageSize: 9999, }) @@ -1470,7 +1476,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testDelete(t *testing // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.DeleteTensorboardRun(fx.Context(), &DeleteTensorboardRunRequest{ + _, err := fx.Service().DeleteTensorboardRun(fx.Context(), &DeleteTensorboardRunRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1479,7 +1485,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testDelete(t *testing // 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.DeleteTensorboardRun(fx.Context(), &DeleteTensorboardRunRequest{ + _, err := fx.Service().DeleteTensorboardRun(fx.Context(), &DeleteTensorboardRunRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1490,7 +1496,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testDelete(t *testing fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteTensorboardRun(fx.Context(), &DeleteTensorboardRunRequest{ + _, err := fx.Service().DeleteTensorboardRun(fx.Context(), &DeleteTensorboardRunRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1501,7 +1507,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testDelete(t *testing fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteTensorboardRun(fx.Context(), &DeleteTensorboardRunRequest{ + _, err := fx.Service().DeleteTensorboardRun(fx.Context(), &DeleteTensorboardRunRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1512,12 +1518,12 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testDelete(t *testing fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteTensorboardRun(fx.Context(), &DeleteTensorboardRunRequest{ + deleted, err := fx.Service().DeleteTensorboardRun(fx.Context(), &DeleteTensorboardRunRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteTensorboardRun(fx.Context(), &DeleteTensorboardRunRequest{ + _, err = fx.Service().DeleteTensorboardRun(fx.Context(), &DeleteTensorboardRunRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1526,7 +1532,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) testDelete(t *testing // 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.DeleteTensorboardRun(fx.Context(), &DeleteTensorboardRunRequest{ + _, err := fx.Service().DeleteTensorboardRun(fx.Context(), &DeleteTensorboardRunRequest{ Name: "projects/-/locations/-/tensorboards/-/experiments/-/runs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1562,7 +1568,7 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) maybeSkip(t *testing. func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) create(t *testing.T, parent string) *TensorboardRun { t.Helper() - created, err := fx.service.CreateTensorboardRun(fx.Context(), &CreateTensorboardRunRequest{ + created, err := fx.Service().CreateTensorboardRun(fx.Context(), &CreateTensorboardRunRequest{ Parent: parent, TensorboardRun: fx.Create(parent), }) @@ -1571,9 +1577,11 @@ func (fx *TensorboardServiceTensorboardRunTestSuiteConfig) create(t *testing.T, } type TensorboardServiceTensorboardTimeSeriesTestSuiteConfig struct { - service TensorboardServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() TensorboardServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -1608,7 +1616,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testCreate(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.CreateTensorboardTimeSeries(fx.Context(), &CreateTensorboardTimeSeriesRequest{ + _, err := fx.Service().CreateTensorboardTimeSeries(fx.Context(), &CreateTensorboardTimeSeriesRequest{ Parent: "", TensorboardTimeSeries: fx.Create(fx.nextParent(t, false)), }) @@ -1618,7 +1626,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testCreate(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.CreateTensorboardTimeSeries(fx.Context(), &CreateTensorboardTimeSeriesRequest{ + _, err := fx.Service().CreateTensorboardTimeSeries(fx.Context(), &CreateTensorboardTimeSeriesRequest{ Parent: "invalid resource name", TensorboardTimeSeries: fx.Create(fx.nextParent(t, false)), }) @@ -1630,7 +1638,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testCreate(t * fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateTensorboardTimeSeries(fx.Context(), &CreateTensorboardTimeSeriesRequest{ + msg, err := fx.Service().CreateTensorboardTimeSeries(fx.Context(), &CreateTensorboardTimeSeriesRequest{ Parent: parent, TensorboardTimeSeries: fx.Create(parent), }) @@ -1644,12 +1652,12 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testCreate(t * t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateTensorboardTimeSeries(fx.Context(), &CreateTensorboardTimeSeriesRequest{ + msg, err := fx.Service().CreateTensorboardTimeSeries(fx.Context(), &CreateTensorboardTimeSeriesRequest{ Parent: parent, TensorboardTimeSeries: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetTensorboardTimeSeries(fx.Context(), &GetTensorboardTimeSeriesRequest{ + persisted, err := fx.Service().GetTensorboardTimeSeries(fx.Context(), &GetTensorboardTimeSeriesRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -1670,7 +1678,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testCreate(t * } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTensorboardTimeSeries(fx.Context(), &CreateTensorboardTimeSeriesRequest{ + _, err := fx.Service().CreateTensorboardTimeSeries(fx.Context(), &CreateTensorboardTimeSeriesRequest{ Parent: parent, TensorboardTimeSeries: msg, }) @@ -1686,7 +1694,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testCreate(t * } fd := container.ProtoReflect().Descriptor().Fields().ByName("value_type") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateTensorboardTimeSeries(fx.Context(), &CreateTensorboardTimeSeriesRequest{ + _, err := fx.Service().CreateTensorboardTimeSeries(fx.Context(), &CreateTensorboardTimeSeriesRequest{ Parent: parent, TensorboardTimeSeries: msg, }) @@ -1698,7 +1706,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testCreate(t * t.Run("etag populated", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - created, _ := fx.service.CreateTensorboardTimeSeries(fx.Context(), &CreateTensorboardTimeSeriesRequest{ + created, _ := fx.Service().CreateTensorboardTimeSeries(fx.Context(), &CreateTensorboardTimeSeriesRequest{ Parent: parent, TensorboardTimeSeries: fx.Create(parent), }) @@ -1712,7 +1720,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testGet(t *tes // Method should fail with InvalidArgument if no name is provided. t.Run("missing name", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.GetTensorboardTimeSeries(fx.Context(), &GetTensorboardTimeSeriesRequest{ + _, err := fx.Service().GetTensorboardTimeSeries(fx.Context(), &GetTensorboardTimeSeriesRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1721,7 +1729,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testGet(t *tes // 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.GetTensorboardTimeSeries(fx.Context(), &GetTensorboardTimeSeriesRequest{ + _, err := fx.Service().GetTensorboardTimeSeries(fx.Context(), &GetTensorboardTimeSeriesRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1732,7 +1740,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testGet(t *tes fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetTensorboardTimeSeries(fx.Context(), &GetTensorboardTimeSeriesRequest{ + msg, err := fx.Service().GetTensorboardTimeSeries(fx.Context(), &GetTensorboardTimeSeriesRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1744,7 +1752,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testGet(t *tes fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetTensorboardTimeSeries(fx.Context(), &GetTensorboardTimeSeriesRequest{ + _, err := fx.Service().GetTensorboardTimeSeries(fx.Context(), &GetTensorboardTimeSeriesRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1753,7 +1761,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testGet(t *tes // 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.GetTensorboardTimeSeries(fx.Context(), &GetTensorboardTimeSeriesRequest{ + _, err := fx.Service().GetTensorboardTimeSeries(fx.Context(), &GetTensorboardTimeSeriesRequest{ Name: "projects/-/locations/-/tensorboards/-/experiments/-/runs/-/timeSeries/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1769,7 +1777,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testUpdate(t * parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateTensorboardTimeSeries(fx.Context(), &UpdateTensorboardTimeSeriesRequest{ + _, err := fx.Service().UpdateTensorboardTimeSeries(fx.Context(), &UpdateTensorboardTimeSeriesRequest{ TensorboardTimeSeries: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1781,7 +1789,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testUpdate(t * parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateTensorboardTimeSeries(fx.Context(), &UpdateTensorboardTimeSeriesRequest{ + _, err := fx.Service().UpdateTensorboardTimeSeries(fx.Context(), &UpdateTensorboardTimeSeriesRequest{ TensorboardTimeSeries: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1792,7 +1800,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testUpdate(t * fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateTensorboardTimeSeries(fx.Context(), &UpdateTensorboardTimeSeriesRequest{ + updated, err := fx.Service().UpdateTensorboardTimeSeries(fx.Context(), &UpdateTensorboardTimeSeriesRequest{ TensorboardTimeSeries: created, }) assert.NilError(t, err) @@ -1804,11 +1812,11 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testUpdate(t * fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateTensorboardTimeSeries(fx.Context(), &UpdateTensorboardTimeSeriesRequest{ + updated, err := fx.Service().UpdateTensorboardTimeSeries(fx.Context(), &UpdateTensorboardTimeSeriesRequest{ TensorboardTimeSeries: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetTensorboardTimeSeries(fx.Context(), &GetTensorboardTimeSeriesRequest{ + persisted, err := fx.Service().GetTensorboardTimeSeries(fx.Context(), &GetTensorboardTimeSeriesRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -1821,7 +1829,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testUpdate(t * parent := fx.nextParent(t, false) created := fx.create(t, parent) originalCreateTime := created.CreateTime - updated, err := fx.service.UpdateTensorboardTimeSeries(fx.Context(), &UpdateTensorboardTimeSeriesRequest{ + updated, err := fx.Service().UpdateTensorboardTimeSeries(fx.Context(), &UpdateTensorboardTimeSeriesRequest{ TensorboardTimeSeries: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -1840,7 +1848,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testUpdate(t * fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateTensorboardTimeSeries(fx.Context(), &UpdateTensorboardTimeSeriesRequest{ + _, err := fx.Service().UpdateTensorboardTimeSeries(fx.Context(), &UpdateTensorboardTimeSeriesRequest{ TensorboardTimeSeries: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1849,7 +1857,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testUpdate(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.UpdateTensorboardTimeSeries(fx.Context(), &UpdateTensorboardTimeSeriesRequest{ + _, err := fx.Service().UpdateTensorboardTimeSeries(fx.Context(), &UpdateTensorboardTimeSeriesRequest{ TensorboardTimeSeries: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -1873,7 +1881,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testUpdate(t * } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateTensorboardTimeSeries(fx.Context(), &UpdateTensorboardTimeSeriesRequest{ + _, err := fx.Service().UpdateTensorboardTimeSeries(fx.Context(), &UpdateTensorboardTimeSeriesRequest{ TensorboardTimeSeries: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -1892,7 +1900,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testList(t *te // Method should fail with InvalidArgument if provided parent is invalid. t.Run("invalid parent", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListTensorboardTimeSeries(fx.Context(), &ListTensorboardTimeSeriesRequest{ + _, err := fx.Service().ListTensorboardTimeSeries(fx.Context(), &ListTensorboardTimeSeriesRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1902,7 +1910,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testList(t *te t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListTensorboardTimeSeries(fx.Context(), &ListTensorboardTimeSeriesRequest{ + _, err := fx.Service().ListTensorboardTimeSeries(fx.Context(), &ListTensorboardTimeSeriesRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -1913,7 +1921,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testList(t *te t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListTensorboardTimeSeries(fx.Context(), &ListTensorboardTimeSeriesRequest{ + _, err := fx.Service().ListTensorboardTimeSeries(fx.Context(), &ListTensorboardTimeSeriesRequest{ Parent: parent, PageSize: -10, }) @@ -1931,7 +1939,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testList(t *te // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListTensorboardTimeSeries(fx.Context(), &ListTensorboardTimeSeriesRequest{ + response, err := fx.Service().ListTensorboardTimeSeries(fx.Context(), &ListTensorboardTimeSeriesRequest{ Parent: parent, PageSize: 999, }) @@ -1950,7 +1958,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testList(t *te // 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.ListTensorboardTimeSeries(fx.Context(), &ListTensorboardTimeSeriesRequest{ + response, err := fx.Service().ListTensorboardTimeSeries(fx.Context(), &ListTensorboardTimeSeriesRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -1961,7 +1969,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testList(t *te // 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.ListTensorboardTimeSeries(fx.Context(), &ListTensorboardTimeSeriesRequest{ + response, err := fx.Service().ListTensorboardTimeSeries(fx.Context(), &ListTensorboardTimeSeriesRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -1975,7 +1983,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testList(t *te msgs := make([]*TensorboardTimeSeries, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListTensorboardTimeSeries(fx.Context(), &ListTensorboardTimeSeriesRequest{ + response, err := fx.Service().ListTensorboardTimeSeries(fx.Context(), &ListTensorboardTimeSeriesRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -2004,12 +2012,12 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testList(t *te fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteTensorboardTimeSeries(fx.Context(), &DeleteTensorboardTimeSeriesRequest{ + _, err := fx.Service().DeleteTensorboardTimeSeries(fx.Context(), &DeleteTensorboardTimeSeriesRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListTensorboardTimeSeries(fx.Context(), &ListTensorboardTimeSeriesRequest{ + response, err := fx.Service().ListTensorboardTimeSeries(fx.Context(), &ListTensorboardTimeSeriesRequest{ Parent: parent, PageSize: 9999, }) @@ -2032,7 +2040,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testDelete(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.DeleteTensorboardTimeSeries(fx.Context(), &DeleteTensorboardTimeSeriesRequest{ + _, err := fx.Service().DeleteTensorboardTimeSeries(fx.Context(), &DeleteTensorboardTimeSeriesRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -2041,7 +2049,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testDelete(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.DeleteTensorboardTimeSeries(fx.Context(), &DeleteTensorboardTimeSeriesRequest{ + _, err := fx.Service().DeleteTensorboardTimeSeries(fx.Context(), &DeleteTensorboardTimeSeriesRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -2052,7 +2060,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testDelete(t * fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteTensorboardTimeSeries(fx.Context(), &DeleteTensorboardTimeSeriesRequest{ + _, err := fx.Service().DeleteTensorboardTimeSeries(fx.Context(), &DeleteTensorboardTimeSeriesRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -2063,7 +2071,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testDelete(t * fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteTensorboardTimeSeries(fx.Context(), &DeleteTensorboardTimeSeriesRequest{ + _, err := fx.Service().DeleteTensorboardTimeSeries(fx.Context(), &DeleteTensorboardTimeSeriesRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -2074,12 +2082,12 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testDelete(t * fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteTensorboardTimeSeries(fx.Context(), &DeleteTensorboardTimeSeriesRequest{ + deleted, err := fx.Service().DeleteTensorboardTimeSeries(fx.Context(), &DeleteTensorboardTimeSeriesRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteTensorboardTimeSeries(fx.Context(), &DeleteTensorboardTimeSeriesRequest{ + _, err = fx.Service().DeleteTensorboardTimeSeries(fx.Context(), &DeleteTensorboardTimeSeriesRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -2088,7 +2096,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) testDelete(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.DeleteTensorboardTimeSeries(fx.Context(), &DeleteTensorboardTimeSeriesRequest{ + _, err := fx.Service().DeleteTensorboardTimeSeries(fx.Context(), &DeleteTensorboardTimeSeriesRequest{ Name: "projects/-/locations/-/tensorboards/-/experiments/-/runs/-/timeSeries/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -2124,7 +2132,7 @@ func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) maybeSkip(t *t func (fx *TensorboardServiceTensorboardTimeSeriesTestSuiteConfig) create(t *testing.T, parent string) *TensorboardTimeSeries { t.Helper() - created, err := fx.service.CreateTensorboardTimeSeries(fx.Context(), &CreateTensorboardTimeSeriesRequest{ + created, err := fx.Service().CreateTensorboardTimeSeries(fx.Context(), &CreateTensorboardTimeSeriesRequest{ Parent: parent, TensorboardTimeSeries: fx.Create(parent), }) diff --git a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/vizier_service_aiptest.pb.go b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/vizier_service_aiptest.pb.go index 02b40a5..a757aea 100644 --- a/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/vizier_service_aiptest.pb.go +++ b/proto/gen/googleapis/aiplatform/apiv1/aiplatformpb/vizier_service_aiptest.pb.go @@ -23,7 +23,7 @@ type VizierServiceTestSuite struct { func (fx VizierServiceTestSuite) TestStudy(ctx context.Context, options VizierServiceStudyTestSuiteConfig) { fx.T.Run("Study", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() VizierServiceServer { return fx.Server } options.test(t) }) } @@ -31,15 +31,17 @@ func (fx VizierServiceTestSuite) TestStudy(ctx context.Context, options VizierSe func (fx VizierServiceTestSuite) TestTrial(ctx context.Context, options VizierServiceTrialTestSuiteConfig) { fx.T.Run("Trial", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() VizierServiceServer { return fx.Server } options.test(t) }) } type VizierServiceStudyTestSuiteConfig struct { - service VizierServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() VizierServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -70,7 +72,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) 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.CreateStudy(fx.Context(), &CreateStudyRequest{ + _, err := fx.Service().CreateStudy(fx.Context(), &CreateStudyRequest{ Parent: "", Study: fx.Create(fx.nextParent(t, false)), }) @@ -80,7 +82,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) 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.CreateStudy(fx.Context(), &CreateStudyRequest{ + _, err := fx.Service().CreateStudy(fx.Context(), &CreateStudyRequest{ Parent: "invalid resource name", Study: fx.Create(fx.nextParent(t, false)), }) @@ -92,7 +94,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) testCreate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) beforeCreate := time.Now() - msg, err := fx.service.CreateStudy(fx.Context(), &CreateStudyRequest{ + msg, err := fx.Service().CreateStudy(fx.Context(), &CreateStudyRequest{ Parent: parent, Study: fx.Create(parent), }) @@ -106,12 +108,12 @@ func (fx *VizierServiceStudyTestSuiteConfig) testCreate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateStudy(fx.Context(), &CreateStudyRequest{ + msg, err := fx.Service().CreateStudy(fx.Context(), &CreateStudyRequest{ Parent: parent, Study: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetStudy(fx.Context(), &GetStudyRequest{ + persisted, err := fx.Service().GetStudy(fx.Context(), &GetStudyRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -132,7 +134,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateStudy(fx.Context(), &CreateStudyRequest{ + _, err := fx.Service().CreateStudy(fx.Context(), &CreateStudyRequest{ Parent: parent, Study: msg, }) @@ -148,7 +150,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("study_spec") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateStudy(fx.Context(), &CreateStudyRequest{ + _, err := fx.Service().CreateStudy(fx.Context(), &CreateStudyRequest{ Parent: parent, Study: msg, }) @@ -164,7 +166,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("metrics") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateStudy(fx.Context(), &CreateStudyRequest{ + _, err := fx.Service().CreateStudy(fx.Context(), &CreateStudyRequest{ Parent: parent, Study: msg, }) @@ -180,7 +182,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("parameters") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateStudy(fx.Context(), &CreateStudyRequest{ + _, err := fx.Service().CreateStudy(fx.Context(), &CreateStudyRequest{ Parent: parent, Study: msg, }) @@ -195,7 +197,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) 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.GetStudy(fx.Context(), &GetStudyRequest{ + _, err := fx.Service().GetStudy(fx.Context(), &GetStudyRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -204,7 +206,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) 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.GetStudy(fx.Context(), &GetStudyRequest{ + _, err := fx.Service().GetStudy(fx.Context(), &GetStudyRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -215,7 +217,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetStudy(fx.Context(), &GetStudyRequest{ + msg, err := fx.Service().GetStudy(fx.Context(), &GetStudyRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -227,7 +229,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetStudy(fx.Context(), &GetStudyRequest{ + _, err := fx.Service().GetStudy(fx.Context(), &GetStudyRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -236,7 +238,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) 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.GetStudy(fx.Context(), &GetStudyRequest{ + _, err := fx.Service().GetStudy(fx.Context(), &GetStudyRequest{ Name: "projects/-/locations/-/studies/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -249,7 +251,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) 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.ListStudies(fx.Context(), &ListStudiesRequest{ + _, err := fx.Service().ListStudies(fx.Context(), &ListStudiesRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -259,7 +261,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListStudies(fx.Context(), &ListStudiesRequest{ + _, err := fx.Service().ListStudies(fx.Context(), &ListStudiesRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -270,7 +272,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListStudies(fx.Context(), &ListStudiesRequest{ + _, err := fx.Service().ListStudies(fx.Context(), &ListStudiesRequest{ Parent: parent, PageSize: -10, }) @@ -288,7 +290,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListStudies(fx.Context(), &ListStudiesRequest{ + response, err := fx.Service().ListStudies(fx.Context(), &ListStudiesRequest{ Parent: parent, PageSize: 999, }) @@ -307,7 +309,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) 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.ListStudies(fx.Context(), &ListStudiesRequest{ + response, err := fx.Service().ListStudies(fx.Context(), &ListStudiesRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -318,7 +320,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) 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.ListStudies(fx.Context(), &ListStudiesRequest{ + response, err := fx.Service().ListStudies(fx.Context(), &ListStudiesRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -332,7 +334,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Study, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListStudies(fx.Context(), &ListStudiesRequest{ + response, err := fx.Service().ListStudies(fx.Context(), &ListStudiesRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -361,12 +363,12 @@ func (fx *VizierServiceStudyTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteStudy(fx.Context(), &DeleteStudyRequest{ + _, err := fx.Service().DeleteStudy(fx.Context(), &DeleteStudyRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListStudies(fx.Context(), &ListStudiesRequest{ + response, err := fx.Service().ListStudies(fx.Context(), &ListStudiesRequest{ Parent: parent, PageSize: 9999, }) @@ -389,7 +391,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) testDelete(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.DeleteStudy(fx.Context(), &DeleteStudyRequest{ + _, err := fx.Service().DeleteStudy(fx.Context(), &DeleteStudyRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -398,7 +400,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) testDelete(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.DeleteStudy(fx.Context(), &DeleteStudyRequest{ + _, err := fx.Service().DeleteStudy(fx.Context(), &DeleteStudyRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -409,7 +411,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteStudy(fx.Context(), &DeleteStudyRequest{ + _, err := fx.Service().DeleteStudy(fx.Context(), &DeleteStudyRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -420,7 +422,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteStudy(fx.Context(), &DeleteStudyRequest{ + _, err := fx.Service().DeleteStudy(fx.Context(), &DeleteStudyRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -431,12 +433,12 @@ func (fx *VizierServiceStudyTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteStudy(fx.Context(), &DeleteStudyRequest{ + deleted, err := fx.Service().DeleteStudy(fx.Context(), &DeleteStudyRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteStudy(fx.Context(), &DeleteStudyRequest{ + _, err = fx.Service().DeleteStudy(fx.Context(), &DeleteStudyRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -445,7 +447,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) testDelete(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.DeleteStudy(fx.Context(), &DeleteStudyRequest{ + _, err := fx.Service().DeleteStudy(fx.Context(), &DeleteStudyRequest{ Name: "projects/-/locations/-/studies/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -481,7 +483,7 @@ func (fx *VizierServiceStudyTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *VizierServiceStudyTestSuiteConfig) create(t *testing.T, parent string) *Study { t.Helper() - created, err := fx.service.CreateStudy(fx.Context(), &CreateStudyRequest{ + created, err := fx.Service().CreateStudy(fx.Context(), &CreateStudyRequest{ Parent: parent, Study: fx.Create(parent), }) @@ -490,9 +492,11 @@ func (fx *VizierServiceStudyTestSuiteConfig) create(t *testing.T, parent string) } type VizierServiceTrialTestSuiteConfig struct { - service VizierServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() VizierServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -523,7 +527,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) 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.CreateTrial(fx.Context(), &CreateTrialRequest{ + _, err := fx.Service().CreateTrial(fx.Context(), &CreateTrialRequest{ Parent: "", Trial: fx.Create(fx.nextParent(t, false)), }) @@ -533,7 +537,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) 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.CreateTrial(fx.Context(), &CreateTrialRequest{ + _, err := fx.Service().CreateTrial(fx.Context(), &CreateTrialRequest{ Parent: "invalid resource name", Trial: fx.Create(fx.nextParent(t, false)), }) @@ -544,12 +548,12 @@ func (fx *VizierServiceTrialTestSuiteConfig) testCreate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateTrial(fx.Context(), &CreateTrialRequest{ + msg, err := fx.Service().CreateTrial(fx.Context(), &CreateTrialRequest{ Parent: parent, Trial: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetTrial(fx.Context(), &GetTrialRequest{ + persisted, err := fx.Service().GetTrial(fx.Context(), &GetTrialRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -563,7 +567,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) 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.GetTrial(fx.Context(), &GetTrialRequest{ + _, err := fx.Service().GetTrial(fx.Context(), &GetTrialRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -572,7 +576,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) 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.GetTrial(fx.Context(), &GetTrialRequest{ + _, err := fx.Service().GetTrial(fx.Context(), &GetTrialRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -583,7 +587,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetTrial(fx.Context(), &GetTrialRequest{ + msg, err := fx.Service().GetTrial(fx.Context(), &GetTrialRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -595,7 +599,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetTrial(fx.Context(), &GetTrialRequest{ + _, err := fx.Service().GetTrial(fx.Context(), &GetTrialRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -604,7 +608,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) 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.GetTrial(fx.Context(), &GetTrialRequest{ + _, err := fx.Service().GetTrial(fx.Context(), &GetTrialRequest{ Name: "projects/-/locations/-/studies/-/trials/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -617,7 +621,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) 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.ListTrials(fx.Context(), &ListTrialsRequest{ + _, err := fx.Service().ListTrials(fx.Context(), &ListTrialsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -627,7 +631,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListTrials(fx.Context(), &ListTrialsRequest{ + _, err := fx.Service().ListTrials(fx.Context(), &ListTrialsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -638,7 +642,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListTrials(fx.Context(), &ListTrialsRequest{ + _, err := fx.Service().ListTrials(fx.Context(), &ListTrialsRequest{ Parent: parent, PageSize: -10, }) @@ -656,7 +660,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListTrials(fx.Context(), &ListTrialsRequest{ + response, err := fx.Service().ListTrials(fx.Context(), &ListTrialsRequest{ Parent: parent, PageSize: 999, }) @@ -675,7 +679,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) 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.ListTrials(fx.Context(), &ListTrialsRequest{ + response, err := fx.Service().ListTrials(fx.Context(), &ListTrialsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -686,7 +690,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) 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.ListTrials(fx.Context(), &ListTrialsRequest{ + response, err := fx.Service().ListTrials(fx.Context(), &ListTrialsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -700,7 +704,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Trial, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListTrials(fx.Context(), &ListTrialsRequest{ + response, err := fx.Service().ListTrials(fx.Context(), &ListTrialsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -729,12 +733,12 @@ func (fx *VizierServiceTrialTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteTrial(fx.Context(), &DeleteTrialRequest{ + _, err := fx.Service().DeleteTrial(fx.Context(), &DeleteTrialRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListTrials(fx.Context(), &ListTrialsRequest{ + response, err := fx.Service().ListTrials(fx.Context(), &ListTrialsRequest{ Parent: parent, PageSize: 9999, }) @@ -757,7 +761,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) testDelete(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.DeleteTrial(fx.Context(), &DeleteTrialRequest{ + _, err := fx.Service().DeleteTrial(fx.Context(), &DeleteTrialRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -766,7 +770,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) testDelete(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.DeleteTrial(fx.Context(), &DeleteTrialRequest{ + _, err := fx.Service().DeleteTrial(fx.Context(), &DeleteTrialRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -777,7 +781,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteTrial(fx.Context(), &DeleteTrialRequest{ + _, err := fx.Service().DeleteTrial(fx.Context(), &DeleteTrialRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -788,7 +792,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteTrial(fx.Context(), &DeleteTrialRequest{ + _, err := fx.Service().DeleteTrial(fx.Context(), &DeleteTrialRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -799,12 +803,12 @@ func (fx *VizierServiceTrialTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteTrial(fx.Context(), &DeleteTrialRequest{ + deleted, err := fx.Service().DeleteTrial(fx.Context(), &DeleteTrialRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteTrial(fx.Context(), &DeleteTrialRequest{ + _, err = fx.Service().DeleteTrial(fx.Context(), &DeleteTrialRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -813,7 +817,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) testDelete(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.DeleteTrial(fx.Context(), &DeleteTrialRequest{ + _, err := fx.Service().DeleteTrial(fx.Context(), &DeleteTrialRequest{ Name: "projects/-/locations/-/studies/-/trials/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -849,7 +853,7 @@ func (fx *VizierServiceTrialTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *VizierServiceTrialTestSuiteConfig) create(t *testing.T, parent string) *Trial { t.Helper() - created, err := fx.service.CreateTrial(fx.Context(), &CreateTrialRequest{ + created, err := fx.Service().CreateTrial(fx.Context(), &CreateTrialRequest{ Parent: parent, Trial: fx.Create(parent), }) diff --git a/proto/gen/googleapis/area120/tables/apiv1alpha1/tablespb/tables_aiptest.pb.go b/proto/gen/googleapis/area120/tables/apiv1alpha1/tablespb/tables_aiptest.pb.go index c9d1307..01bd703 100644 --- a/proto/gen/googleapis/area120/tables/apiv1alpha1/tablespb/tables_aiptest.pb.go +++ b/proto/gen/googleapis/area120/tables/apiv1alpha1/tablespb/tables_aiptest.pb.go @@ -23,7 +23,7 @@ type TablesServiceTestSuite struct { func (fx TablesServiceTestSuite) TestRow(ctx context.Context, options TablesServiceRowTestSuiteConfig) { fx.T.Run("Row", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() TablesServiceServer { return fx.Server } options.test(t) }) } @@ -31,7 +31,7 @@ func (fx TablesServiceTestSuite) TestRow(ctx context.Context, options TablesServ func (fx TablesServiceTestSuite) TestTable(ctx context.Context, options TablesServiceTableTestSuiteConfig) { fx.T.Run("Table", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() TablesServiceServer { return fx.Server } options.test(t) }) } @@ -39,15 +39,17 @@ func (fx TablesServiceTestSuite) TestTable(ctx context.Context, options TablesSe func (fx TablesServiceTestSuite) TestWorkspace(ctx context.Context, options TablesServiceWorkspaceTestSuiteConfig) { fx.T.Run("Workspace", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() TablesServiceServer { return fx.Server } options.test(t) }) } type TablesServiceRowTestSuiteConfig struct { - service TablesServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() TablesServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -82,7 +84,7 @@ func (fx *TablesServiceRowTestSuiteConfig) 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.CreateRow(fx.Context(), &CreateRowRequest{ + _, err := fx.Service().CreateRow(fx.Context(), &CreateRowRequest{ Parent: "", Row: fx.Create(fx.nextParent(t, false)), }) @@ -92,7 +94,7 @@ func (fx *TablesServiceRowTestSuiteConfig) 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.CreateRow(fx.Context(), &CreateRowRequest{ + _, err := fx.Service().CreateRow(fx.Context(), &CreateRowRequest{ Parent: "invalid resource name", Row: fx.Create(fx.nextParent(t, false)), }) @@ -103,12 +105,12 @@ func (fx *TablesServiceRowTestSuiteConfig) testCreate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateRow(fx.Context(), &CreateRowRequest{ + msg, err := fx.Service().CreateRow(fx.Context(), &CreateRowRequest{ Parent: parent, Row: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetRow(fx.Context(), &GetRowRequest{ + persisted, err := fx.Service().GetRow(fx.Context(), &GetRowRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -122,7 +124,7 @@ func (fx *TablesServiceRowTestSuiteConfig) 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.GetRow(fx.Context(), &GetRowRequest{ + _, err := fx.Service().GetRow(fx.Context(), &GetRowRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -131,7 +133,7 @@ func (fx *TablesServiceRowTestSuiteConfig) 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.GetRow(fx.Context(), &GetRowRequest{ + _, err := fx.Service().GetRow(fx.Context(), &GetRowRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -142,7 +144,7 @@ func (fx *TablesServiceRowTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetRow(fx.Context(), &GetRowRequest{ + msg, err := fx.Service().GetRow(fx.Context(), &GetRowRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -154,7 +156,7 @@ func (fx *TablesServiceRowTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetRow(fx.Context(), &GetRowRequest{ + _, err := fx.Service().GetRow(fx.Context(), &GetRowRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -163,7 +165,7 @@ func (fx *TablesServiceRowTestSuiteConfig) 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.GetRow(fx.Context(), &GetRowRequest{ + _, err := fx.Service().GetRow(fx.Context(), &GetRowRequest{ Name: "tables/-/rows/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -179,7 +181,7 @@ func (fx *TablesServiceRowTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateRow(fx.Context(), &UpdateRowRequest{ + _, err := fx.Service().UpdateRow(fx.Context(), &UpdateRowRequest{ Row: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -191,7 +193,7 @@ func (fx *TablesServiceRowTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateRow(fx.Context(), &UpdateRowRequest{ + _, err := fx.Service().UpdateRow(fx.Context(), &UpdateRowRequest{ Row: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -202,11 +204,11 @@ func (fx *TablesServiceRowTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateRow(fx.Context(), &UpdateRowRequest{ + updated, err := fx.Service().UpdateRow(fx.Context(), &UpdateRowRequest{ Row: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetRow(fx.Context(), &GetRowRequest{ + persisted, err := fx.Service().GetRow(fx.Context(), &GetRowRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -220,7 +222,7 @@ func (fx *TablesServiceRowTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateRow(fx.Context(), &UpdateRowRequest{ + _, err := fx.Service().UpdateRow(fx.Context(), &UpdateRowRequest{ Row: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -229,7 +231,7 @@ func (fx *TablesServiceRowTestSuiteConfig) 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.UpdateRow(fx.Context(), &UpdateRowRequest{ + _, err := fx.Service().UpdateRow(fx.Context(), &UpdateRowRequest{ Row: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -247,7 +249,7 @@ func (fx *TablesServiceRowTestSuiteConfig) 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.ListRows(fx.Context(), &ListRowsRequest{ + _, err := fx.Service().ListRows(fx.Context(), &ListRowsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -257,7 +259,7 @@ func (fx *TablesServiceRowTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListRows(fx.Context(), &ListRowsRequest{ + _, err := fx.Service().ListRows(fx.Context(), &ListRowsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -268,7 +270,7 @@ func (fx *TablesServiceRowTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListRows(fx.Context(), &ListRowsRequest{ + _, err := fx.Service().ListRows(fx.Context(), &ListRowsRequest{ Parent: parent, PageSize: -10, }) @@ -286,7 +288,7 @@ func (fx *TablesServiceRowTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListRows(fx.Context(), &ListRowsRequest{ + response, err := fx.Service().ListRows(fx.Context(), &ListRowsRequest{ Parent: parent, PageSize: 999, }) @@ -305,7 +307,7 @@ func (fx *TablesServiceRowTestSuiteConfig) 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.ListRows(fx.Context(), &ListRowsRequest{ + response, err := fx.Service().ListRows(fx.Context(), &ListRowsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -316,7 +318,7 @@ func (fx *TablesServiceRowTestSuiteConfig) 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.ListRows(fx.Context(), &ListRowsRequest{ + response, err := fx.Service().ListRows(fx.Context(), &ListRowsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -330,7 +332,7 @@ func (fx *TablesServiceRowTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Row, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListRows(fx.Context(), &ListRowsRequest{ + response, err := fx.Service().ListRows(fx.Context(), &ListRowsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -359,12 +361,12 @@ func (fx *TablesServiceRowTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteRow(fx.Context(), &DeleteRowRequest{ + _, err := fx.Service().DeleteRow(fx.Context(), &DeleteRowRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListRows(fx.Context(), &ListRowsRequest{ + response, err := fx.Service().ListRows(fx.Context(), &ListRowsRequest{ Parent: parent, PageSize: 9999, }) @@ -387,7 +389,7 @@ func (fx *TablesServiceRowTestSuiteConfig) testDelete(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.DeleteRow(fx.Context(), &DeleteRowRequest{ + _, err := fx.Service().DeleteRow(fx.Context(), &DeleteRowRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -396,7 +398,7 @@ func (fx *TablesServiceRowTestSuiteConfig) testDelete(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.DeleteRow(fx.Context(), &DeleteRowRequest{ + _, err := fx.Service().DeleteRow(fx.Context(), &DeleteRowRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -407,7 +409,7 @@ func (fx *TablesServiceRowTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteRow(fx.Context(), &DeleteRowRequest{ + _, err := fx.Service().DeleteRow(fx.Context(), &DeleteRowRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -418,7 +420,7 @@ func (fx *TablesServiceRowTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteRow(fx.Context(), &DeleteRowRequest{ + _, err := fx.Service().DeleteRow(fx.Context(), &DeleteRowRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -429,12 +431,12 @@ func (fx *TablesServiceRowTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteRow(fx.Context(), &DeleteRowRequest{ + deleted, err := fx.Service().DeleteRow(fx.Context(), &DeleteRowRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteRow(fx.Context(), &DeleteRowRequest{ + _, err = fx.Service().DeleteRow(fx.Context(), &DeleteRowRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -443,7 +445,7 @@ func (fx *TablesServiceRowTestSuiteConfig) testDelete(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.DeleteRow(fx.Context(), &DeleteRowRequest{ + _, err := fx.Service().DeleteRow(fx.Context(), &DeleteRowRequest{ Name: "tables/-/rows/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -479,7 +481,7 @@ func (fx *TablesServiceRowTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *TablesServiceRowTestSuiteConfig) create(t *testing.T, parent string) *Row { t.Helper() - created, err := fx.service.CreateRow(fx.Context(), &CreateRowRequest{ + created, err := fx.Service().CreateRow(fx.Context(), &CreateRowRequest{ Parent: parent, Row: fx.Create(parent), }) @@ -488,9 +490,11 @@ func (fx *TablesServiceRowTestSuiteConfig) create(t *testing.T, parent string) * } type TablesServiceTableTestSuiteConfig struct { - service TablesServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() TablesServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -517,7 +521,7 @@ func (fx *TablesServiceTableTestSuiteConfig) 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.GetTable(fx.Context(), &GetTableRequest{ + _, err := fx.Service().GetTable(fx.Context(), &GetTableRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -526,7 +530,7 @@ func (fx *TablesServiceTableTestSuiteConfig) 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.GetTable(fx.Context(), &GetTableRequest{ + _, err := fx.Service().GetTable(fx.Context(), &GetTableRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -536,7 +540,7 @@ func (fx *TablesServiceTableTestSuiteConfig) testGet(t *testing.T) { t.Run("exists", func(t *testing.T) { fx.maybeSkip(t) created := fx.create(t) - msg, err := fx.service.GetTable(fx.Context(), &GetTableRequest{ + msg, err := fx.Service().GetTable(fx.Context(), &GetTableRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -547,7 +551,7 @@ func (fx *TablesServiceTableTestSuiteConfig) testGet(t *testing.T) { t.Run("not found", func(t *testing.T) { fx.maybeSkip(t) created := fx.create(t) - _, err := fx.service.GetTable(fx.Context(), &GetTableRequest{ + _, err := fx.Service().GetTable(fx.Context(), &GetTableRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -556,7 +560,7 @@ func (fx *TablesServiceTableTestSuiteConfig) 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.GetTable(fx.Context(), &GetTableRequest{ + _, err := fx.Service().GetTable(fx.Context(), &GetTableRequest{ Name: "tables/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -569,7 +573,7 @@ func (fx *TablesServiceTableTestSuiteConfig) testList(t *testing.T) { // Method should fail with InvalidArgument is provided page token is not valid. t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListTables(fx.Context(), &ListTablesRequest{ + _, err := fx.Service().ListTables(fx.Context(), &ListTablesRequest{ PageToken: "invalid page token", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -578,7 +582,7 @@ func (fx *TablesServiceTableTestSuiteConfig) testList(t *testing.T) { // Method should fail with InvalidArgument is provided page size is negative. t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListTables(fx.Context(), &ListTablesRequest{ + _, err := fx.Service().ListTables(fx.Context(), &ListTablesRequest{ PageSize: -10, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -605,9 +609,11 @@ func (fx *TablesServiceTableTestSuiteConfig) create(t *testing.T) *Table { } type TablesServiceWorkspaceTestSuiteConfig struct { - service TablesServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() TablesServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -634,7 +640,7 @@ func (fx *TablesServiceWorkspaceTestSuiteConfig) 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.GetWorkspace(fx.Context(), &GetWorkspaceRequest{ + _, err := fx.Service().GetWorkspace(fx.Context(), &GetWorkspaceRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -643,7 +649,7 @@ func (fx *TablesServiceWorkspaceTestSuiteConfig) 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.GetWorkspace(fx.Context(), &GetWorkspaceRequest{ + _, err := fx.Service().GetWorkspace(fx.Context(), &GetWorkspaceRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -653,7 +659,7 @@ func (fx *TablesServiceWorkspaceTestSuiteConfig) testGet(t *testing.T) { t.Run("exists", func(t *testing.T) { fx.maybeSkip(t) created := fx.create(t) - msg, err := fx.service.GetWorkspace(fx.Context(), &GetWorkspaceRequest{ + msg, err := fx.Service().GetWorkspace(fx.Context(), &GetWorkspaceRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -664,7 +670,7 @@ func (fx *TablesServiceWorkspaceTestSuiteConfig) testGet(t *testing.T) { t.Run("not found", func(t *testing.T) { fx.maybeSkip(t) created := fx.create(t) - _, err := fx.service.GetWorkspace(fx.Context(), &GetWorkspaceRequest{ + _, err := fx.Service().GetWorkspace(fx.Context(), &GetWorkspaceRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -673,7 +679,7 @@ func (fx *TablesServiceWorkspaceTestSuiteConfig) 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.GetWorkspace(fx.Context(), &GetWorkspaceRequest{ + _, err := fx.Service().GetWorkspace(fx.Context(), &GetWorkspaceRequest{ Name: "workspaces/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -686,7 +692,7 @@ func (fx *TablesServiceWorkspaceTestSuiteConfig) testList(t *testing.T) { // Method should fail with InvalidArgument is provided page token is not valid. t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListWorkspaces(fx.Context(), &ListWorkspacesRequest{ + _, err := fx.Service().ListWorkspaces(fx.Context(), &ListWorkspacesRequest{ PageToken: "invalid page token", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -695,7 +701,7 @@ func (fx *TablesServiceWorkspaceTestSuiteConfig) testList(t *testing.T) { // Method should fail with InvalidArgument is provided page size is negative. t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) - _, err := fx.service.ListWorkspaces(fx.Context(), &ListWorkspacesRequest{ + _, err := fx.Service().ListWorkspaces(fx.Context(), &ListWorkspacesRequest{ PageSize: -10, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) diff --git a/proto/gen/googleapis/gsuiteaddons/apiv1/gsuiteaddonspb/gsuiteaddons_aiptest.pb.go b/proto/gen/googleapis/gsuiteaddons/apiv1/gsuiteaddonspb/gsuiteaddons_aiptest.pb.go index 1c0f7f3..fe9ec72 100644 --- a/proto/gen/googleapis/gsuiteaddons/apiv1/gsuiteaddonspb/gsuiteaddons_aiptest.pb.go +++ b/proto/gen/googleapis/gsuiteaddons/apiv1/gsuiteaddonspb/gsuiteaddons_aiptest.pb.go @@ -22,7 +22,7 @@ type GSuiteAddOnsTestSuite struct { func (fx GSuiteAddOnsTestSuite) TestAuthorization(ctx context.Context, options GSuiteAddOnsAuthorizationTestSuiteConfig) { fx.T.Run("Authorization", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() GSuiteAddOnsServer { return fx.Server } options.test(t) }) } @@ -30,7 +30,7 @@ func (fx GSuiteAddOnsTestSuite) TestAuthorization(ctx context.Context, options G func (fx GSuiteAddOnsTestSuite) TestDeployment(ctx context.Context, options GSuiteAddOnsDeploymentTestSuiteConfig) { fx.T.Run("Deployment", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() GSuiteAddOnsServer { return fx.Server } options.test(t) }) } @@ -38,15 +38,17 @@ func (fx GSuiteAddOnsTestSuite) TestDeployment(ctx context.Context, options GSui func (fx GSuiteAddOnsTestSuite) TestInstallStatus(ctx context.Context, options GSuiteAddOnsInstallStatusTestSuiteConfig) { fx.T.Run("InstallStatus", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() GSuiteAddOnsServer { return fx.Server } options.test(t) }) } type GSuiteAddOnsAuthorizationTestSuiteConfig struct { - service GSuiteAddOnsServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() GSuiteAddOnsServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -72,7 +74,7 @@ func (fx *GSuiteAddOnsAuthorizationTestSuiteConfig) 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.GetAuthorization(fx.Context(), &GetAuthorizationRequest{ + _, err := fx.Service().GetAuthorization(fx.Context(), &GetAuthorizationRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -81,7 +83,7 @@ func (fx *GSuiteAddOnsAuthorizationTestSuiteConfig) 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.GetAuthorization(fx.Context(), &GetAuthorizationRequest{ + _, err := fx.Service().GetAuthorization(fx.Context(), &GetAuthorizationRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -91,7 +93,7 @@ func (fx *GSuiteAddOnsAuthorizationTestSuiteConfig) testGet(t *testing.T) { t.Run("exists", func(t *testing.T) { fx.maybeSkip(t) created := fx.create(t) - msg, err := fx.service.GetAuthorization(fx.Context(), &GetAuthorizationRequest{ + msg, err := fx.Service().GetAuthorization(fx.Context(), &GetAuthorizationRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -102,7 +104,7 @@ func (fx *GSuiteAddOnsAuthorizationTestSuiteConfig) testGet(t *testing.T) { t.Run("not found", func(t *testing.T) { fx.maybeSkip(t) created := fx.create(t) - _, err := fx.service.GetAuthorization(fx.Context(), &GetAuthorizationRequest{ + _, err := fx.Service().GetAuthorization(fx.Context(), &GetAuthorizationRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -111,7 +113,7 @@ func (fx *GSuiteAddOnsAuthorizationTestSuiteConfig) 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.GetAuthorization(fx.Context(), &GetAuthorizationRequest{ + _, err := fx.Service().GetAuthorization(fx.Context(), &GetAuthorizationRequest{ Name: "projects/-/authorization", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -138,9 +140,11 @@ func (fx *GSuiteAddOnsAuthorizationTestSuiteConfig) create(t *testing.T) *Author } type GSuiteAddOnsDeploymentTestSuiteConfig struct { - service GSuiteAddOnsServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() GSuiteAddOnsServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -171,7 +175,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) 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.CreateDeployment(fx.Context(), &CreateDeploymentRequest{ + _, err := fx.Service().CreateDeployment(fx.Context(), &CreateDeploymentRequest{ Parent: "", Deployment: fx.Create(fx.nextParent(t, false)), }) @@ -181,7 +185,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) 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.CreateDeployment(fx.Context(), &CreateDeploymentRequest{ + _, err := fx.Service().CreateDeployment(fx.Context(), &CreateDeploymentRequest{ Parent: "invalid resource name", Deployment: fx.Create(fx.nextParent(t, false)), }) @@ -192,12 +196,12 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testCreate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateDeployment(fx.Context(), &CreateDeploymentRequest{ + msg, err := fx.Service().CreateDeployment(fx.Context(), &CreateDeploymentRequest{ Parent: parent, Deployment: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetDeployment(fx.Context(), &GetDeploymentRequest{ + persisted, err := fx.Service().GetDeployment(fx.Context(), &GetDeploymentRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -218,7 +222,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("run_function") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDeployment(fx.Context(), &CreateDeploymentRequest{ + _, err := fx.Service().CreateDeployment(fx.Context(), &CreateDeploymentRequest{ Parent: parent, Deployment: msg, }) @@ -234,7 +238,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("run_function") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDeployment(fx.Context(), &CreateDeploymentRequest{ + _, err := fx.Service().CreateDeployment(fx.Context(), &CreateDeploymentRequest{ Parent: parent, Deployment: msg, }) @@ -250,7 +254,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("run_function") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDeployment(fx.Context(), &CreateDeploymentRequest{ + _, err := fx.Service().CreateDeployment(fx.Context(), &CreateDeploymentRequest{ Parent: parent, Deployment: msg, }) @@ -266,7 +270,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("run_function") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateDeployment(fx.Context(), &CreateDeploymentRequest{ + _, err := fx.Service().CreateDeployment(fx.Context(), &CreateDeploymentRequest{ Parent: parent, Deployment: msg, }) @@ -278,7 +282,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testCreate(t *testing.T) { t.Run("etag populated", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - created, _ := fx.service.CreateDeployment(fx.Context(), &CreateDeploymentRequest{ + created, _ := fx.Service().CreateDeployment(fx.Context(), &CreateDeploymentRequest{ Parent: parent, Deployment: fx.Create(parent), }) @@ -292,7 +296,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) 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.GetDeployment(fx.Context(), &GetDeploymentRequest{ + _, err := fx.Service().GetDeployment(fx.Context(), &GetDeploymentRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -301,7 +305,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) 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.GetDeployment(fx.Context(), &GetDeploymentRequest{ + _, err := fx.Service().GetDeployment(fx.Context(), &GetDeploymentRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -312,7 +316,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetDeployment(fx.Context(), &GetDeploymentRequest{ + msg, err := fx.Service().GetDeployment(fx.Context(), &GetDeploymentRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -324,7 +328,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetDeployment(fx.Context(), &GetDeploymentRequest{ + _, err := fx.Service().GetDeployment(fx.Context(), &GetDeploymentRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -333,7 +337,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) 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.GetDeployment(fx.Context(), &GetDeploymentRequest{ + _, err := fx.Service().GetDeployment(fx.Context(), &GetDeploymentRequest{ Name: "projects/-/deployments/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -346,7 +350,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) 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.ListDeployments(fx.Context(), &ListDeploymentsRequest{ + _, err := fx.Service().ListDeployments(fx.Context(), &ListDeploymentsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -356,7 +360,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListDeployments(fx.Context(), &ListDeploymentsRequest{ + _, err := fx.Service().ListDeployments(fx.Context(), &ListDeploymentsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -367,7 +371,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListDeployments(fx.Context(), &ListDeploymentsRequest{ + _, err := fx.Service().ListDeployments(fx.Context(), &ListDeploymentsRequest{ Parent: parent, PageSize: -10, }) @@ -385,7 +389,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListDeployments(fx.Context(), &ListDeploymentsRequest{ + response, err := fx.Service().ListDeployments(fx.Context(), &ListDeploymentsRequest{ Parent: parent, PageSize: 999, }) @@ -404,7 +408,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) 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.ListDeployments(fx.Context(), &ListDeploymentsRequest{ + response, err := fx.Service().ListDeployments(fx.Context(), &ListDeploymentsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -415,7 +419,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) 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.ListDeployments(fx.Context(), &ListDeploymentsRequest{ + response, err := fx.Service().ListDeployments(fx.Context(), &ListDeploymentsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -429,7 +433,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Deployment, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListDeployments(fx.Context(), &ListDeploymentsRequest{ + response, err := fx.Service().ListDeployments(fx.Context(), &ListDeploymentsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -458,12 +462,12 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ + _, err := fx.Service().DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListDeployments(fx.Context(), &ListDeploymentsRequest{ + response, err := fx.Service().ListDeployments(fx.Context(), &ListDeploymentsRequest{ Parent: parent, PageSize: 9999, }) @@ -486,7 +490,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testDelete(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.DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ + _, err := fx.Service().DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -495,7 +499,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testDelete(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.DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ + _, err := fx.Service().DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -506,7 +510,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ + _, err := fx.Service().DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -517,7 +521,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ + _, err := fx.Service().DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -528,12 +532,12 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ + deleted, err := fx.Service().DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ + _, err = fx.Service().DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -542,7 +546,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testDelete(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.DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ + _, err := fx.Service().DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ Name: "projects/-/deployments/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -553,7 +557,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ + _, err := fx.Service().DeleteDeployment(fx.Context(), &DeleteDeploymentRequest{ Name: created.Name, Etag: `"99999"`, }) @@ -590,7 +594,7 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) create(t *testing.T, parent string) *Deployment { t.Helper() - created, err := fx.service.CreateDeployment(fx.Context(), &CreateDeploymentRequest{ + created, err := fx.Service().CreateDeployment(fx.Context(), &CreateDeploymentRequest{ Parent: parent, Deployment: fx.Create(parent), }) @@ -599,9 +603,11 @@ func (fx *GSuiteAddOnsDeploymentTestSuiteConfig) create(t *testing.T, parent str } type GSuiteAddOnsInstallStatusTestSuiteConfig struct { - service GSuiteAddOnsServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() GSuiteAddOnsServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -632,7 +638,7 @@ func (fx *GSuiteAddOnsInstallStatusTestSuiteConfig) 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.GetInstallStatus(fx.Context(), &GetInstallStatusRequest{ + _, err := fx.Service().GetInstallStatus(fx.Context(), &GetInstallStatusRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -641,7 +647,7 @@ func (fx *GSuiteAddOnsInstallStatusTestSuiteConfig) 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.GetInstallStatus(fx.Context(), &GetInstallStatusRequest{ + _, err := fx.Service().GetInstallStatus(fx.Context(), &GetInstallStatusRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -652,7 +658,7 @@ func (fx *GSuiteAddOnsInstallStatusTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetInstallStatus(fx.Context(), &GetInstallStatusRequest{ + msg, err := fx.Service().GetInstallStatus(fx.Context(), &GetInstallStatusRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -664,7 +670,7 @@ func (fx *GSuiteAddOnsInstallStatusTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetInstallStatus(fx.Context(), &GetInstallStatusRequest{ + _, err := fx.Service().GetInstallStatus(fx.Context(), &GetInstallStatusRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -673,7 +679,7 @@ func (fx *GSuiteAddOnsInstallStatusTestSuiteConfig) 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.GetInstallStatus(fx.Context(), &GetInstallStatusRequest{ + _, err := fx.Service().GetInstallStatus(fx.Context(), &GetInstallStatusRequest{ Name: "projects/-/deployments/-/installStatus", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) diff --git a/proto/gen/googleapis/pubsub/apiv1/pubsubpb/pubsub_aiptest.pb.go b/proto/gen/googleapis/pubsub/apiv1/pubsubpb/pubsub_aiptest.pb.go index 8ebd57d..c441c8d 100644 --- a/proto/gen/googleapis/pubsub/apiv1/pubsubpb/pubsub_aiptest.pb.go +++ b/proto/gen/googleapis/pubsub/apiv1/pubsubpb/pubsub_aiptest.pb.go @@ -22,15 +22,17 @@ type PublisherTestSuite struct { func (fx PublisherTestSuite) TestTopic(ctx context.Context, options PublisherTopicTestSuiteConfig) { fx.T.Run("Topic", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() PublisherServer { return fx.Server } options.test(t) }) } type PublisherTopicTestSuiteConfig struct { - service PublisherServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() PublisherServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -67,7 +69,7 @@ func (fx *PublisherTopicTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateTopic(fx.Context(), &UpdateTopicRequest{ + _, err := fx.Service().UpdateTopic(fx.Context(), &UpdateTopicRequest{ Topic: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -79,7 +81,7 @@ func (fx *PublisherTopicTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateTopic(fx.Context(), &UpdateTopicRequest{ + _, err := fx.Service().UpdateTopic(fx.Context(), &UpdateTopicRequest{ Topic: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -92,7 +94,7 @@ func (fx *PublisherTopicTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateTopic(fx.Context(), &UpdateTopicRequest{ + _, err := fx.Service().UpdateTopic(fx.Context(), &UpdateTopicRequest{ Topic: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -101,7 +103,7 @@ func (fx *PublisherTopicTestSuiteConfig) 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.UpdateTopic(fx.Context(), &UpdateTopicRequest{ + _, err := fx.Service().UpdateTopic(fx.Context(), &UpdateTopicRequest{ Topic: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -125,7 +127,7 @@ func (fx *PublisherTopicTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateTopic(fx.Context(), &UpdateTopicRequest{ + _, err := fx.Service().UpdateTopic(fx.Context(), &UpdateTopicRequest{ Topic: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -144,7 +146,7 @@ func (fx *PublisherTopicTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("schema") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateTopic(fx.Context(), &UpdateTopicRequest{ + _, err := fx.Service().UpdateTopic(fx.Context(), &UpdateTopicRequest{ Topic: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -163,7 +165,7 @@ func (fx *PublisherTopicTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("stream_arn") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateTopic(fx.Context(), &UpdateTopicRequest{ + _, err := fx.Service().UpdateTopic(fx.Context(), &UpdateTopicRequest{ Topic: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -182,7 +184,7 @@ func (fx *PublisherTopicTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("consumer_arn") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateTopic(fx.Context(), &UpdateTopicRequest{ + _, err := fx.Service().UpdateTopic(fx.Context(), &UpdateTopicRequest{ Topic: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -201,7 +203,7 @@ func (fx *PublisherTopicTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("aws_role_arn") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateTopic(fx.Context(), &UpdateTopicRequest{ + _, err := fx.Service().UpdateTopic(fx.Context(), &UpdateTopicRequest{ Topic: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -220,7 +222,7 @@ func (fx *PublisherTopicTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("gcp_service_account") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateTopic(fx.Context(), &UpdateTopicRequest{ + _, err := fx.Service().UpdateTopic(fx.Context(), &UpdateTopicRequest{ Topic: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -279,7 +281,7 @@ type SubscriberTestSuite struct { func (fx SubscriberTestSuite) TestSnapshot(ctx context.Context, options SubscriberSnapshotTestSuiteConfig) { fx.T.Run("Snapshot", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() SubscriberServer { return fx.Server } options.test(t) }) } @@ -287,15 +289,17 @@ func (fx SubscriberTestSuite) TestSnapshot(ctx context.Context, options Subscrib func (fx SubscriberTestSuite) TestSubscription(ctx context.Context, options SubscriberSubscriptionTestSuiteConfig) { fx.T.Run("Subscription", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() SubscriberServer { return fx.Server } options.test(t) }) } type SubscriberSnapshotTestSuiteConfig struct { - service SubscriberServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() SubscriberServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -332,7 +336,7 @@ func (fx *SubscriberSnapshotTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateSnapshot(fx.Context(), &UpdateSnapshotRequest{ + _, err := fx.Service().UpdateSnapshot(fx.Context(), &UpdateSnapshotRequest{ Snapshot: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -344,7 +348,7 @@ func (fx *SubscriberSnapshotTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateSnapshot(fx.Context(), &UpdateSnapshotRequest{ + _, err := fx.Service().UpdateSnapshot(fx.Context(), &UpdateSnapshotRequest{ Snapshot: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -357,7 +361,7 @@ func (fx *SubscriberSnapshotTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateSnapshot(fx.Context(), &UpdateSnapshotRequest{ + _, err := fx.Service().UpdateSnapshot(fx.Context(), &UpdateSnapshotRequest{ Snapshot: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -366,7 +370,7 @@ func (fx *SubscriberSnapshotTestSuiteConfig) 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.UpdateSnapshot(fx.Context(), &UpdateSnapshotRequest{ + _, err := fx.Service().UpdateSnapshot(fx.Context(), &UpdateSnapshotRequest{ Snapshot: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -416,9 +420,11 @@ func (fx *SubscriberSnapshotTestSuiteConfig) create(t *testing.T, parent string) } type SubscriberSubscriptionTestSuiteConfig struct { - service SubscriberServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() SubscriberServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -455,7 +461,7 @@ func (fx *SubscriberSubscriptionTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateSubscription(fx.Context(), &UpdateSubscriptionRequest{ + _, err := fx.Service().UpdateSubscription(fx.Context(), &UpdateSubscriptionRequest{ Subscription: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -467,7 +473,7 @@ func (fx *SubscriberSubscriptionTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateSubscription(fx.Context(), &UpdateSubscriptionRequest{ + _, err := fx.Service().UpdateSubscription(fx.Context(), &UpdateSubscriptionRequest{ Subscription: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -480,7 +486,7 @@ func (fx *SubscriberSubscriptionTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateSubscription(fx.Context(), &UpdateSubscriptionRequest{ + _, err := fx.Service().UpdateSubscription(fx.Context(), &UpdateSubscriptionRequest{ Subscription: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -489,7 +495,7 @@ func (fx *SubscriberSubscriptionTestSuiteConfig) 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.UpdateSubscription(fx.Context(), &UpdateSubscriptionRequest{ + _, err := fx.Service().UpdateSubscription(fx.Context(), &UpdateSubscriptionRequest{ Subscription: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -513,7 +519,7 @@ func (fx *SubscriberSubscriptionTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateSubscription(fx.Context(), &UpdateSubscriptionRequest{ + _, err := fx.Service().UpdateSubscription(fx.Context(), &UpdateSubscriptionRequest{ Subscription: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -532,7 +538,7 @@ func (fx *SubscriberSubscriptionTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("topic") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateSubscription(fx.Context(), &UpdateSubscriptionRequest{ + _, err := fx.Service().UpdateSubscription(fx.Context(), &UpdateSubscriptionRequest{ Subscription: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -551,7 +557,7 @@ func (fx *SubscriberSubscriptionTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("bucket") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateSubscription(fx.Context(), &UpdateSubscriptionRequest{ + _, err := fx.Service().UpdateSubscription(fx.Context(), &UpdateSubscriptionRequest{ Subscription: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ diff --git a/proto/gen/googleapis/pubsub/apiv1/pubsubpb/schema_aiptest.pb.go b/proto/gen/googleapis/pubsub/apiv1/pubsubpb/schema_aiptest.pb.go index 428b228..03b482b 100644 --- a/proto/gen/googleapis/pubsub/apiv1/pubsubpb/schema_aiptest.pb.go +++ b/proto/gen/googleapis/pubsub/apiv1/pubsubpb/schema_aiptest.pb.go @@ -22,15 +22,17 @@ type SchemaServiceTestSuite struct { func (fx SchemaServiceTestSuite) TestSchema(ctx context.Context, options SchemaServiceSchemaTestSuiteConfig) { fx.T.Run("Schema", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() SchemaServiceServer { return fx.Server } options.test(t) }) } type SchemaServiceSchemaTestSuiteConfig struct { - service SchemaServiceServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() SchemaServiceServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -61,7 +63,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) 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.CreateSchema(fx.Context(), &CreateSchemaRequest{ + _, err := fx.Service().CreateSchema(fx.Context(), &CreateSchemaRequest{ Parent: "", Schema: fx.Create(fx.nextParent(t, false)), }) @@ -71,7 +73,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) 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.CreateSchema(fx.Context(), &CreateSchemaRequest{ + _, err := fx.Service().CreateSchema(fx.Context(), &CreateSchemaRequest{ Parent: "invalid resource name", Schema: fx.Create(fx.nextParent(t, false)), }) @@ -82,12 +84,12 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) testCreate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateSchema(fx.Context(), &CreateSchemaRequest{ + msg, err := fx.Service().CreateSchema(fx.Context(), &CreateSchemaRequest{ Parent: parent, Schema: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetSchema(fx.Context(), &GetSchemaRequest{ + persisted, err := fx.Service().GetSchema(fx.Context(), &GetSchemaRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -108,7 +110,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateSchema(fx.Context(), &CreateSchemaRequest{ + _, err := fx.Service().CreateSchema(fx.Context(), &CreateSchemaRequest{ Parent: parent, Schema: msg, }) @@ -123,7 +125,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) 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.GetSchema(fx.Context(), &GetSchemaRequest{ + _, err := fx.Service().GetSchema(fx.Context(), &GetSchemaRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -132,7 +134,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) 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.GetSchema(fx.Context(), &GetSchemaRequest{ + _, err := fx.Service().GetSchema(fx.Context(), &GetSchemaRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -143,7 +145,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetSchema(fx.Context(), &GetSchemaRequest{ + msg, err := fx.Service().GetSchema(fx.Context(), &GetSchemaRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -155,7 +157,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetSchema(fx.Context(), &GetSchemaRequest{ + _, err := fx.Service().GetSchema(fx.Context(), &GetSchemaRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -164,7 +166,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) 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.GetSchema(fx.Context(), &GetSchemaRequest{ + _, err := fx.Service().GetSchema(fx.Context(), &GetSchemaRequest{ Name: "projects/-/schemas/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -177,7 +179,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) 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.ListSchemas(fx.Context(), &ListSchemasRequest{ + _, err := fx.Service().ListSchemas(fx.Context(), &ListSchemasRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -187,7 +189,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListSchemas(fx.Context(), &ListSchemasRequest{ + _, err := fx.Service().ListSchemas(fx.Context(), &ListSchemasRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -198,7 +200,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListSchemas(fx.Context(), &ListSchemasRequest{ + _, err := fx.Service().ListSchemas(fx.Context(), &ListSchemasRequest{ Parent: parent, PageSize: -10, }) @@ -216,7 +218,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListSchemas(fx.Context(), &ListSchemasRequest{ + response, err := fx.Service().ListSchemas(fx.Context(), &ListSchemasRequest{ Parent: parent, PageSize: 999, }) @@ -235,7 +237,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) 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.ListSchemas(fx.Context(), &ListSchemasRequest{ + response, err := fx.Service().ListSchemas(fx.Context(), &ListSchemasRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -246,7 +248,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) 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.ListSchemas(fx.Context(), &ListSchemasRequest{ + response, err := fx.Service().ListSchemas(fx.Context(), &ListSchemasRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -260,7 +262,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Schema, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListSchemas(fx.Context(), &ListSchemasRequest{ + response, err := fx.Service().ListSchemas(fx.Context(), &ListSchemasRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -289,12 +291,12 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteSchemaRevision(fx.Context(), &DeleteSchemaRevisionRequest{ + _, err := fx.Service().DeleteSchemaRevision(fx.Context(), &DeleteSchemaRevisionRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListSchemas(fx.Context(), &ListSchemasRequest{ + response, err := fx.Service().ListSchemas(fx.Context(), &ListSchemasRequest{ Parent: parent, PageSize: 9999, }) @@ -317,7 +319,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) testDelete(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.DeleteSchemaRevision(fx.Context(), &DeleteSchemaRevisionRequest{ + _, err := fx.Service().DeleteSchemaRevision(fx.Context(), &DeleteSchemaRevisionRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -326,7 +328,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) testDelete(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.DeleteSchemaRevision(fx.Context(), &DeleteSchemaRevisionRequest{ + _, err := fx.Service().DeleteSchemaRevision(fx.Context(), &DeleteSchemaRevisionRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -337,7 +339,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteSchemaRevision(fx.Context(), &DeleteSchemaRevisionRequest{ + _, err := fx.Service().DeleteSchemaRevision(fx.Context(), &DeleteSchemaRevisionRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -348,7 +350,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteSchemaRevision(fx.Context(), &DeleteSchemaRevisionRequest{ + _, err := fx.Service().DeleteSchemaRevision(fx.Context(), &DeleteSchemaRevisionRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -359,12 +361,12 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteSchemaRevision(fx.Context(), &DeleteSchemaRevisionRequest{ + deleted, err := fx.Service().DeleteSchemaRevision(fx.Context(), &DeleteSchemaRevisionRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteSchemaRevision(fx.Context(), &DeleteSchemaRevisionRequest{ + _, err = fx.Service().DeleteSchemaRevision(fx.Context(), &DeleteSchemaRevisionRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -373,7 +375,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) testDelete(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.DeleteSchemaRevision(fx.Context(), &DeleteSchemaRevisionRequest{ + _, err := fx.Service().DeleteSchemaRevision(fx.Context(), &DeleteSchemaRevisionRequest{ Name: "projects/-/schemas/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -409,7 +411,7 @@ func (fx *SchemaServiceSchemaTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *SchemaServiceSchemaTestSuiteConfig) create(t *testing.T, parent string) *Schema { t.Helper() - created, err := fx.service.CreateSchema(fx.Context(), &CreateSchemaRequest{ + created, err := fx.Service().CreateSchema(fx.Context(), &CreateSchemaRequest{ Parent: parent, Schema: fx.Create(parent), }) diff --git a/proto/gen/googleapis/scheduler/apiv1/schedulerpb/cloudscheduler_aiptest.pb.go b/proto/gen/googleapis/scheduler/apiv1/schedulerpb/cloudscheduler_aiptest.pb.go index 2601b35..7ce08e4 100644 --- a/proto/gen/googleapis/scheduler/apiv1/schedulerpb/cloudscheduler_aiptest.pb.go +++ b/proto/gen/googleapis/scheduler/apiv1/schedulerpb/cloudscheduler_aiptest.pb.go @@ -23,15 +23,17 @@ type CloudSchedulerTestSuite struct { func (fx CloudSchedulerTestSuite) TestJob(ctx context.Context, options CloudSchedulerJobTestSuiteConfig) { fx.T.Run("Job", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() CloudSchedulerServer { return fx.Server } options.test(t) }) } type CloudSchedulerJobTestSuiteConfig struct { - service CloudSchedulerServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() CloudSchedulerServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -66,7 +68,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) 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.CreateJob(fx.Context(), &CreateJobRequest{ + _, err := fx.Service().CreateJob(fx.Context(), &CreateJobRequest{ Parent: "", Job: fx.Create(fx.nextParent(t, false)), }) @@ -76,7 +78,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) 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.CreateJob(fx.Context(), &CreateJobRequest{ + _, err := fx.Service().CreateJob(fx.Context(), &CreateJobRequest{ Parent: "invalid resource name", Job: fx.Create(fx.nextParent(t, false)), }) @@ -87,12 +89,12 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testCreate(t *testing.T) { t.Run("persisted", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - msg, err := fx.service.CreateJob(fx.Context(), &CreateJobRequest{ + msg, err := fx.Service().CreateJob(fx.Context(), &CreateJobRequest{ Parent: parent, Job: fx.Create(parent), }) assert.NilError(t, err) - persisted, err := fx.service.GetJob(fx.Context(), &GetJobRequest{ + persisted, err := fx.Service().GetJob(fx.Context(), &GetJobRequest{ Name: msg.Name, }) assert.NilError(t, err) @@ -112,7 +114,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.TopicName = "invalid resource name" - _, err := fx.service.CreateJob(fx.Context(), &CreateJobRequest{ + _, err := fx.Service().CreateJob(fx.Context(), &CreateJobRequest{ Parent: parent, Job: msg, }) @@ -127,7 +129,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) 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.GetJob(fx.Context(), &GetJobRequest{ + _, err := fx.Service().GetJob(fx.Context(), &GetJobRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -136,7 +138,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) 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.GetJob(fx.Context(), &GetJobRequest{ + _, err := fx.Service().GetJob(fx.Context(), &GetJobRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -147,7 +149,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetJob(fx.Context(), &GetJobRequest{ + msg, err := fx.Service().GetJob(fx.Context(), &GetJobRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -159,7 +161,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetJob(fx.Context(), &GetJobRequest{ + _, err := fx.Service().GetJob(fx.Context(), &GetJobRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -168,7 +170,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) 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.GetJob(fx.Context(), &GetJobRequest{ + _, err := fx.Service().GetJob(fx.Context(), &GetJobRequest{ Name: "projects/-/locations/-/jobs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -184,7 +186,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateJob(fx.Context(), &UpdateJobRequest{ + _, err := fx.Service().UpdateJob(fx.Context(), &UpdateJobRequest{ Job: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -196,7 +198,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateJob(fx.Context(), &UpdateJobRequest{ + _, err := fx.Service().UpdateJob(fx.Context(), &UpdateJobRequest{ Job: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -207,11 +209,11 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateJob(fx.Context(), &UpdateJobRequest{ + updated, err := fx.Service().UpdateJob(fx.Context(), &UpdateJobRequest{ Job: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetJob(fx.Context(), &GetJobRequest{ + persisted, err := fx.Service().GetJob(fx.Context(), &GetJobRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -225,7 +227,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateJob(fx.Context(), &UpdateJobRequest{ + _, err := fx.Service().UpdateJob(fx.Context(), &UpdateJobRequest{ Job: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -234,7 +236,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) 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.UpdateJob(fx.Context(), &UpdateJobRequest{ + _, err := fx.Service().UpdateJob(fx.Context(), &UpdateJobRequest{ Job: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -252,7 +254,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) 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.ListJobs(fx.Context(), &ListJobsRequest{ + _, err := fx.Service().ListJobs(fx.Context(), &ListJobsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -262,7 +264,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListJobs(fx.Context(), &ListJobsRequest{ + _, err := fx.Service().ListJobs(fx.Context(), &ListJobsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -273,7 +275,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListJobs(fx.Context(), &ListJobsRequest{ + _, err := fx.Service().ListJobs(fx.Context(), &ListJobsRequest{ Parent: parent, PageSize: -10, }) @@ -291,7 +293,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListJobs(fx.Context(), &ListJobsRequest{ + response, err := fx.Service().ListJobs(fx.Context(), &ListJobsRequest{ Parent: parent, PageSize: 999, }) @@ -310,7 +312,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) 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.ListJobs(fx.Context(), &ListJobsRequest{ + response, err := fx.Service().ListJobs(fx.Context(), &ListJobsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -321,7 +323,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) 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.ListJobs(fx.Context(), &ListJobsRequest{ + response, err := fx.Service().ListJobs(fx.Context(), &ListJobsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -335,7 +337,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Job, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListJobs(fx.Context(), &ListJobsRequest{ + response, err := fx.Service().ListJobs(fx.Context(), &ListJobsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -364,12 +366,12 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteJob(fx.Context(), &DeleteJobRequest{ + _, err := fx.Service().DeleteJob(fx.Context(), &DeleteJobRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListJobs(fx.Context(), &ListJobsRequest{ + response, err := fx.Service().ListJobs(fx.Context(), &ListJobsRequest{ Parent: parent, PageSize: 9999, }) @@ -392,7 +394,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testDelete(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.DeleteJob(fx.Context(), &DeleteJobRequest{ + _, err := fx.Service().DeleteJob(fx.Context(), &DeleteJobRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -401,7 +403,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testDelete(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.DeleteJob(fx.Context(), &DeleteJobRequest{ + _, err := fx.Service().DeleteJob(fx.Context(), &DeleteJobRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -412,7 +414,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteJob(fx.Context(), &DeleteJobRequest{ + _, err := fx.Service().DeleteJob(fx.Context(), &DeleteJobRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -423,7 +425,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteJob(fx.Context(), &DeleteJobRequest{ + _, err := fx.Service().DeleteJob(fx.Context(), &DeleteJobRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -434,12 +436,12 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteJob(fx.Context(), &DeleteJobRequest{ + deleted, err := fx.Service().DeleteJob(fx.Context(), &DeleteJobRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteJob(fx.Context(), &DeleteJobRequest{ + _, err = fx.Service().DeleteJob(fx.Context(), &DeleteJobRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -448,7 +450,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) testDelete(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.DeleteJob(fx.Context(), &DeleteJobRequest{ + _, err := fx.Service().DeleteJob(fx.Context(), &DeleteJobRequest{ Name: "projects/-/locations/-/jobs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -484,7 +486,7 @@ func (fx *CloudSchedulerJobTestSuiteConfig) maybeSkip(t *testing.T) { func (fx *CloudSchedulerJobTestSuiteConfig) create(t *testing.T, parent string) *Job { t.Helper() - created, err := fx.service.CreateJob(fx.Context(), &CreateJobRequest{ + created, err := fx.Service().CreateJob(fx.Context(), &CreateJobRequest{ Parent: parent, Job: fx.Create(parent), }) diff --git a/proto/gen/googleapis/spanner/admin/database/apiv1/databasepb/spanner_database_admin_aiptest.pb.go b/proto/gen/googleapis/spanner/admin/database/apiv1/databasepb/spanner_database_admin_aiptest.pb.go index 772e853..7c0fc81 100644 --- a/proto/gen/googleapis/spanner/admin/database/apiv1/databasepb/spanner_database_admin_aiptest.pb.go +++ b/proto/gen/googleapis/spanner/admin/database/apiv1/databasepb/spanner_database_admin_aiptest.pb.go @@ -24,7 +24,7 @@ type DatabaseAdminTestSuite struct { func (fx DatabaseAdminTestSuite) TestBackup(ctx context.Context, options DatabaseAdminBackupTestSuiteConfig) { fx.T.Run("Backup", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() DatabaseAdminServer { return fx.Server } options.test(t) }) } @@ -32,7 +32,7 @@ func (fx DatabaseAdminTestSuite) TestBackup(ctx context.Context, options Databas func (fx DatabaseAdminTestSuite) TestDatabase(ctx context.Context, options DatabaseAdminDatabaseTestSuiteConfig) { fx.T.Run("Database", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() DatabaseAdminServer { return fx.Server } options.test(t) }) } @@ -40,15 +40,17 @@ func (fx DatabaseAdminTestSuite) TestDatabase(ctx context.Context, options Datab func (fx DatabaseAdminTestSuite) TestDatabaseRole(ctx context.Context, options DatabaseAdminDatabaseRoleTestSuiteConfig) { fx.T.Run("DatabaseRole", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() DatabaseAdminServer { return fx.Server } options.test(t) }) } type DatabaseAdminBackupTestSuiteConfig struct { - service DatabaseAdminServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() DatabaseAdminServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -83,7 +85,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) 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.CreateBackup(fx.Context(), &CreateBackupRequest{ + _, err := fx.Service().CreateBackup(fx.Context(), &CreateBackupRequest{ Parent: "", Backup: fx.Create(fx.nextParent(t, false)), }) @@ -93,7 +95,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) 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.CreateBackup(fx.Context(), &CreateBackupRequest{ + _, err := fx.Service().CreateBackup(fx.Context(), &CreateBackupRequest{ Parent: "invalid resource name", Backup: fx.Create(fx.nextParent(t, false)), }) @@ -113,7 +115,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Database = "invalid resource name" - _, err := fx.service.CreateBackup(fx.Context(), &CreateBackupRequest{ + _, err := fx.Service().CreateBackup(fx.Context(), &CreateBackupRequest{ Parent: parent, Backup: msg, }) @@ -128,7 +130,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) 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.GetBackup(fx.Context(), &GetBackupRequest{ + _, err := fx.Service().GetBackup(fx.Context(), &GetBackupRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -137,7 +139,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) 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.GetBackup(fx.Context(), &GetBackupRequest{ + _, err := fx.Service().GetBackup(fx.Context(), &GetBackupRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -148,7 +150,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetBackup(fx.Context(), &GetBackupRequest{ + msg, err := fx.Service().GetBackup(fx.Context(), &GetBackupRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -160,7 +162,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetBackup(fx.Context(), &GetBackupRequest{ + _, err := fx.Service().GetBackup(fx.Context(), &GetBackupRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -169,7 +171,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) 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.GetBackup(fx.Context(), &GetBackupRequest{ + _, err := fx.Service().GetBackup(fx.Context(), &GetBackupRequest{ Name: "projects/-/instances/-/backups/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -185,7 +187,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateBackup(fx.Context(), &UpdateBackupRequest{ + _, err := fx.Service().UpdateBackup(fx.Context(), &UpdateBackupRequest{ Backup: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -197,7 +199,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateBackup(fx.Context(), &UpdateBackupRequest{ + _, err := fx.Service().UpdateBackup(fx.Context(), &UpdateBackupRequest{ Backup: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -208,11 +210,11 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - updated, err := fx.service.UpdateBackup(fx.Context(), &UpdateBackupRequest{ + updated, err := fx.Service().UpdateBackup(fx.Context(), &UpdateBackupRequest{ Backup: created, }) assert.NilError(t, err) - persisted, err := fx.service.GetBackup(fx.Context(), &GetBackupRequest{ + persisted, err := fx.Service().GetBackup(fx.Context(), &GetBackupRequest{ Name: updated.Name, }) assert.NilError(t, err) @@ -226,7 +228,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateBackup(fx.Context(), &UpdateBackupRequest{ + _, err := fx.Service().UpdateBackup(fx.Context(), &UpdateBackupRequest{ Backup: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -235,7 +237,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) 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.UpdateBackup(fx.Context(), &UpdateBackupRequest{ + _, err := fx.Service().UpdateBackup(fx.Context(), &UpdateBackupRequest{ Backup: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -253,7 +255,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) 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.ListBackups(fx.Context(), &ListBackupsRequest{ + _, err := fx.Service().ListBackups(fx.Context(), &ListBackupsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -263,7 +265,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListBackups(fx.Context(), &ListBackupsRequest{ + _, err := fx.Service().ListBackups(fx.Context(), &ListBackupsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -274,7 +276,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListBackups(fx.Context(), &ListBackupsRequest{ + _, err := fx.Service().ListBackups(fx.Context(), &ListBackupsRequest{ Parent: parent, PageSize: -10, }) @@ -292,7 +294,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListBackups(fx.Context(), &ListBackupsRequest{ + response, err := fx.Service().ListBackups(fx.Context(), &ListBackupsRequest{ Parent: parent, PageSize: 999, }) @@ -311,7 +313,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) 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.ListBackups(fx.Context(), &ListBackupsRequest{ + response, err := fx.Service().ListBackups(fx.Context(), &ListBackupsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -322,7 +324,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) 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.ListBackups(fx.Context(), &ListBackupsRequest{ + response, err := fx.Service().ListBackups(fx.Context(), &ListBackupsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -336,7 +338,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Backup, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListBackups(fx.Context(), &ListBackupsRequest{ + response, err := fx.Service().ListBackups(fx.Context(), &ListBackupsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -365,12 +367,12 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteBackup(fx.Context(), &DeleteBackupRequest{ + _, err := fx.Service().DeleteBackup(fx.Context(), &DeleteBackupRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListBackups(fx.Context(), &ListBackupsRequest{ + response, err := fx.Service().ListBackups(fx.Context(), &ListBackupsRequest{ Parent: parent, PageSize: 9999, }) @@ -393,7 +395,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testDelete(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.DeleteBackup(fx.Context(), &DeleteBackupRequest{ + _, err := fx.Service().DeleteBackup(fx.Context(), &DeleteBackupRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -402,7 +404,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testDelete(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.DeleteBackup(fx.Context(), &DeleteBackupRequest{ + _, err := fx.Service().DeleteBackup(fx.Context(), &DeleteBackupRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -413,7 +415,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteBackup(fx.Context(), &DeleteBackupRequest{ + _, err := fx.Service().DeleteBackup(fx.Context(), &DeleteBackupRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -424,7 +426,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteBackup(fx.Context(), &DeleteBackupRequest{ + _, err := fx.Service().DeleteBackup(fx.Context(), &DeleteBackupRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -435,12 +437,12 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteBackup(fx.Context(), &DeleteBackupRequest{ + deleted, err := fx.Service().DeleteBackup(fx.Context(), &DeleteBackupRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteBackup(fx.Context(), &DeleteBackupRequest{ + _, err = fx.Service().DeleteBackup(fx.Context(), &DeleteBackupRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -449,7 +451,7 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) testDelete(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.DeleteBackup(fx.Context(), &DeleteBackupRequest{ + _, err := fx.Service().DeleteBackup(fx.Context(), &DeleteBackupRequest{ Name: "projects/-/instances/-/backups/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -490,9 +492,11 @@ func (fx *DatabaseAdminBackupTestSuiteConfig) create(t *testing.T, parent string } type DatabaseAdminDatabaseTestSuiteConfig struct { - service DatabaseAdminServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() DatabaseAdminServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -528,7 +532,7 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) 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.GetDatabase(fx.Context(), &GetDatabaseRequest{ + _, err := fx.Service().GetDatabase(fx.Context(), &GetDatabaseRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -537,7 +541,7 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) 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.GetDatabase(fx.Context(), &GetDatabaseRequest{ + _, err := fx.Service().GetDatabase(fx.Context(), &GetDatabaseRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -548,7 +552,7 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetDatabase(fx.Context(), &GetDatabaseRequest{ + msg, err := fx.Service().GetDatabase(fx.Context(), &GetDatabaseRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -560,7 +564,7 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetDatabase(fx.Context(), &GetDatabaseRequest{ + _, err := fx.Service().GetDatabase(fx.Context(), &GetDatabaseRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -569,7 +573,7 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) 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.GetDatabase(fx.Context(), &GetDatabaseRequest{ + _, err := fx.Service().GetDatabase(fx.Context(), &GetDatabaseRequest{ Name: "projects/-/instances/-/databases/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -585,7 +589,7 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateDatabase(fx.Context(), &UpdateDatabaseRequest{ + _, err := fx.Service().UpdateDatabase(fx.Context(), &UpdateDatabaseRequest{ Database: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -597,7 +601,7 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateDatabase(fx.Context(), &UpdateDatabaseRequest{ + _, err := fx.Service().UpdateDatabase(fx.Context(), &UpdateDatabaseRequest{ Database: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -610,7 +614,7 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateDatabase(fx.Context(), &UpdateDatabaseRequest{ + _, err := fx.Service().UpdateDatabase(fx.Context(), &UpdateDatabaseRequest{ Database: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -619,7 +623,7 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) 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.UpdateDatabase(fx.Context(), &UpdateDatabaseRequest{ + _, err := fx.Service().UpdateDatabase(fx.Context(), &UpdateDatabaseRequest{ Database: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -643,7 +647,7 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateDatabase(fx.Context(), &UpdateDatabaseRequest{ + _, err := fx.Service().UpdateDatabase(fx.Context(), &UpdateDatabaseRequest{ Database: msg, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -662,7 +666,7 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) 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.ListDatabases(fx.Context(), &ListDatabasesRequest{ + _, err := fx.Service().ListDatabases(fx.Context(), &ListDatabasesRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -672,7 +676,7 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListDatabases(fx.Context(), &ListDatabasesRequest{ + _, err := fx.Service().ListDatabases(fx.Context(), &ListDatabasesRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -683,7 +687,7 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListDatabases(fx.Context(), &ListDatabasesRequest{ + _, err := fx.Service().ListDatabases(fx.Context(), &ListDatabasesRequest{ Parent: parent, PageSize: -10, }) @@ -701,7 +705,7 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListDatabases(fx.Context(), &ListDatabasesRequest{ + response, err := fx.Service().ListDatabases(fx.Context(), &ListDatabasesRequest{ Parent: parent, PageSize: 999, }) @@ -720,7 +724,7 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) 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.ListDatabases(fx.Context(), &ListDatabasesRequest{ + response, err := fx.Service().ListDatabases(fx.Context(), &ListDatabasesRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -731,7 +735,7 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) 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.ListDatabases(fx.Context(), &ListDatabasesRequest{ + response, err := fx.Service().ListDatabases(fx.Context(), &ListDatabasesRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -745,7 +749,7 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Database, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListDatabases(fx.Context(), &ListDatabasesRequest{ + response, err := fx.Service().ListDatabases(fx.Context(), &ListDatabasesRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -808,9 +812,11 @@ func (fx *DatabaseAdminDatabaseTestSuiteConfig) create(t *testing.T, parent stri } type DatabaseAdminDatabaseRoleTestSuiteConfig struct { - service DatabaseAdminServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() DatabaseAdminServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -841,7 +847,7 @@ func (fx *DatabaseAdminDatabaseRoleTestSuiteConfig) 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.ListDatabaseRoles(fx.Context(), &ListDatabaseRolesRequest{ + _, err := fx.Service().ListDatabaseRoles(fx.Context(), &ListDatabaseRolesRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -851,7 +857,7 @@ func (fx *DatabaseAdminDatabaseRoleTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListDatabaseRoles(fx.Context(), &ListDatabaseRolesRequest{ + _, err := fx.Service().ListDatabaseRoles(fx.Context(), &ListDatabaseRolesRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -862,7 +868,7 @@ func (fx *DatabaseAdminDatabaseRoleTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListDatabaseRoles(fx.Context(), &ListDatabaseRolesRequest{ + _, err := fx.Service().ListDatabaseRoles(fx.Context(), &ListDatabaseRolesRequest{ Parent: parent, PageSize: -10, }) @@ -880,7 +886,7 @@ func (fx *DatabaseAdminDatabaseRoleTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListDatabaseRoles(fx.Context(), &ListDatabaseRolesRequest{ + response, err := fx.Service().ListDatabaseRoles(fx.Context(), &ListDatabaseRolesRequest{ Parent: parent, PageSize: 999, }) @@ -899,7 +905,7 @@ func (fx *DatabaseAdminDatabaseRoleTestSuiteConfig) 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.ListDatabaseRoles(fx.Context(), &ListDatabaseRolesRequest{ + response, err := fx.Service().ListDatabaseRoles(fx.Context(), &ListDatabaseRolesRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -910,7 +916,7 @@ func (fx *DatabaseAdminDatabaseRoleTestSuiteConfig) 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.ListDatabaseRoles(fx.Context(), &ListDatabaseRolesRequest{ + response, err := fx.Service().ListDatabaseRoles(fx.Context(), &ListDatabaseRolesRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -924,7 +930,7 @@ func (fx *DatabaseAdminDatabaseRoleTestSuiteConfig) testList(t *testing.T) { msgs := make([]*DatabaseRole, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListDatabaseRoles(fx.Context(), &ListDatabaseRolesRequest{ + response, err := fx.Service().ListDatabaseRoles(fx.Context(), &ListDatabaseRolesRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, diff --git a/proto/gen/googleapis/spanner/admin/instance/apiv1/instancepb/spanner_instance_admin_aiptest.pb.go b/proto/gen/googleapis/spanner/admin/instance/apiv1/instancepb/spanner_instance_admin_aiptest.pb.go index b26d053..bb2926c 100644 --- a/proto/gen/googleapis/spanner/admin/instance/apiv1/instancepb/spanner_instance_admin_aiptest.pb.go +++ b/proto/gen/googleapis/spanner/admin/instance/apiv1/instancepb/spanner_instance_admin_aiptest.pb.go @@ -24,7 +24,7 @@ type InstanceAdminTestSuite struct { func (fx InstanceAdminTestSuite) TestInstance(ctx context.Context, options InstanceAdminInstanceTestSuiteConfig) { fx.T.Run("Instance", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() InstanceAdminServer { return fx.Server } options.test(t) }) } @@ -32,7 +32,7 @@ func (fx InstanceAdminTestSuite) TestInstance(ctx context.Context, options Insta func (fx InstanceAdminTestSuite) TestInstanceConfig(ctx context.Context, options InstanceAdminInstanceConfigTestSuiteConfig) { fx.T.Run("InstanceConfig", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() InstanceAdminServer { return fx.Server } options.test(t) }) } @@ -40,15 +40,17 @@ func (fx InstanceAdminTestSuite) TestInstanceConfig(ctx context.Context, options func (fx InstanceAdminTestSuite) TestInstancePartition(ctx context.Context, options InstanceAdminInstancePartitionTestSuiteConfig) { fx.T.Run("InstancePartition", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() InstanceAdminServer { return fx.Server } options.test(t) }) } type InstanceAdminInstanceTestSuiteConfig struct { - service InstanceAdminServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() InstanceAdminServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -83,7 +85,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) 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.CreateInstance(fx.Context(), &CreateInstanceRequest{ + _, err := fx.Service().CreateInstance(fx.Context(), &CreateInstanceRequest{ Parent: "", Instance: fx.Create(fx.nextParent(t, false)), }) @@ -93,7 +95,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) 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.CreateInstance(fx.Context(), &CreateInstanceRequest{ + _, err := fx.Service().CreateInstance(fx.Context(), &CreateInstanceRequest{ Parent: "invalid resource name", Instance: fx.Create(fx.nextParent(t, false)), }) @@ -114,7 +116,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateInstance(fx.Context(), &CreateInstanceRequest{ + _, err := fx.Service().CreateInstance(fx.Context(), &CreateInstanceRequest{ Parent: parent, Instance: msg, }) @@ -130,7 +132,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("config") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateInstance(fx.Context(), &CreateInstanceRequest{ + _, err := fx.Service().CreateInstance(fx.Context(), &CreateInstanceRequest{ Parent: parent, Instance: msg, }) @@ -146,7 +148,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateInstance(fx.Context(), &CreateInstanceRequest{ + _, err := fx.Service().CreateInstance(fx.Context(), &CreateInstanceRequest{ Parent: parent, Instance: msg, }) @@ -162,7 +164,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("autoscaling_limits") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateInstance(fx.Context(), &CreateInstanceRequest{ + _, err := fx.Service().CreateInstance(fx.Context(), &CreateInstanceRequest{ Parent: parent, Instance: msg, }) @@ -178,7 +180,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("autoscaling_targets") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateInstance(fx.Context(), &CreateInstanceRequest{ + _, err := fx.Service().CreateInstance(fx.Context(), &CreateInstanceRequest{ Parent: parent, Instance: msg, }) @@ -194,7 +196,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("high_priority_cpu_utilization_percent") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateInstance(fx.Context(), &CreateInstanceRequest{ + _, err := fx.Service().CreateInstance(fx.Context(), &CreateInstanceRequest{ Parent: parent, Instance: msg, }) @@ -210,7 +212,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testCreate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("storage_utilization_percent") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateInstance(fx.Context(), &CreateInstanceRequest{ + _, err := fx.Service().CreateInstance(fx.Context(), &CreateInstanceRequest{ Parent: parent, Instance: msg, }) @@ -231,7 +233,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.Config = "invalid resource name" - _, err := fx.service.CreateInstance(fx.Context(), &CreateInstanceRequest{ + _, err := fx.Service().CreateInstance(fx.Context(), &CreateInstanceRequest{ Parent: parent, Instance: msg, }) @@ -246,7 +248,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) 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.GetInstance(fx.Context(), &GetInstanceRequest{ + _, err := fx.Service().GetInstance(fx.Context(), &GetInstanceRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -255,7 +257,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) 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.GetInstance(fx.Context(), &GetInstanceRequest{ + _, err := fx.Service().GetInstance(fx.Context(), &GetInstanceRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -266,7 +268,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetInstance(fx.Context(), &GetInstanceRequest{ + msg, err := fx.Service().GetInstance(fx.Context(), &GetInstanceRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -278,7 +280,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetInstance(fx.Context(), &GetInstanceRequest{ + _, err := fx.Service().GetInstance(fx.Context(), &GetInstanceRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -287,7 +289,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) 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.GetInstance(fx.Context(), &GetInstanceRequest{ + _, err := fx.Service().GetInstance(fx.Context(), &GetInstanceRequest{ Name: "projects/-/instances/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -303,7 +305,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateInstance(fx.Context(), &UpdateInstanceRequest{ + _, err := fx.Service().UpdateInstance(fx.Context(), &UpdateInstanceRequest{ Instance: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -315,7 +317,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateInstance(fx.Context(), &UpdateInstanceRequest{ + _, err := fx.Service().UpdateInstance(fx.Context(), &UpdateInstanceRequest{ Instance: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -328,7 +330,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateInstance(fx.Context(), &UpdateInstanceRequest{ + _, err := fx.Service().UpdateInstance(fx.Context(), &UpdateInstanceRequest{ Instance: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -347,7 +349,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateInstance(fx.Context(), &UpdateInstanceRequest{ + _, err := fx.Service().UpdateInstance(fx.Context(), &UpdateInstanceRequest{ Instance: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -361,7 +363,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("config") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateInstance(fx.Context(), &UpdateInstanceRequest{ + _, err := fx.Service().UpdateInstance(fx.Context(), &UpdateInstanceRequest{ Instance: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -375,7 +377,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateInstance(fx.Context(), &UpdateInstanceRequest{ + _, err := fx.Service().UpdateInstance(fx.Context(), &UpdateInstanceRequest{ Instance: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -389,7 +391,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("autoscaling_limits") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateInstance(fx.Context(), &UpdateInstanceRequest{ + _, err := fx.Service().UpdateInstance(fx.Context(), &UpdateInstanceRequest{ Instance: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -403,7 +405,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("autoscaling_targets") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateInstance(fx.Context(), &UpdateInstanceRequest{ + _, err := fx.Service().UpdateInstance(fx.Context(), &UpdateInstanceRequest{ Instance: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -417,7 +419,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("high_priority_cpu_utilization_percent") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateInstance(fx.Context(), &UpdateInstanceRequest{ + _, err := fx.Service().UpdateInstance(fx.Context(), &UpdateInstanceRequest{ Instance: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -431,7 +433,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testUpdate(t *testing.T) { } fd := container.ProtoReflect().Descriptor().Fields().ByName("storage_utilization_percent") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateInstance(fx.Context(), &UpdateInstanceRequest{ + _, err := fx.Service().UpdateInstance(fx.Context(), &UpdateInstanceRequest{ Instance: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -445,7 +447,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) 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.ListInstances(fx.Context(), &ListInstancesRequest{ + _, err := fx.Service().ListInstances(fx.Context(), &ListInstancesRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -455,7 +457,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListInstances(fx.Context(), &ListInstancesRequest{ + _, err := fx.Service().ListInstances(fx.Context(), &ListInstancesRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -466,7 +468,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListInstances(fx.Context(), &ListInstancesRequest{ + _, err := fx.Service().ListInstances(fx.Context(), &ListInstancesRequest{ Parent: parent, PageSize: -10, }) @@ -484,7 +486,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListInstances(fx.Context(), &ListInstancesRequest{ + response, err := fx.Service().ListInstances(fx.Context(), &ListInstancesRequest{ Parent: parent, PageSize: 999, }) @@ -503,7 +505,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) 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.ListInstances(fx.Context(), &ListInstancesRequest{ + response, err := fx.Service().ListInstances(fx.Context(), &ListInstancesRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -514,7 +516,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) 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.ListInstances(fx.Context(), &ListInstancesRequest{ + response, err := fx.Service().ListInstances(fx.Context(), &ListInstancesRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -528,7 +530,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testList(t *testing.T) { msgs := make([]*Instance, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListInstances(fx.Context(), &ListInstancesRequest{ + response, err := fx.Service().ListInstances(fx.Context(), &ListInstancesRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -557,12 +559,12 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteInstance(fx.Context(), &DeleteInstanceRequest{ + _, err := fx.Service().DeleteInstance(fx.Context(), &DeleteInstanceRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListInstances(fx.Context(), &ListInstancesRequest{ + response, err := fx.Service().ListInstances(fx.Context(), &ListInstancesRequest{ Parent: parent, PageSize: 9999, }) @@ -585,7 +587,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testDelete(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.DeleteInstance(fx.Context(), &DeleteInstanceRequest{ + _, err := fx.Service().DeleteInstance(fx.Context(), &DeleteInstanceRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -594,7 +596,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testDelete(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.DeleteInstance(fx.Context(), &DeleteInstanceRequest{ + _, err := fx.Service().DeleteInstance(fx.Context(), &DeleteInstanceRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -605,7 +607,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteInstance(fx.Context(), &DeleteInstanceRequest{ + _, err := fx.Service().DeleteInstance(fx.Context(), &DeleteInstanceRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -616,7 +618,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteInstance(fx.Context(), &DeleteInstanceRequest{ + _, err := fx.Service().DeleteInstance(fx.Context(), &DeleteInstanceRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -627,12 +629,12 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteInstance(fx.Context(), &DeleteInstanceRequest{ + deleted, err := fx.Service().DeleteInstance(fx.Context(), &DeleteInstanceRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteInstance(fx.Context(), &DeleteInstanceRequest{ + _, err = fx.Service().DeleteInstance(fx.Context(), &DeleteInstanceRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -641,7 +643,7 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) testDelete(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.DeleteInstance(fx.Context(), &DeleteInstanceRequest{ + _, err := fx.Service().DeleteInstance(fx.Context(), &DeleteInstanceRequest{ Name: "projects/-/instances/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -682,9 +684,11 @@ func (fx *InstanceAdminInstanceTestSuiteConfig) create(t *testing.T, parent stri } type InstanceAdminInstanceConfigTestSuiteConfig struct { - service InstanceAdminServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() InstanceAdminServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -719,7 +723,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) 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.CreateInstanceConfig(fx.Context(), &CreateInstanceConfigRequest{ + _, err := fx.Service().CreateInstanceConfig(fx.Context(), &CreateInstanceConfigRequest{ Parent: "", InstanceConfig: fx.Create(fx.nextParent(t, false)), }) @@ -729,7 +733,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) 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.CreateInstanceConfig(fx.Context(), &CreateInstanceConfigRequest{ + _, err := fx.Service().CreateInstanceConfig(fx.Context(), &CreateInstanceConfigRequest{ Parent: "invalid resource name", InstanceConfig: fx.Create(fx.nextParent(t, false)), }) @@ -749,7 +753,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testCreate(t *testing.T) { t.Skip("not reachable") } container.BaseConfig = "invalid resource name" - _, err := fx.service.CreateInstanceConfig(fx.Context(), &CreateInstanceConfigRequest{ + _, err := fx.Service().CreateInstanceConfig(fx.Context(), &CreateInstanceConfigRequest{ Parent: parent, InstanceConfig: msg, }) @@ -764,7 +768,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) 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.GetInstanceConfig(fx.Context(), &GetInstanceConfigRequest{ + _, err := fx.Service().GetInstanceConfig(fx.Context(), &GetInstanceConfigRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -773,7 +777,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) 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.GetInstanceConfig(fx.Context(), &GetInstanceConfigRequest{ + _, err := fx.Service().GetInstanceConfig(fx.Context(), &GetInstanceConfigRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -784,7 +788,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetInstanceConfig(fx.Context(), &GetInstanceConfigRequest{ + msg, err := fx.Service().GetInstanceConfig(fx.Context(), &GetInstanceConfigRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -796,7 +800,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetInstanceConfig(fx.Context(), &GetInstanceConfigRequest{ + _, err := fx.Service().GetInstanceConfig(fx.Context(), &GetInstanceConfigRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -805,7 +809,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) 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.GetInstanceConfig(fx.Context(), &GetInstanceConfigRequest{ + _, err := fx.Service().GetInstanceConfig(fx.Context(), &GetInstanceConfigRequest{ Name: "projects/-/instanceConfigs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -821,7 +825,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateInstanceConfig(fx.Context(), &UpdateInstanceConfigRequest{ + _, err := fx.Service().UpdateInstanceConfig(fx.Context(), &UpdateInstanceConfigRequest{ InstanceConfig: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -833,7 +837,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testUpdate(t *testing.T) { parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateInstanceConfig(fx.Context(), &UpdateInstanceConfigRequest{ + _, err := fx.Service().UpdateInstanceConfig(fx.Context(), &UpdateInstanceConfigRequest{ InstanceConfig: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -846,7 +850,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testUpdate(t *testing.T) { fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateInstanceConfig(fx.Context(), &UpdateInstanceConfigRequest{ + _, err := fx.Service().UpdateInstanceConfig(fx.Context(), &UpdateInstanceConfigRequest{ InstanceConfig: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -855,7 +859,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) 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.UpdateInstanceConfig(fx.Context(), &UpdateInstanceConfigRequest{ + _, err := fx.Service().UpdateInstanceConfig(fx.Context(), &UpdateInstanceConfigRequest{ InstanceConfig: created, UpdateMask: &fieldmaskpb.FieldMask{ Paths: []string{ @@ -873,7 +877,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) 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.ListInstanceConfigs(fx.Context(), &ListInstanceConfigsRequest{ + _, err := fx.Service().ListInstanceConfigs(fx.Context(), &ListInstanceConfigsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -883,7 +887,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testList(t *testing.T) { t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListInstanceConfigs(fx.Context(), &ListInstanceConfigsRequest{ + _, err := fx.Service().ListInstanceConfigs(fx.Context(), &ListInstanceConfigsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -894,7 +898,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testList(t *testing.T) { t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListInstanceConfigs(fx.Context(), &ListInstanceConfigsRequest{ + _, err := fx.Service().ListInstanceConfigs(fx.Context(), &ListInstanceConfigsRequest{ Parent: parent, PageSize: -10, }) @@ -912,7 +916,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testList(t *testing.T) { // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListInstanceConfigs(fx.Context(), &ListInstanceConfigsRequest{ + response, err := fx.Service().ListInstanceConfigs(fx.Context(), &ListInstanceConfigsRequest{ Parent: parent, PageSize: 999, }) @@ -931,7 +935,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) 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.ListInstanceConfigs(fx.Context(), &ListInstanceConfigsRequest{ + response, err := fx.Service().ListInstanceConfigs(fx.Context(), &ListInstanceConfigsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -942,7 +946,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) 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.ListInstanceConfigs(fx.Context(), &ListInstanceConfigsRequest{ + response, err := fx.Service().ListInstanceConfigs(fx.Context(), &ListInstanceConfigsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -956,7 +960,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testList(t *testing.T) { msgs := make([]*InstanceConfig, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListInstanceConfigs(fx.Context(), &ListInstanceConfigsRequest{ + response, err := fx.Service().ListInstanceConfigs(fx.Context(), &ListInstanceConfigsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -985,12 +989,12 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testList(t *testing.T) { fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ + _, err := fx.Service().DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListInstanceConfigs(fx.Context(), &ListInstanceConfigsRequest{ + response, err := fx.Service().ListInstanceConfigs(fx.Context(), &ListInstanceConfigsRequest{ Parent: parent, PageSize: 9999, }) @@ -1013,7 +1017,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testDelete(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.DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ + _, err := fx.Service().DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1022,7 +1026,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testDelete(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.DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ + _, err := fx.Service().DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1033,7 +1037,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ + _, err := fx.Service().DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1044,7 +1048,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ + _, err := fx.Service().DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1055,12 +1059,12 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ + deleted, err := fx.Service().DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ + _, err = fx.Service().DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1069,7 +1073,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testDelete(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.DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ + _, err := fx.Service().DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ Name: "projects/-/instanceConfigs/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1080,7 +1084,7 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ + _, err := fx.Service().DeleteInstanceConfig(fx.Context(), &DeleteInstanceConfigRequest{ Name: created.Name, Etag: `"99999"`, }) @@ -1122,9 +1126,11 @@ func (fx *InstanceAdminInstanceConfigTestSuiteConfig) create(t *testing.T, paren } type InstanceAdminInstancePartitionTestSuiteConfig struct { - service InstanceAdminServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() InstanceAdminServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -1159,7 +1165,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) 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.CreateInstancePartition(fx.Context(), &CreateInstancePartitionRequest{ + _, err := fx.Service().CreateInstancePartition(fx.Context(), &CreateInstancePartitionRequest{ Parent: "", InstancePartition: fx.Create(fx.nextParent(t, false)), }) @@ -1169,7 +1175,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) 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.CreateInstancePartition(fx.Context(), &CreateInstancePartitionRequest{ + _, err := fx.Service().CreateInstancePartition(fx.Context(), &CreateInstancePartitionRequest{ Parent: "invalid resource name", InstancePartition: fx.Create(fx.nextParent(t, false)), }) @@ -1190,7 +1196,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testCreate(t *testing.T } fd := container.ProtoReflect().Descriptor().Fields().ByName("name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateInstancePartition(fx.Context(), &CreateInstancePartitionRequest{ + _, err := fx.Service().CreateInstancePartition(fx.Context(), &CreateInstancePartitionRequest{ Parent: parent, InstancePartition: msg, }) @@ -1206,7 +1212,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testCreate(t *testing.T } fd := container.ProtoReflect().Descriptor().Fields().ByName("config") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateInstancePartition(fx.Context(), &CreateInstancePartitionRequest{ + _, err := fx.Service().CreateInstancePartition(fx.Context(), &CreateInstancePartitionRequest{ Parent: parent, InstancePartition: msg, }) @@ -1222,7 +1228,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testCreate(t *testing.T } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.CreateInstancePartition(fx.Context(), &CreateInstancePartitionRequest{ + _, err := fx.Service().CreateInstancePartition(fx.Context(), &CreateInstancePartitionRequest{ Parent: parent, InstancePartition: msg, }) @@ -1243,7 +1249,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testCreate(t *testing.T t.Skip("not reachable") } container.Config = "invalid resource name" - _, err := fx.service.CreateInstancePartition(fx.Context(), &CreateInstancePartitionRequest{ + _, err := fx.Service().CreateInstancePartition(fx.Context(), &CreateInstancePartitionRequest{ Parent: parent, InstancePartition: msg, }) @@ -1258,7 +1264,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) 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.GetInstancePartition(fx.Context(), &GetInstancePartitionRequest{ + _, err := fx.Service().GetInstancePartition(fx.Context(), &GetInstancePartitionRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1267,7 +1273,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) 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.GetInstancePartition(fx.Context(), &GetInstancePartitionRequest{ + _, err := fx.Service().GetInstancePartition(fx.Context(), &GetInstancePartitionRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1278,7 +1284,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetInstancePartition(fx.Context(), &GetInstancePartitionRequest{ + msg, err := fx.Service().GetInstancePartition(fx.Context(), &GetInstancePartitionRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1290,7 +1296,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetInstancePartition(fx.Context(), &GetInstancePartitionRequest{ + _, err := fx.Service().GetInstancePartition(fx.Context(), &GetInstancePartitionRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1299,7 +1305,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) 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.GetInstancePartition(fx.Context(), &GetInstancePartitionRequest{ + _, err := fx.Service().GetInstancePartition(fx.Context(), &GetInstancePartitionRequest{ Name: "projects/-/instances/-/instancePartitions/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1315,7 +1321,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testUpdate(t *testing.T parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "" - _, err := fx.service.UpdateInstancePartition(fx.Context(), &UpdateInstancePartitionRequest{ + _, err := fx.Service().UpdateInstancePartition(fx.Context(), &UpdateInstancePartitionRequest{ InstancePartition: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1327,7 +1333,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testUpdate(t *testing.T parent := fx.nextParent(t, false) msg := fx.Update(parent) msg.Name = "invalid resource name" - _, err := fx.service.UpdateInstancePartition(fx.Context(), &UpdateInstancePartitionRequest{ + _, err := fx.Service().UpdateInstancePartition(fx.Context(), &UpdateInstancePartitionRequest{ InstancePartition: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1340,7 +1346,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testUpdate(t *testing.T fx.maybeSkip(t) msg := fx.Update(parent) msg.Name = created.Name + "notfound" - _, err := fx.service.UpdateInstancePartition(fx.Context(), &UpdateInstancePartitionRequest{ + _, err := fx.Service().UpdateInstancePartition(fx.Context(), &UpdateInstancePartitionRequest{ InstancePartition: msg, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1359,7 +1365,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testUpdate(t *testing.T } fd := container.ProtoReflect().Descriptor().Fields().ByName("name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateInstancePartition(fx.Context(), &UpdateInstancePartitionRequest{ + _, err := fx.Service().UpdateInstancePartition(fx.Context(), &UpdateInstancePartitionRequest{ InstancePartition: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1373,7 +1379,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testUpdate(t *testing.T } fd := container.ProtoReflect().Descriptor().Fields().ByName("config") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateInstancePartition(fx.Context(), &UpdateInstancePartitionRequest{ + _, err := fx.Service().UpdateInstancePartition(fx.Context(), &UpdateInstancePartitionRequest{ InstancePartition: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1387,7 +1393,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testUpdate(t *testing.T } fd := container.ProtoReflect().Descriptor().Fields().ByName("display_name") container.ProtoReflect().Clear(fd) - _, err := fx.service.UpdateInstancePartition(fx.Context(), &UpdateInstancePartitionRequest{ + _, err := fx.Service().UpdateInstancePartition(fx.Context(), &UpdateInstancePartitionRequest{ InstancePartition: msg, }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1401,7 +1407,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) 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.ListInstancePartitions(fx.Context(), &ListInstancePartitionsRequest{ + _, err := fx.Service().ListInstancePartitions(fx.Context(), &ListInstancePartitionsRequest{ Parent: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1411,7 +1417,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testList(t *testing.T) t.Run("invalid page token", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListInstancePartitions(fx.Context(), &ListInstancePartitionsRequest{ + _, err := fx.Service().ListInstancePartitions(fx.Context(), &ListInstancePartitionsRequest{ Parent: parent, PageToken: "invalid page token", }) @@ -1422,7 +1428,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testList(t *testing.T) t.Run("negative page size", func(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) - _, err := fx.service.ListInstancePartitions(fx.Context(), &ListInstancePartitionsRequest{ + _, err := fx.Service().ListInstancePartitions(fx.Context(), &ListInstancePartitionsRequest{ Parent: parent, PageSize: -10, }) @@ -1440,7 +1446,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testList(t *testing.T) // under that parent. t.Run("isolation", func(t *testing.T) { fx.maybeSkip(t) - response, err := fx.service.ListInstancePartitions(fx.Context(), &ListInstancePartitionsRequest{ + response, err := fx.Service().ListInstancePartitions(fx.Context(), &ListInstancePartitionsRequest{ Parent: parent, PageSize: 999, }) @@ -1459,7 +1465,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) 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.ListInstancePartitions(fx.Context(), &ListInstancePartitionsRequest{ + response, err := fx.Service().ListInstancePartitions(fx.Context(), &ListInstancePartitionsRequest{ Parent: parent, PageSize: resourcesCount, }) @@ -1470,7 +1476,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) 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.ListInstancePartitions(fx.Context(), &ListInstancePartitionsRequest{ + response, err := fx.Service().ListInstancePartitions(fx.Context(), &ListInstancePartitionsRequest{ Parent: parent, PageSize: resourcesCount - 1, }) @@ -1484,7 +1490,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testList(t *testing.T) msgs := make([]*InstancePartition, 0, resourcesCount) var nextPageToken string for { - response, err := fx.service.ListInstancePartitions(fx.Context(), &ListInstancePartitionsRequest{ + response, err := fx.Service().ListInstancePartitions(fx.Context(), &ListInstancePartitionsRequest{ Parent: parent, PageSize: 1, PageToken: nextPageToken, @@ -1513,12 +1519,12 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testList(t *testing.T) fx.maybeSkip(t) const deleteCount = 5 for i := 0; i < deleteCount; i++ { - _, err := fx.service.DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ + _, err := fx.Service().DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ Name: parentMsgs[i].Name, }) assert.NilError(t, err) } - response, err := fx.service.ListInstancePartitions(fx.Context(), &ListInstancePartitionsRequest{ + response, err := fx.Service().ListInstancePartitions(fx.Context(), &ListInstancePartitionsRequest{ Parent: parent, PageSize: 9999, }) @@ -1541,7 +1547,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testDelete(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.DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ + _, err := fx.Service().DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1550,7 +1556,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testDelete(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.DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ + _, err := fx.Service().DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1561,7 +1567,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testDelete(t *testing.T fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ + _, err := fx.Service().DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -1572,7 +1578,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testDelete(t *testing.T fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ + _, err := fx.Service().DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1583,12 +1589,12 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testDelete(t *testing.T fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ + deleted, err := fx.Service().DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ + _, err = fx.Service().DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -1597,7 +1603,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testDelete(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.DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ + _, err := fx.Service().DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ Name: "projects/-/instances/-/instancePartitions/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -1608,7 +1614,7 @@ func (fx *InstanceAdminInstancePartitionTestSuiteConfig) testDelete(t *testing.T fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ + _, err := fx.Service().DeleteInstancePartition(fx.Context(), &DeleteInstancePartitionRequest{ Name: created.Name, Etag: `"99999"`, }) diff --git a/proto/gen/googleapis/spanner/apiv1/spannerpb/spanner_aiptest.pb.go b/proto/gen/googleapis/spanner/apiv1/spannerpb/spanner_aiptest.pb.go index 78faee9..d7629ff 100644 --- a/proto/gen/googleapis/spanner/apiv1/spannerpb/spanner_aiptest.pb.go +++ b/proto/gen/googleapis/spanner/apiv1/spannerpb/spanner_aiptest.pb.go @@ -21,15 +21,17 @@ type SpannerTestSuite struct { func (fx SpannerTestSuite) TestSession(ctx context.Context, options SpannerSessionTestSuiteConfig) { fx.T.Run("Session", func(t *testing.T) { options.Context = func() context.Context { return ctx } - options.service = fx.Server + options.Service = func() SpannerServer { return fx.Server } options.test(t) }) } type SpannerSessionTestSuiteConfig struct { - service SpannerServer currParent int + // Service should return the service that should be tested. + // The service will be used for several tests. + Service func() SpannerServer // Context should return a new context. // The context will be used for several tests. Context func() context.Context @@ -61,7 +63,7 @@ func (fx *SpannerSessionTestSuiteConfig) 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.GetSession(fx.Context(), &GetSessionRequest{ + _, err := fx.Service().GetSession(fx.Context(), &GetSessionRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -70,7 +72,7 @@ func (fx *SpannerSessionTestSuiteConfig) 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.GetSession(fx.Context(), &GetSessionRequest{ + _, err := fx.Service().GetSession(fx.Context(), &GetSessionRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -81,7 +83,7 @@ func (fx *SpannerSessionTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - msg, err := fx.service.GetSession(fx.Context(), &GetSessionRequest{ + msg, err := fx.Service().GetSession(fx.Context(), &GetSessionRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -93,7 +95,7 @@ func (fx *SpannerSessionTestSuiteConfig) testGet(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.GetSession(fx.Context(), &GetSessionRequest{ + _, err := fx.Service().GetSession(fx.Context(), &GetSessionRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -102,7 +104,7 @@ func (fx *SpannerSessionTestSuiteConfig) 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.GetSession(fx.Context(), &GetSessionRequest{ + _, err := fx.Service().GetSession(fx.Context(), &GetSessionRequest{ Name: "projects/-/instances/-/databases/-/sessions/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -115,7 +117,7 @@ func (fx *SpannerSessionTestSuiteConfig) testDelete(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.DeleteSession(fx.Context(), &DeleteSessionRequest{ + _, err := fx.Service().DeleteSession(fx.Context(), &DeleteSessionRequest{ Name: "", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -124,7 +126,7 @@ func (fx *SpannerSessionTestSuiteConfig) testDelete(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.DeleteSession(fx.Context(), &DeleteSessionRequest{ + _, err := fx.Service().DeleteSession(fx.Context(), &DeleteSessionRequest{ Name: "invalid resource name", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err) @@ -135,7 +137,7 @@ func (fx *SpannerSessionTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteSession(fx.Context(), &DeleteSessionRequest{ + _, err := fx.Service().DeleteSession(fx.Context(), &DeleteSessionRequest{ Name: created.Name, }) assert.NilError(t, err) @@ -146,7 +148,7 @@ func (fx *SpannerSessionTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - _, err := fx.service.DeleteSession(fx.Context(), &DeleteSessionRequest{ + _, err := fx.Service().DeleteSession(fx.Context(), &DeleteSessionRequest{ Name: created.Name + "notfound", }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -157,12 +159,12 @@ func (fx *SpannerSessionTestSuiteConfig) testDelete(t *testing.T) { fx.maybeSkip(t) parent := fx.nextParent(t, false) created := fx.create(t, parent) - deleted, err := fx.service.DeleteSession(fx.Context(), &DeleteSessionRequest{ + deleted, err := fx.Service().DeleteSession(fx.Context(), &DeleteSessionRequest{ Name: created.Name, }) assert.NilError(t, err) _ = deleted - _, err = fx.service.DeleteSession(fx.Context(), &DeleteSessionRequest{ + _, err = fx.Service().DeleteSession(fx.Context(), &DeleteSessionRequest{ Name: created.Name, }) assert.Equal(t, codes.NotFound, status.Code(err), err) @@ -171,7 +173,7 @@ func (fx *SpannerSessionTestSuiteConfig) testDelete(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.DeleteSession(fx.Context(), &DeleteSessionRequest{ + _, err := fx.Service().DeleteSession(fx.Context(), &DeleteSessionRequest{ Name: "projects/-/instances/-/databases/-/sessions/-", }) assert.Equal(t, codes.InvalidArgument, status.Code(err), err)