Skip to content

Commit

Permalink
move mocks to the mock pkgs
Browse files Browse the repository at this point in the history
  • Loading branch information
ykadowak committed Aug 1, 2023
1 parent 49814fd commit f64b1c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
11 changes: 11 additions & 0 deletions internal/test/mock/grpc_testify_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"context"

"github.com/stretchr/testify/mock"
"github.com/vdaas/vald/apis/grpc/v1/payload"
"google.golang.org/grpc/metadata"
)

Expand Down Expand Up @@ -52,3 +53,13 @@ func (*ServerStreamTestifyMock) SendMsgWithContext(_ context.Context, _ interfac
func (*ServerStreamTestifyMock) RecvMsg(_ interface{}) error {
return nil
}

// ListObjectStreamMock is a testify mock struct for ListObjectStream based on ServerStreamTestifyMock
type ListObjectStreamMock struct {
ServerStreamTestifyMock
}

func (losm *ListObjectStreamMock) Send(res *payload.Object_List_Response) error {
args := losm.Called(res)
return args.Error(0)
}
15 changes: 3 additions & 12 deletions pkg/agent/core/ngt/handler/grpc/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1188,15 +1188,6 @@ func Test_server_GetObject(t *testing.T) {
}
}

type ListObjectStreamMock struct {
mock.ServerStreamTestifyMock
}

func (sssm *ListObjectStreamMock) Send(res *payload.Object_List_Response) error {
args := sssm.Called(res)
return args.Error(0)
}

func Test_server_StreamGetObject(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1258,7 +1249,7 @@ func Test_server_StreamGetObject(t *testing.T) {
require.NoError(t, err)

// Set mock and expectations
stream := ListObjectStreamMock{}
stream := mock.ListObjectStreamMock{}
stream.On("Send", tmock.Anything).Return(nil)

// Call the method under test
Expand Down Expand Up @@ -1302,7 +1293,7 @@ func Test_server_StreamGetObject(t *testing.T) {
require.NoError(t, err)

// Set mock and expectations
stream := ListObjectStreamMock{}
stream := mock.ListObjectStreamMock{}
stream.On("Send", tmock.Anything).Return(status.New(codes.Unknown, "foo").Err()).Once()
stream.On("Send", tmock.Anything).Return(status.New(codes.Aborted, "bar").Err())

Expand All @@ -1324,7 +1315,7 @@ func Test_server_StreamGetObject(t *testing.T) {
_, s := setup(t)

// Set mock and expectations
stream := ListObjectStreamMock{}
stream := mock.ListObjectStreamMock{}
stream.On("Send", tmock.Anything).Return(nil)

// Call the method under test
Expand Down

0 comments on commit f64b1c4

Please sign in to comment.