diff --git a/__debug_bin1379664372 b/__debug_bin1379664372 deleted file mode 100755 index b5f2e7489..000000000 Binary files a/__debug_bin1379664372 and /dev/null differ diff --git a/api/handler/v1beta1/appeal.go b/api/handler/v1beta1/appeal.go index 528ef0bb0..b96f5513f 100644 --- a/api/handler/v1beta1/appeal.go +++ b/api/handler/v1beta1/appeal.go @@ -184,13 +184,19 @@ func (s *GRPCServer) listAppeals(ctx context.Context, filters *domain.ListAppeal eg.Go(func() error { appealRecords, err := s.appealService.Find(ctx, filters) + if err != nil { + return status.Errorf(codes.Internal, "failed to get appeal list: %s", err) + } appeals = appealRecords - return err + return nil }) eg.Go(func() error { totalRecord, err := s.appealService.GetAppealsTotalCount(ctx, filters) + if err != nil { + return status.Errorf(codes.Internal, "failed to get appeal total count: %s", err) + } total = totalRecord - return err + return nil }) if err := eg.Wait(); err != nil { diff --git a/api/handler/v1beta1/appeal_test.go b/api/handler/v1beta1/appeal_test.go index 8054703ab..9c79b1e35 100644 --- a/api/handler/v1beta1/appeal_test.go +++ b/api/handler/v1beta1/appeal_test.go @@ -3,6 +3,7 @@ package v1beta1_test import ( "context" "errors" + "fmt" "time" "github.com/google/uuid" @@ -121,9 +122,9 @@ func (s *GrpcHandlersSuite) TestListUserAppeals() { }, Total: 1, } - s.appealService.EXPECT().Find(mock.AnythingOfType("*context.valueCtx"), expectedFilters). + s.appealService.EXPECT().Find(mock.AnythingOfType("*context.cancelCtx"), expectedFilters). Return(expectedAppeals, nil).Once() - s.appealService.EXPECT().GetAppealsTotalCount(mock.AnythingOfType("*context.valueCtx"), expectedFilters). + s.appealService.EXPECT().GetAppealsTotalCount(mock.AnythingOfType("*context.cancelCtx"), expectedFilters). Return(int64(1), nil).Once() req := &guardianv1beta1.ListUserAppealsRequest{ @@ -163,13 +164,16 @@ func (s *GrpcHandlersSuite) TestListUserAppeals() { s.setup() expectedError := errors.New("random error") - s.appealService.EXPECT().Find(mock.AnythingOfType("*context.valueCtx"), mock.Anything). + s.appealService.EXPECT().Find(mock.AnythingOfType("*context.cancelCtx"), mock.Anything). Return(nil, expectedError).Once() + s.appealService.EXPECT().GetAppealsTotalCount(mock.AnythingOfType("*context.cancelCtx"), mock.Anything). + Return(int64(0), nil).Once() req := &guardianv1beta1.ListUserAppealsRequest{} ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, "test-user") res, err := s.grpcServer.ListUserAppeals(ctx, req) + fmt.Println(status.Code(err)) s.Equal(codes.Internal, status.Code(err)) s.Nil(res) s.appealService.AssertExpectations(s.T()) @@ -185,9 +189,9 @@ func (s *GrpcHandlersSuite) TestListUserAppeals() { }, }, } - s.appealService.EXPECT().Find(mock.AnythingOfType("*context.valueCtx"), mock.Anything). + s.appealService.EXPECT().Find(mock.AnythingOfType("*context.cancelCtx"), mock.Anything). Return(invalidAppeals, nil).Once() - s.appealService.EXPECT().GetAppealsTotalCount(mock.AnythingOfType("*context.valueCtx"), mock.Anything). + s.appealService.EXPECT().GetAppealsTotalCount(mock.AnythingOfType("*context.cancelCtx"), mock.Anything). Return(int64(1), nil).Once() req := &guardianv1beta1.ListUserAppealsRequest{} @@ -325,8 +329,10 @@ func (s *GrpcHandlersSuite) TestListAppeals() { s.setup() expectedError := errors.New("random error") - s.appealService.EXPECT().Find(mock.AnythingOfType("*context.emptyCtx"), mock.Anything). + s.appealService.EXPECT().Find(mock.AnythingOfType("*context.cancelCtx"), mock.Anything). Return(nil, expectedError).Once() + s.appealService.EXPECT().GetAppealsTotalCount(mock.AnythingOfType("*context.cancelCtx"), mock.Anything). + Return(int64(0), nil).Once() req := &guardianv1beta1.ListAppealsRequest{} res, err := s.grpcServer.ListAppeals(context.Background(), req) @@ -346,9 +352,9 @@ func (s *GrpcHandlersSuite) TestListAppeals() { }, }, } - s.appealService.EXPECT().Find(mock.AnythingOfType("*context.emptyCtx"), mock.Anything). + s.appealService.EXPECT().Find(mock.AnythingOfType("*context.cancelCtx"), mock.Anything). Return(invalidAppeals, nil).Once() - s.appealService.EXPECT().GetAppealsTotalCount(mock.AnythingOfType("*context.emptyCtx"), mock.Anything). + s.appealService.EXPECT().GetAppealsTotalCount(mock.AnythingOfType("*context.cancelCtx"), mock.Anything). Return(int64(1), nil).Once() req := &guardianv1beta1.ListAppealsRequest{} diff --git a/api/handler/v1beta1/grant.go b/api/handler/v1beta1/grant.go index 915d75df9..b66471005 100644 --- a/api/handler/v1beta1/grant.go +++ b/api/handler/v1beta1/grant.go @@ -182,13 +182,19 @@ func (s *GRPCServer) listGrants(ctx context.Context, filter domain.ListGrantsFil eg.Go(func() error { grantRecords, err := s.grantService.List(ctx, filter) + if err != nil { + return status.Errorf(codes.Internal, "failed to get grant list: %s", err) + } grants = grantRecords - return err + return nil }) eg.Go(func() error { totalRecord, err := s.grantService.GetGrantsTotalCount(ctx, filter) + if err != nil { + return status.Errorf(codes.Internal, "failed to get grant total count: %s", err) + } total = totalRecord - return err + return nil }) if err := eg.Wait(); err != nil { diff --git a/api/handler/v1beta1/grant_test.go b/api/handler/v1beta1/grant_test.go index 47d2324d1..c99fed055 100644 --- a/api/handler/v1beta1/grant_test.go +++ b/api/handler/v1beta1/grant_test.go @@ -75,10 +75,10 @@ func (s *GrpcHandlersSuite) TestListGrants() { ResourceIDs: []string{"test-resource-id"}, } s.grantService.EXPECT(). - List(mock.AnythingOfType("*context.emptyCtx"), expectedFilter). + List(mock.AnythingOfType("*context.cancelCtx"), expectedFilter). Return(dummyGrants, nil).Once() s.grantService.EXPECT(). - GetGrantsTotalCount(mock.AnythingOfType("*context.emptyCtx"), expectedFilter). + GetGrantsTotalCount(mock.AnythingOfType("*context.cancelCtx"), expectedFilter). Return(int64(1), nil).Once() req := &guardianv1beta1.ListGrantsRequest{ @@ -99,8 +99,11 @@ func (s *GrpcHandlersSuite) TestListGrants() { expectedError := errors.New("unexpected error") s.grantService.EXPECT(). - List(mock.AnythingOfType("*context.emptyCtx"), mock.AnythingOfType("domain.ListGrantsFilter")). + List(mock.AnythingOfType("*context.cancelCtx"), mock.AnythingOfType("domain.ListGrantsFilter")). Return(nil, expectedError).Once() + s.grantService.EXPECT(). + GetGrantsTotalCount(mock.AnythingOfType("*context.cancelCtx"), mock.AnythingOfType("domain.ListGrantsFilter")). + Return(int64(0), nil).Once() req := &guardianv1beta1.ListGrantsRequest{} res, err := s.grpcServer.ListGrants(context.Background(), req) @@ -123,10 +126,10 @@ func (s *GrpcHandlersSuite) TestListGrants() { }, } s.grantService.EXPECT(). - List(mock.AnythingOfType("*context.emptyCtx"), mock.AnythingOfType("domain.ListGrantsFilter")). + List(mock.AnythingOfType("*context.cancelCtx"), mock.AnythingOfType("domain.ListGrantsFilter")). Return(expectedGrants, nil).Once() s.grantService.EXPECT(). - GetGrantsTotalCount(mock.AnythingOfType("*context.emptyCtx"), mock.AnythingOfType("domain.ListGrantsFilter")). + GetGrantsTotalCount(mock.AnythingOfType("*context.cancelCtx"), mock.AnythingOfType("domain.ListGrantsFilter")). Return(int64(1), nil).Once() req := &guardianv1beta1.ListGrantsRequest{} res, err := s.grpcServer.ListGrants(context.Background(), req)