
- 定义接口
- 实现接口
- 实现测试桩
- 定义代理
- 聚合多个rpc接口服务
测试
third.InitThirdProxyStub()
func (suite *TestTestStubSuite) Test009_ContactShopEs() {
var ret, err = third.FindBeanThirdProxy().ContactShopListQuery([]int64{974835942347243523})
golog.Info(esobject.AdapterFrom(ret), err)
}
INFO[ git.ichub.com/general/webcli120/goconfig/base/goutils.Info() {
"list": [
{
"id": 974835942347243523,
"created_by": 974835940126588931,
"updated_by": 974835940126588931,
"name": "ichubp之家",
"short_name": "ichubp之家",
"slug": "347dcdcf-4b3d-49aa-a983-9f670d7c2025",
"status": "L",
"shop_type": "single",
"default_address": " ",
"contactId": "53a9a98d-3125-4f9a-8db0-bd618f80e0b8",
"main_account_num": "CA4954124",
"Address": {
},
"partner_id": 974835942347243523,
"partner": "ichubp之家",
"contact_shop_code": "CS0526255",
"station": "icHub",
"created_by_name": "ichubp0398",
"updated_by_name": "ichubp0398"
}
],
"pagination": {
"total": 1,
"current": 1,
"page_size": 500
}
}
接口
package thirdiface
import (
"context"
"github.com/micro/go-micro/v2/client"
accountProto "icd/proto/account"
connectProto "icd/proto/connection"
cooProto "icd/proto/coo"
)
type ThirdIface interface {
GetAccountByShopIds(shop_ids []int64) *accountProto.AccountAllResult
ContactShopMemberQueryByIds(ids []int64) (*connectProto.ContactShopMemberQueryResult, error)
ContactShopMemberQuery(ctx context.Context, in *connectProto.ContactShopMemberQueryRequest, opts ...client.CallOption) (*connectProto.ContactShopMemberQueryResult, error)
CooDeptIdsByMmberId(memberIds []int64) (*cooProto.CooMemberJobShopMemberRelRespList, error)
//GetAccountContactByIds(ids []int64) (*accountProto.AccountContactRecords, error)
ContactShopListQuery(ids []int64) (*connectProto.ContactShopQueryResult, error)
}
代理
package third
import (
"git.ichub.com/general/webcli120/goconfig/base/basedto"
"icd/general-srv/third/thirdiface"
"icd/general-srv/third/thirdstub"
)
func InitThirdProxyStub() *ThirdProxy {
var bean *ThirdProxy = FindBeanThirdProxy()
bean.ThirdIface = thirdstub.FindBeanTestStub()
return bean
}
type ThirdProxy struct {
basedto.BaseEntitySingle
thirdiface.ThirdIface
}
func NewThirdProxy() *ThirdProxy {
return &ThirdProxy{
ThirdIface: FindBeanThirdImpl(),
}
}
package third
import (
"context"
"git.ichub.com/general/webcli120/goconfig/base/basedto"
"github.com/micro/go-micro/v2/client"
accountProto "icd/proto/account"
connectProto "icd/proto/connection"
cooProto "icd/proto/coo"
)
type ThirdImpl struct {
basedto.BaseEntitySingle
connectionClient connectProto.ConnectionService
}
func NewThirdImpl() *ThirdImpl {
return &ThirdImpl{}
}
func (t ThirdImpl) GetAccountByShopIds(shop_ids []int64) *accountProto.AccountAllResult {
return GetAccountByShopIds(shop_ids)
}
func (t ThirdImpl) ContactShopMemberQueryByIds(ids []int64) (*connectProto.ContactShopMemberQueryResult, error) {
return ContactShopMemberQueryByIds(ids)
}
func (t ThirdImpl) ContactShopMemberQuery(ctx context.Context, in *connectProto.ContactShopMemberQueryRequest, opts ...client.CallOption) (*connectProto.ContactShopMemberQueryResult, error) {
return t.connectionClient.ContactShopMemberQuery(ctx, in, opts...)
}
func (t ThirdImpl) CooDeptIdsByMmberId(memberIds []int64) (*cooProto.CooMemberJobShopMemberRelRespList, error) {
return CooDeptIdsByMmberId(memberIds)
}
func (t ThirdImpl) ContactShopListQuery(ids []int64) (*connectProto.ContactShopQueryResult, error) {
return ContactShopListQuery(ids)
}
package thirdstub
import (
"context"
"git.ichub.com/general/webcli120/goconfig/base/basedto"
"git.ichub.com/general/webcli120/goconfig/ichublog/golog"
"git.ichub.com/general/webcli120/goweb/pagemodel"
"git.ichub.com/general/webcli120/goweb/webclient/eswebclient/webfacade"
"github.com/gogf/gf/v2/util/gconv"
"github.com/micro/go-micro/v2/client"
"github.com/olivere/elastic/v7"
"icd/general-srv/third/thirdstub/thirddto"
"icd/pkg/clifacade/esclient/esobject"
accountProto "icd/proto/account"
connectProto "icd/proto/connection"
cooProto "icd/proto/coo"
)
type ThirdStub struct {
basedto.BaseEntitySingle
}
func NewThirdStub() *ThirdStub {
return &ThirdStub{}
}
func (t ThirdStub) GetAccountContactByIds(ids []int64) (*accountProto.AccountContactRecords, error) {
return nil, nil
}
func (t ThirdStub) Ret2AccountAllResult(ret *pagemodel.PageResult[*thirddto.AccountStub]) *accountProto.AccountAllResult {
var result = accountProto.AccountAllResult{
PageResult: &accountProto.PaginationResult{},
}
result.PageResult.PageSize = gconv.Uint32(ret.PageSize)
result.PageResult.Current = uint32(ret.PageCurrent)
result.PageResult.Total = uint64(ret.Total)
return &result
}
func (t ThirdStub) GetAccountByShopIds(shop_ids []int64) *accountProto.AccountAllResult {
var q = elastic.NewTermsQuery("root_shop_id", gconv.SliceAny(shop_ids)...)
var qq = webfacade.DefaultOf[*thirddto.AccountStub](q)
var ret = qq.GeneralQueryMax()
qq.SetSource("id,full_name,root_shop_id")
var data = make([]*accountProto.Account, 0)
golog.Info(ret)
gconv.Structs(ret.Data, &data)
var rets = t.Ret2AccountAllResult(ret)
rets.Data = data
return rets
}
func (t ThirdStub) Ret2ContactShopMemberQueryResult(ret *pagemodel.PageResult[*thirddto.ContactShopMemberStub]) *connectProto.ContactShopMemberQueryResult {
var result = connectProto.ContactShopMemberQueryResult{
Pagination: &connectProto.Pagination{},
}
result.Pagination.PageSize = gconv.Uint32(ret.PageSize)
result.Pagination.Current = uint32(ret.PageCurrent)
result.Pagination.Total = uint32(ret.Total)
return &result
}
func (t ThirdStub) ContactShopMemberQueryByIds(ids []int64) (*connectProto.ContactShopMemberQueryResult, error) {
var q = elastic.NewTermsQuery("id", gconv.SliceAny(ids)...)
var qq = webfacade.DefaultOf[*thirddto.ContactShopMemberStub](q)
var ret = qq.GeneralQueryMax()
golog.Info("[ContactShopMemberQueryByIds] =", ret)
var rets = t.Ret2ContactShopMemberQueryResult(ret)
var data = make([]*connectProto.ContactShopMember, 0)
err := gconv.Structs(ret.Data, &data)
if err != nil {
golog.Info("ContactShopMemberQueryByIds] ", err)
return nil, err
}
rets.List = data
return rets, nil
}
func (t ThirdStub) ContactShopMemberQuery(ctx context.Context, in *connectProto.ContactShopMemberQueryRequest, opts ...client.CallOption) (*connectProto.ContactShopMemberQueryResult, error) {
// ContactShopMemberQuery(ctx context.Context, in *ContactShopMemberQueryRequest, opts ...client.CallOption) (*ContactShopMemberQueryResult, error)
var q = elastic.NewTermsQuery("id", gconv.SliceAny(in.Ids)...)
var qq = webfacade.DefaultOf[*thirddto.ContactShopMemberStub](q)
var ret = qq.GeneralQueryMax()
golog.Info("[ContactShopMemberQueryByIds] =", ret)
var rets = t.Ret2ContactShopMemberQueryResult(ret)
var data = make([]*connectProto.ContactShopMember, 0)
err := gconv.Structs(ret.Data, &data)
if err != nil {
golog.Info("ContactShopMemberQueryByIds] ", err)
return nil, err
}
rets.List = data
return rets, nil
}
func (t ThirdStub) CooDeptIdsByMmberId(memberIds []int64) (*cooProto.CooMemberJobShopMemberRelRespList, error) {
var q = elastic.NewBoolQuery()
q.Must(elastic.NewTermQuery("active", true))
q.Must(elastic.NewTermsQuery("shop_member_id", gconv.SliceAny(memberIds)...))
var qq = webfacade.DefaultOf[*thirddto.CooMemberJobRel](q)
var ret = qq.GeneralQueryMax()
var c = cooProto.CooMemberJobShopMemberRelRespList{
//Data:[]cooProto.CooMemberJobShopMemberRel{},
PageResult: &cooProto.PaginationResult{},
}
c.PageResult.PageSize = int64(ret.PageSize)
c.PageResult.Current = int64(ret.PageCurrent)
c.PageResult.Total = int64(ret.Total)
gconv.Structs(ret.Data, &c.Data)
golog.Info(ret, esobject.AdapterFrom(c))
return &c, ret.Result2Error() //third.CooDeptIdsByMmberId(memberIds)
}
func (t ThirdStub) ContactShopListQuery(ids []int64) (*connectProto.ContactShopQueryResult, error) {
var q = elastic.NewBoolQuery()
q.Must(elastic.NewTermsQuery("id", gconv.SliceAny(ids)...))
var qq = webfacade.DefaultOf[*thirddto.ContactShopEs](q)
var ret = qq.GeneralQueryMax()
golog.Info(ret)
var rets = &connectProto.ContactShopQueryResult{
Pagination: &connectProto.Pagination{},
}
rets.Pagination.PageSize = uint32(ret.PageSize)
rets.Pagination.Current = uint32(ret.PageCurrent)
rets.Pagination.Total = uint32(ret.Total)
gconv.Structs(ret.Data, &rets.List)
golog.Info(ret, esobject.AdapterFrom(rets))
return rets, ret.Result2Error()
}
测试套全文
package thirdtest
import (
"git.ichub.com/general/webcli120/goconfig/ichubconfig"
"git.ichub.com/general/webcli120/goconfig/ichublog/golog"
"git.ichub.com/general/webcli120/goweb/webclient/eswebclient/webfacade"
"github.com/gogf/gf/v2/util/gconv"
"github.com/olivere/elastic/v7"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"icd/general-srv/third"
"icd/general-srv/third/thirdstub"
cooProto "icd/proto/coo"
"icd/general-srv/third/thirdstub/thirddto"
"icd/pkg/clifacade/esclient/esobject"
"icd/pkg/clifacade/test/testenv"
"testing"
)
type TestTestStubSuite struct {
suite.Suite
inst *thirdstub.ThirdStub
rootdir string
dbtype string
cfg *ichubconfig.IchubConfig
}
func TestTestStubSuites(t *testing.T) {
suite.Run(t, new(TestTestStubSuite))
}
func (suite *TestTestStubSuite) SetupSuite() {
logrus.Info(" setup suite")
testenv.FindBeanReleaseEnv().Init()
suite.inst = thirdstub.FindBeanTestStub()
third.InitThirdProxyStub()
}
func (suite *TestTestStubSuite) TearDownSuite() {
logrus.Info(" teardown suite")
}
func (suite *TestTestStubSuite) SetupTest() {
logrus.Info(" setup test")
}
// 764236805152309249
func (suite *TestTestStubSuite) TearDownTest() {
logrus.Info(" teardown test")
}
func (suite *TestTestStubSuite) Test001_GetAccountByShopIds() {
logrus.Info(" Test001_GetAccountByShopIds test")
var ret = suite.inst.GetAccountByShopIds([]int64{673093338758840321})
golog.Info(esobject.AdapterFrom(ret))
}
func (suite *TestTestStubSuite) Test002_ContactShopMemberQueryByIds() {
logrus.Info(" Test002_ContactShopMemberQueryByIds test")
var ret, err = suite.inst.ContactShopMemberQueryByIds([]int64{764236805152309249})
golog.Info("Test002_ContactShopMemberQueryByIds=", esobject.AdapterFrom(ret), err)
}
func (suite *TestTestStubSuite) Test003_ContactShopMemberQueryByIds() {
logrus.Info(" Test002_ContactShopMemberQueryByIds test")
var ret, err = suite.inst.ContactShopMemberQueryByIds([]int64{764236805152309249})
golog.Info("Test002_ContactShopMemberQueryByIds=", esobject.AdapterFrom(ret), err)
}
//CooMemberJob CooMemberJobRel
func (suite *TestTestStubSuite) Test005_CooMemberJobRel() {
logrus.Info(" test")
var q = elastic.NewMatchAllQuery()
var qq = webfacade.DefaultOf[*thirddto.CooMemberJobRel](q)
var ret = qq.GeneralQuery()
var c = cooProto.CooMemberJobShopMemberRelRespList{
//Data:[]cooProto.CooMemberJobShopMemberRel{},
}
gconv.Structs(ret.Data, &c.Data)
golog.Info(ret, esobject.AdapterFrom(c))
//895568159726403585
}
func (suite *TestTestStubSuite) Test006_ContactShopMemberQueryByIds() {
logrus.Info(" test")
var q = elastic.NewMatchAllQuery()
var qq = webfacade.DefaultOf[*thirddto.CooMemberJob](q)
var ret = qq.GeneralQuery()
var models = []*cooProto.CooMemberJobShopMemberRel{}
golog.Info(ret)
gconv.Structs(ret.Data, &models)
for i := 0; i < len(models); i++ {
models[i] = ret.Data[i].ToCooMemberJobShopMemberRel()
}
golog.Info(esobject.AdapterFrom(models))
}
func (suite *TestTestStubSuite) Test007_CooMemberJobRel() {
var ret, err = thirdstub.FindBeanTestStub().CooDeptIdsByMmberId([]int64{895571843400531969})
//
golog.Info(err, esobject.AdapterFrom(ret)) //ContactShopEs
}
func (suite *TestTestStubSuite) Test008_ContactShopEs() {
var q = elastic.NewMatchAllQuery()
var qq = webfacade.DefaultOf[*thirddto.ContactShopEs](q)
var ret = qq.GeneralQuery()
golog.Info(ret)
}
func (suite *TestTestStubSuite) Test009_ContactShopEs() {
var ret, err = third.FindBeanThirdProxy().ContactShopListQuery([]int64{974835942347243523})
golog.Info(esobject.AdapterFrom(ret), err)
}
func (suite *TestTestStubSuite) Test009_CooSbuEs() {
var q = elastic.NewMatchAllQuery()
var qq = webfacade.DefaultOf[*thirddto.CooSbuEs](q)
var ret = qq.GeneralQueryMax()
golog.Info(ret)
}


被折叠的 条评论
为什么被折叠?



