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") + +}