Skip to content

Commit f64b1c4

Browse files
committed
move mocks to the mock pkgs
1 parent 49814fd commit f64b1c4

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

internal/test/mock/grpc_testify_mock.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"context"
1818

1919
"github.com/stretchr/testify/mock"
20+
"github.com/vdaas/vald/apis/grpc/v1/payload"
2021
"google.golang.org/grpc/metadata"
2122
)
2223

@@ -52,3 +53,13 @@ func (*ServerStreamTestifyMock) SendMsgWithContext(_ context.Context, _ interfac
5253
func (*ServerStreamTestifyMock) RecvMsg(_ interface{}) error {
5354
return nil
5455
}
56+
57+
// ListObjectStreamMock is a testify mock struct for ListObjectStream based on ServerStreamTestifyMock
58+
type ListObjectStreamMock struct {
59+
ServerStreamTestifyMock
60+
}
61+
62+
func (losm *ListObjectStreamMock) Send(res *payload.Object_List_Response) error {
63+
args := losm.Called(res)
64+
return args.Error(0)
65+
}

pkg/agent/core/ngt/handler/grpc/object_test.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,15 +1188,6 @@ func Test_server_GetObject(t *testing.T) {
11881188
}
11891189
}
11901190

1191-
type ListObjectStreamMock struct {
1192-
mock.ServerStreamTestifyMock
1193-
}
1194-
1195-
func (sssm *ListObjectStreamMock) Send(res *payload.Object_List_Response) error {
1196-
args := sssm.Called(res)
1197-
return args.Error(0)
1198-
}
1199-
12001191
func Test_server_StreamGetObject(t *testing.T) {
12011192
t.Parallel()
12021193

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

12601251
// Set mock and expectations
1261-
stream := ListObjectStreamMock{}
1252+
stream := mock.ListObjectStreamMock{}
12621253
stream.On("Send", tmock.Anything).Return(nil)
12631254

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

13041295
// Set mock and expectations
1305-
stream := ListObjectStreamMock{}
1296+
stream := mock.ListObjectStreamMock{}
13061297
stream.On("Send", tmock.Anything).Return(status.New(codes.Unknown, "foo").Err()).Once()
13071298
stream.On("Send", tmock.Anything).Return(status.New(codes.Aborted, "bar").Err())
13081299

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

13261317
// Set mock and expectations
1327-
stream := ListObjectStreamMock{}
1318+
stream := mock.ListObjectStreamMock{}
13281319
stream.On("Send", tmock.Anything).Return(nil)
13291320

13301321
// Call the method under test

0 commit comments

Comments
 (0)