Skip to content

Commit

Permalink
fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
anjaliagg9791 committed Sep 22, 2023
1 parent 5cb5626 commit 3b19721
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions api/handler/v1beta1/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ func (s *GrpcHandlersSuite) TestListResources() {
s.setup()
timeNow := time.Now()

ctx := context.Background()

req := &guardianv1beta1.ListResourcesRequest{
IsDeleted: true,
Type: "test-type",
Expand Down Expand Up @@ -85,9 +83,10 @@ func (s *GrpcHandlersSuite) TestListResources() {
Details: expectedDetails,
},
}
s.resourceService.EXPECT().Find(ctx, expectedFilters).Return(dummyResources, nil)
s.resourceService.EXPECT().GetResourcesTotalCount(ctx, expectedFilters).Return(int64(1), nil)
res, err := s.grpcServer.ListResources(ctx, req)
s.resourceService.EXPECT().Find(mock.AnythingOfType("*context.cancelCtx"), expectedFilters).Return(dummyResources, nil)
s.resourceService.EXPECT().GetResourcesTotalCount(mock.AnythingOfType("*context.cancelCtx"),
expectedFilters).Return(0, nil).Once()
res, err := s.grpcServer.ListResources(context.Background(), req)

s.NoError(err)
s.Equal(expectedResponse, res)
Expand All @@ -98,7 +97,10 @@ func (s *GrpcHandlersSuite) TestListResources() {
s.setup()

expectedError := errors.New("random error")
s.resourceService.EXPECT().Find(mock.AnythingOfType("*context.emptyCtx"), mock.Anything).Return(nil, expectedError).Once()
s.resourceService.EXPECT().Find(mock.AnythingOfType("*context.cancelCtx"),
mock.AnythingOfType("domain.ListResourcesFilter")).Return(nil, expectedError).Once()
s.resourceService.EXPECT().GetResourcesTotalCount(mock.AnythingOfType("*context.cancelCtx"),
mock.AnythingOfType("domain.ListResourcesFilter")).Return(0, nil).Once()

req := &guardianv1beta1.ListResourcesRequest{}
res, err := s.grpcServer.ListResources(context.Background(), req)
Expand All @@ -118,7 +120,10 @@ func (s *GrpcHandlersSuite) TestListResources() {
},
},
}
s.resourceService.EXPECT().Find(mock.AnythingOfType("*context.emptyCtx"), mock.Anything).Return(invalidResources, nil).Once()
s.resourceService.EXPECT().Find(mock.AnythingOfType("*context.cancelCtx"),
mock.AnythingOfType("domain.ListResourcesFilter")).Return(invalidResources, nil).Once()
s.resourceService.EXPECT().GetResourcesTotalCount(mock.AnythingOfType("*context.cancelCtx"),
mock.AnythingOfType("domain.ListResourcesFilter")).Return(0, nil).Once()

req := &guardianv1beta1.ListResourcesRequest{}
res, err := s.grpcServer.ListResources(context.Background(), req)
Expand Down

0 comments on commit 3b19721

Please sign in to comment.