From e5f217b3b0eded1651176b26a3b80963abd34774 Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Thu, 18 Nov 2021 14:54:27 +0800 Subject: [PATCH] teat(storage-gateway): add gateway mock --- storage/external/gateway_test.go | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 storage/external/gateway_test.go diff --git a/storage/external/gateway_test.go b/storage/external/gateway_test.go new file mode 100644 index 0000000..f495e77 --- /dev/null +++ b/storage/external/gateway_test.go @@ -0,0 +1,36 @@ +package external + +import ( + "context" + "testing" + + _ "gitee.com/wheat-os/wheatCache/conf" + mockClient "gitee.com/wheat-os/wheatCache/mock/storage" + "gitee.com/wheat-os/wheatCache/pkg/proto" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" +) + +func TestNewGatewayClient(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + GateWayCtrl = ctrl + + cli, err := NewGatewayClient() + require.NoError(t, err) + mockClient := cli.(*mockClient.MockCommServerClient) + ctx := context.Background() + + mockClient.EXPECT().Get(ctx, gomock.Any()).Return(&proto.GetResponse{ + Result: "mockData", + }, nil) + + resp, err := mockClient.Get(ctx, nil) + require.NoError(t, err) + require.Equal(t, resp.Result, "mockData") + + resp, err = mockClient.Get(ctx, nil) + require.NoError(t, err) + require.Equal(t, resp.Result, "mockData") + +}