proto/goutils/proto_build/tpls/http_grpc_method_test.tpl

40 lines
820 B
Smarty
Raw Normal View History

2023-11-27 09:36:02 +00:00
package test
import (
"context"
"net/http"
"{{.ProjectName}}/gen/go/service"
"{{.ProjectName}}/server/config"
"fusen-basic/env"
)
{{range .HttpGrpcTestStructs}}
var {{.RequestVar}} *service.{{.RequestStruct}}
func {{.MethodName}}Http(reqHandler func(*http.Request) error) (any, error) {
resp, err := HttpRequest({{.HttpMethod}}, gatewayAddrress+{{.UrlPath}}, {{.RequestVar}}, reqHandler)
if err != nil {
// t.Error(err)
return nil, err
}
return resp, nil
}
func {{.MethodName}}RPC() (any, error) {
if fusen == nil {
fusen := env.NewFusenTest[config.Config]()
fusen.StartNacos(nil)
service.AutoGrpcInit(fusen)
}
resp, err := service.Auto{{.ServiceName}}Client(context.TODO()).{{.MethodName}}(context.TODO(), {{.RequestVar}})
if err != nil {
return nil, err
}
return resp, nil
}
{{end}}