feat(storage-gateway): add storage gateway mock

This commit is contained in:
bandl 2021-11-18 14:54:03 +08:00
parent 981a3341ef
commit 113185d17c
2 changed files with 17 additions and 0 deletions

View File

@ -4,9 +4,14 @@ import (
"sync"
"gitee.com/wheat-os/wheatCache/pkg/proto"
"github.com/golang/mock/gomock"
)
var (
oneGatewayClient sync.Once
gatewayClient proto.CommServerClient
)
var (
GateWayCtrl *gomock.Controller
)

View File

@ -5,10 +5,22 @@ import (
"gitee.com/wheat-os/wheatCache/client"
"gitee.com/wheat-os/wheatCache/client/middle"
_ "gitee.com/wheat-os/wheatCache/conf"
mockClient "gitee.com/wheat-os/wheatCache/mock/storage"
"gitee.com/wheat-os/wheatCache/pkg/errorx"
"gitee.com/wheat-os/wheatCache/pkg/proto"
"github.com/spf13/viper"
)
func NewGatewayClient() (proto.CommServerClient, error) {
if viper.GetString("env") == "dev" {
if GateWayCtrl == nil {
return nil, errorx.New("mock ctrl not init")
}
return mockClient.NewMockCommServerClient(GateWayCtrl), nil
}
oneGatewayClient.Do(func() {
cli, err := client.NewWheatClient("127.0.0.1:5891", middle.WithUnaryColonyClient)
if err == nil {