From 779bf33fcc417ec4def8d0a600ba8bdb3f9a8b9c Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Wed, 24 Apr 2024 15:08:57 +0200 Subject: [PATCH] refactor: rename GetShares to GetSharesForResource Rename this method to make more clear what it is about. --- .../graph/mocks/drives_drive_item_provider.go | 22 ++++++++-------- .../pkg/service/v0/api_drives_drive_item.go | 16 ++++++------ .../service/v0/api_drives_drive_item_test.go | 26 +++++++++---------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/services/graph/mocks/drives_drive_item_provider.go b/services/graph/mocks/drives_drive_item_provider.go index a521268a2e..6e8d4c9d61 100644 --- a/services/graph/mocks/drives_drive_item_provider.go +++ b/services/graph/mocks/drives_drive_item_provider.go @@ -86,12 +86,12 @@ func (_c *DrivesDriveItemProvider_GetShare_Call) RunAndReturn(run func(context.C return _c } -// GetShares provides a mock function with given fields: ctx, resourceID, filters -func (_m *DrivesDriveItemProvider) GetShares(ctx context.Context, resourceID *providerv1beta1.ResourceId, filters []*collaborationv1beta1.Filter) ([]*collaborationv1beta1.ReceivedShare, error) { +// GetSharesForResource provides a mock function with given fields: ctx, resourceID, filters +func (_m *DrivesDriveItemProvider) GetSharesForResource(ctx context.Context, resourceID *providerv1beta1.ResourceId, filters []*collaborationv1beta1.Filter) ([]*collaborationv1beta1.ReceivedShare, error) { ret := _m.Called(ctx, resourceID, filters) if len(ret) == 0 { - panic("no return value specified for GetShares") + panic("no return value specified for GetSharesForResource") } var r0 []*collaborationv1beta1.ReceivedShare @@ -116,32 +116,32 @@ func (_m *DrivesDriveItemProvider) GetShares(ctx context.Context, resourceID *pr return r0, r1 } -// DrivesDriveItemProvider_GetShares_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetShares' -type DrivesDriveItemProvider_GetShares_Call struct { +// DrivesDriveItemProvider_GetSharesForResource_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetSharesForResource' +type DrivesDriveItemProvider_GetSharesForResource_Call struct { *mock.Call } -// GetShares is a helper method to define mock.On call +// GetSharesForResource is a helper method to define mock.On call // - ctx context.Context // - resourceID *providerv1beta1.ResourceId // - filters []*collaborationv1beta1.Filter -func (_e *DrivesDriveItemProvider_Expecter) GetShares(ctx interface{}, resourceID interface{}, filters interface{}) *DrivesDriveItemProvider_GetShares_Call { - return &DrivesDriveItemProvider_GetShares_Call{Call: _e.mock.On("GetShares", ctx, resourceID, filters)} +func (_e *DrivesDriveItemProvider_Expecter) GetSharesForResource(ctx interface{}, resourceID interface{}, filters interface{}) *DrivesDriveItemProvider_GetSharesForResource_Call { + return &DrivesDriveItemProvider_GetSharesForResource_Call{Call: _e.mock.On("GetSharesForResource", ctx, resourceID, filters)} } -func (_c *DrivesDriveItemProvider_GetShares_Call) Run(run func(ctx context.Context, resourceID *providerv1beta1.ResourceId, filters []*collaborationv1beta1.Filter)) *DrivesDriveItemProvider_GetShares_Call { +func (_c *DrivesDriveItemProvider_GetSharesForResource_Call) Run(run func(ctx context.Context, resourceID *providerv1beta1.ResourceId, filters []*collaborationv1beta1.Filter)) *DrivesDriveItemProvider_GetSharesForResource_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(context.Context), args[1].(*providerv1beta1.ResourceId), args[2].([]*collaborationv1beta1.Filter)) }) return _c } -func (_c *DrivesDriveItemProvider_GetShares_Call) Return(_a0 []*collaborationv1beta1.ReceivedShare, _a1 error) *DrivesDriveItemProvider_GetShares_Call { +func (_c *DrivesDriveItemProvider_GetSharesForResource_Call) Return(_a0 []*collaborationv1beta1.ReceivedShare, _a1 error) *DrivesDriveItemProvider_GetSharesForResource_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *DrivesDriveItemProvider_GetShares_Call) RunAndReturn(run func(context.Context, *providerv1beta1.ResourceId, []*collaborationv1beta1.Filter) ([]*collaborationv1beta1.ReceivedShare, error)) *DrivesDriveItemProvider_GetShares_Call { +func (_c *DrivesDriveItemProvider_GetSharesForResource_Call) RunAndReturn(run func(context.Context, *providerv1beta1.ResourceId, []*collaborationv1beta1.Filter) ([]*collaborationv1beta1.ReceivedShare, error)) *DrivesDriveItemProvider_GetSharesForResource_Call { _c.Call.Return(run) return _c } diff --git a/services/graph/pkg/service/v0/api_drives_drive_item.go b/services/graph/pkg/service/v0/api_drives_drive_item.go index 74de0c464b..04d0af046f 100644 --- a/services/graph/pkg/service/v0/api_drives_drive_item.go +++ b/services/graph/pkg/service/v0/api_drives_drive_item.go @@ -84,8 +84,8 @@ type ( // GetShare returns the share GetShare(ctx context.Context, shareID *collaboration.ShareId) (*collaboration.ReceivedShare, error) - // GetShares returns all shares for a given resourceID - GetShares(ctx context.Context, resourceID *storageprovider.ResourceId, filters []*collaboration.Filter) ([]*collaboration.ReceivedShare, error) + // GetSharesForResource returns all shares for a given resourceID + GetSharesForResource(ctx context.Context, resourceID *storageprovider.ResourceId, filters []*collaboration.Filter) ([]*collaboration.ReceivedShare, error) } ) @@ -123,8 +123,8 @@ func (s DrivesDriveItemService) GetShare(ctx context.Context, shareID *collabora return getReceivedShareResponse.GetShare(), errorcode.FromCS3Status(getReceivedShareResponse.GetStatus(), err) } -// GetShares returns all shares for a given resourceID -func (s DrivesDriveItemService) GetShares(ctx context.Context, resourceID *storageprovider.ResourceId, filters []*collaboration.Filter) ([]*collaboration.ReceivedShare, error) { +// GetSharesForResource returns all shares for a given resourceID +func (s DrivesDriveItemService) GetSharesForResource(ctx context.Context, resourceID *storageprovider.ResourceId, filters []*collaboration.Filter) ([]*collaboration.ReceivedShare, error) { // Find all accepted shares for this resource gatewayClient, err := s.gatewaySelector.Next() if err != nil { @@ -214,7 +214,7 @@ func (s DrivesDriveItemService) UnmountShare(ctx context.Context, shareID *colla return err } - availableShares, err := s.GetShares(ctx, share.GetShare().GetResourceId(), []*collaboration.Filter{ + availableShares, err := s.GetSharesForResource(ctx, share.GetShare().GetResourceId(), []*collaboration.Filter{ { Type: collaboration.Filter_TYPE_STATE, Term: &collaboration.Filter_State{ @@ -246,7 +246,7 @@ func (s DrivesDriveItemService) MountShare(ctx context.Context, resourceID *stor name = filepath.Clean(name) } - availableShares, err := s.GetShares(ctx, resourceID, []*collaboration.Filter{ + availableShares, err := s.GetSharesForResource(ctx, resourceID, []*collaboration.Filter{ { Type: collaboration.Filter_TYPE_STATE, Term: &collaboration.Filter_State{ @@ -360,7 +360,7 @@ func (api DrivesDriveItemApi) GetDriveItem(w http.ResponseWriter, r *http.Reques return } - availableShares, err := api.drivesDriveItemService.GetShares(r.Context(), share.GetShare().GetResourceId(), nil) + availableShares, err := api.drivesDriveItemService.GetSharesForResource(r.Context(), share.GetShare().GetResourceId(), nil) if err != nil { api.logger.Debug().Err(err).Msg(ErrNoShares.Error()) ErrNoShares.Render(w, r) @@ -414,7 +414,7 @@ func (api DrivesDriveItemApi) UpdateDriveItem(w http.ResponseWriter, r *http.Req return } - availableShares, err := api.drivesDriveItemService.GetShares(r.Context(), share.GetShare().GetResourceId(), nil) + availableShares, err := api.drivesDriveItemService.GetSharesForResource(r.Context(), share.GetShare().GetResourceId(), nil) if err != nil { api.logger.Debug().Err(err).Msg(ErrNoShares.Error()) ErrNoShares.Render(w, r) diff --git a/services/graph/pkg/service/v0/api_drives_drive_item_test.go b/services/graph/pkg/service/v0/api_drives_drive_item_test.go index d986655bfd..e0542a1985 100644 --- a/services/graph/pkg/service/v0/api_drives_drive_item_test.go +++ b/services/graph/pkg/service/v0/api_drives_drive_item_test.go @@ -58,9 +58,9 @@ var _ = Describe("DrivesDriveItemService", func() { }) } - var _ = Describe("GetShares", func() { + var _ = Describe("GetSharesForResource", func() { failOnFailingGatewayClientRotation(func() error { - _, err := drivesDriveItemService.GetShares(context.Background(), nil, nil) + _, err := drivesDriveItemService.GetSharesForResource(context.Background(), nil, nil) return err }) @@ -83,7 +83,7 @@ var _ = Describe("DrivesDriveItemService", func() { }). Once() - _, _ = drivesDriveItemService.GetShares(context.Background(), resourceID, []*collaborationv1beta1.Filter{ + _, _ = drivesDriveItemService.GetSharesForResource(context.Background(), resourceID, []*collaborationv1beta1.Filter{ { Type: collaborationv1beta1.Filter_TYPE_STATE, Term: &collaborationv1beta1.Filter_State{ @@ -101,7 +101,7 @@ var _ = Describe("DrivesDriveItemService", func() { Return(nil, someErr). Once() - _, err := drivesDriveItemService.GetShares(context.Background(), &storageprovider.ResourceId{}, []*collaborationv1beta1.Filter{}) + _, err := drivesDriveItemService.GetSharesForResource(context.Background(), &storageprovider.ResourceId{}, []*collaborationv1beta1.Filter{}) Expect(err).To(MatchError(someErr)) }) @@ -112,7 +112,7 @@ var _ = Describe("DrivesDriveItemService", func() { Return(nil, nil). Once() - _, err := drivesDriveItemService.GetShares(context.Background(), &storageprovider.ResourceId{}, []*collaborationv1beta1.Filter{}) + _, err := drivesDriveItemService.GetSharesForResource(context.Background(), &storageprovider.ResourceId{}, []*collaborationv1beta1.Filter{}) Expect(err).To(MatchError(svc.ErrNoShares)) }) @@ -131,7 +131,7 @@ var _ = Describe("DrivesDriveItemService", func() { }, nil). Once() - shares, err := drivesDriveItemService.GetShares(context.Background(), &storageprovider.ResourceId{}, []*collaborationv1beta1.Filter{}) + shares, err := drivesDriveItemService.GetSharesForResource(context.Background(), &storageprovider.ResourceId{}, []*collaborationv1beta1.Filter{}) Expect(err).To(BeNil()) Expect(shares).To(Equal(givenShares)) }) @@ -616,7 +616,7 @@ var _ = Describe("DrivesDriveItemApi", func() { drivesDriveItemProvider. EXPECT(). - GetShares(mock.Anything, mock.Anything, mock.Anything). + GetSharesForResource(mock.Anything, mock.Anything, mock.Anything). Return(nil, errors.New("some error")). Once() @@ -649,7 +649,7 @@ var _ = Describe("DrivesDriveItemApi", func() { drivesDriveItemProvider. EXPECT(). - GetShares(mock.Anything, mock.Anything, mock.Anything). + GetSharesForResource(mock.Anything, mock.Anything, mock.Anything). Return(nil, nil). Once() @@ -693,7 +693,7 @@ var _ = Describe("DrivesDriveItemApi", func() { drivesDriveItemProvider. EXPECT(). - GetShares(mock.Anything, mock.Anything, mock.Anything). + GetSharesForResource(mock.Anything, mock.Anything, mock.Anything). Return([]*collaborationv1beta1.ReceivedShare{}, nil). Once() @@ -772,7 +772,7 @@ var _ = Describe("DrivesDriveItemApi", func() { drivesDriveItemProvider. EXPECT(). - GetShares(mock.Anything, mock.Anything, mock.Anything). + GetSharesForResource(mock.Anything, mock.Anything, mock.Anything). Return([]*collaborationv1beta1.ReceivedShare{share}, nil). Once() @@ -864,7 +864,7 @@ var _ = Describe("DrivesDriveItemApi", func() { drivesDriveItemProvider. EXPECT(). - GetShares(mock.Anything, mock.Anything, mock.Anything). + GetSharesForResource(mock.Anything, mock.Anything, mock.Anything). Return(nil, errors.New("some error")). Once() @@ -907,7 +907,7 @@ var _ = Describe("DrivesDriveItemApi", func() { drivesDriveItemProvider. EXPECT(). - GetShares(mock.Anything, mock.Anything, mock.Anything). + GetSharesForResource(mock.Anything, mock.Anything, mock.Anything). Return([]*collaborationv1beta1.ReceivedShare{share}, nil). Once() }) @@ -967,7 +967,7 @@ var _ = Describe("DrivesDriveItemApi", func() { drivesDriveItemProvider. EXPECT(). - GetShares(mock.Anything, mock.Anything, mock.Anything). + GetSharesForResource(mock.Anything, mock.Anything, mock.Anything). Return([]*collaborationv1beta1.ReceivedShare{share}, nil). Once()