Skip to content

Commit

Permalink
chore: add validator_fields option
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtARTs36 committed Aug 14, 2024
1 parent 4d2c3ae commit 8ecf81c
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 98 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ test:
--go-srv-handler_opt=gen_tests=true \
--go-srv-handler_opt=handler_file_naming=without_domain \
--go-srv-handler_opt=request_validator=ozzo \
userapi/*.proto
--go-srv-handler_opt=request_validator_fields=all \
example/*.proto

lint:
golangci-lint run --fix
3 changes: 2 additions & 1 deletion userapi/example.proto → example/example.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ syntax = "proto3";

package userapi;

option go_package = "github.com/artarts36/protoc-gen-go-srv-handler/userapi;userapi";
option go_package = "github.com/artarts36/protoc-gen-go-srv-handler/example;userapi";

service UserService {
rpc Add(AddUserRequest) returns (AddUserResponse);
Expand All @@ -18,6 +18,7 @@ service SuperUserService {
message AddUserRequest {
string name = 1;
int32 age = 2;
optional string phone = 3;
}

message AddUserResponse {
Expand Down
11 changes: 6 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module github.com/artarts36/protoc-gen-go-srv-handler

go 1.16
go 1.21

require (
google.golang.org/grpc v1.27.0
google.golang.org/protobuf v1.25.0
)
toolchain go1.21.10

require google.golang.org/protobuf v1.34.2

require github.com/google/go-cmp v0.6.0 // indirect
75 changes: 4 additions & 71 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,71 +1,4 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.27.0 h1:rRYRFMVgRv6E0D70Skyfsr28tDXIuuPZyWGMPdMcnXg=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
6 changes: 4 additions & 2 deletions internal/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ type Message struct {
}

type MessageProperties struct {
All []*MessageProperty
Required []*MessageProperty
All []*MessageProperty
Required []*MessageProperty
Validateable []*MessageProperty
}

type MessageProperty struct {
GoName string
Type ValType
Required bool
Optional bool
}

func (p *MessageProperty) ExampleValue() string {
Expand Down
3 changes: 2 additions & 1 deletion internal/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ type RenderHandlerParams struct {
RequestValidator RequestValidator
}

func (r *Renderer) RenderHandlerTest(w io.Writer, hand *Handler) error {
func (r *Renderer) RenderHandlerTest(w io.Writer, hand *Handler, params RenderHandlerParams) error {
return r.templates.service.ExecuteTemplate(w, "handler_test.template", map[string]interface{}{
"Service": hand.Service,
"Handler": hand,
"Params": params,
})
}
29 changes: 22 additions & 7 deletions internal/req.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
package internal

type RequestValidator string
type RequestValidatorType string

const (
RequestValidatorNo = RequestValidator("no")
RequestValidatorOzzo = RequestValidator("ozzo")
RequestValidatorTypeNo = RequestValidatorType("no")
RequestValidatorTypeOzzo = RequestValidatorType("ozzo")
)

func CreateRequestValidator(val string) RequestValidator {
if val == string(RequestValidatorOzzo) {
return RequestValidatorOzzo
type RequestValidatorFields string

const (
RequestValidatorFieldsNonOptional = RequestValidatorFields("non_optional")
)

type RequestValidator struct {
Type RequestValidatorType
Fields RequestValidatorFields
}

func CreateRequestValidator(val string) RequestValidatorType {
if val == string(RequestValidatorTypeOzzo) {
return RequestValidatorTypeOzzo
}

return RequestValidatorNo
return RequestValidatorTypeNo
}

func CreateRequestValidatorFields(_ string) RequestValidatorFields {
return RequestValidatorFieldsNonOptional
}
14 changes: 12 additions & 2 deletions internal/srv_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type CollectOpts struct {
SrvNaming SrvNaming
PkgNaming PkgNaming
HandlerFileNaming HandlerFileNaming
RequestValidator RequestValidator
}

type handlerFileNames struct {
Expand Down Expand Up @@ -77,7 +78,7 @@ func (c *SrvCollector) Collect(file *protogen.File, opts CollectOpts) (*Services

handlersByFiles[names.selected] = names

inputMsg := Message{
inputMsg := &Message{
Name: string(method.Input.Desc.Name()),
Properties: MessageProperties{
All: make([]*MessageProperty, 0),
Expand All @@ -90,6 +91,7 @@ func (c *SrvCollector) Collect(file *protogen.File, opts CollectOpts) (*Services
GoName: field.GoName,
Type: createValType(field.Desc.Kind()),
Required: !field.Desc.HasOptionalKeyword(),
Optional: field.Desc.HasOptionalKeyword(),
}

inputMsg.Properties.All = append(inputMsg.Properties.All, prop)
Expand All @@ -98,11 +100,13 @@ func (c *SrvCollector) Collect(file *protogen.File, opts CollectOpts) (*Services
}
}

c.setMessageValidateableFields(inputMsg, opts)

handler := &Handler{
Filename: names.selected,
MethodName: method.GoName,
InputMsgStructName: string(method.Input.Desc.Name()),
InputMsg: inputMsg,
InputMsg: *inputMsg,
OutputMsgStructName: string(method.Output.Desc.Name()),
Service: srv,
}
Expand Down Expand Up @@ -159,3 +163,9 @@ func (*SrvCollector) generateHandlerFilename(

return names
}

func (*SrvCollector) setMessageValidateableFields(msg *Message, opts CollectOpts) {
if opts.RequestValidator.Type != RequestValidatorTypeNo {
msg.Properties.Validateable = msg.Properties.Required
}
}
22 changes: 19 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os"
"path/filepath"

"google.golang.org/protobuf/types/pluginpb"

"github.com/artarts36/protoc-gen-go-srv-handler/internal"
"google.golang.org/protobuf/compiler/protogen"
)
Expand All @@ -27,13 +29,20 @@ func main() {
)
requestValidatorVal := flags.String(
"request_validator",
string(internal.HandlerFileNamingAsIs),
string(internal.RequestValidatorTypeNo),
"Request validator: `no`, `ozzo`",
)
requestValidatorFieldsVal := flags.String(
"request_validator_fields",
string(internal.RequestValidatorFieldsNonOptional),
"Request validator fields: `non_optional`",
)

protogen.Options{
ParamFunc: flags.Set,
}.Run(func(gen *protogen.Plugin) error {
gen.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)

if *outDir == "" {
return fmt.Errorf("out_dir is required, set --go-srv-handler_opt=out_dir=./dir")
}
Expand All @@ -42,6 +51,7 @@ func main() {
srvNaming := internal.CreateSrvNaming(*srvNamingVal)
handlerFileNaming := internal.CreateHandlerFileNaming(*handlerFileNamingVal)
reqValidator := internal.CreateRequestValidator(*requestValidatorVal)
reqValidatorFields := internal.CreateRequestValidatorFields(*requestValidatorFieldsVal)

renderer, err := internal.NewRenderer()
if err != nil {
Expand All @@ -62,7 +72,10 @@ func main() {
srvCollector: internal.NewSrvCollector(),
renderer: renderer,
srvNaming: srvNaming,
reqValidator: reqValidator,
reqValidator: internal.RequestValidator{
Type: reqValidator,
Fields: reqValidatorFields,
},
}

for _, f := range gen.Files {
Expand Down Expand Up @@ -96,6 +109,7 @@ func (c *command) gen(gen *protogen.Plugin, file *protogen.File) error {
PkgNaming: c.pkgNaming,
SrvNaming: c.srvNaming,
HandlerFileNaming: c.handlerFileNaming,
RequestValidator: c.reqValidator,
})
if err != nil {
return fmt.Errorf("failed to collect services: %w", err)
Expand Down Expand Up @@ -157,7 +171,9 @@ func (c *command) genHandlers(gen *protogen.Plugin, file *protogen.File, srv *in
func (c *command) genHandlerTest(gen *protogen.Plugin, file *protogen.File, handler *internal.Handler) error {
handlerTestGenFile := gen.NewGeneratedFile(handler.TestFileName(), file.GoImportPath)
if !c.skipFile(handler.TestFileName()) {
err := c.renderer.RenderHandlerTest(handlerTestGenFile, handler)
err := c.renderer.RenderHandlerTest(handlerTestGenFile, handler, internal.RenderHandlerParams{
RequestValidator: c.reqValidator,
})
if err != nil {
return fmt.Errorf("failed rendering handler test: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions templates/handler.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package {{.Service.PackageName}}
import (
"context"

{{if eq .Params.RequestValidator "ozzo"}}validation "github.com/go-ozzo/ozzo-validation/v4"{{end}}
{{if eq .Params.RequestValidator.Type "ozzo"}}validation "github.com/go-ozzo/ozzo-validation/v4"{{end}}
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand All @@ -13,17 +13,17 @@ import (
func (srv *{{.Service.Name}}) {{.Handler.MethodName }} (
ctx context.Context,
req *{{.Service.APIImportPackage.Alias}}.{{.Handler.InputMsg.Name }},
) (*{{.Service.APIImportPackage.Alias}}.{{.Handler.OutputMsgStructName }}, error) { {{if ne .Params.RequestValidator "no"}}
) (*{{.Service.APIImportPackage.Alias}}.{{.Handler.OutputMsgStructName }}, error) { {{if ne .Params.RequestValidator.Type "no"}}
if err := srv.validate{{.Handler.MethodName }}Request(req); err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
{{end}}
return &{{.Service.APIImportPackage.Alias}}.{{.Handler.OutputMsgStructName }}{}, nil
}

{{if eq .Params.RequestValidator "ozzo"}}
{{if eq .Params.RequestValidator.Type "ozzo"}}
func (srv *{{.Service.Name}}) validate{{.Handler.MethodName }}Request(req *{{.Service.APIImportPackage.Alias}}.{{.Handler.InputMsg.Name }}) error {
return validation.Errors{ {{ range .Handler.InputMsg.Properties.Required }}{{ if ne .Type 0 }}
return validation.Errors{ {{ range .Handler.InputMsg.Properties.Validateable }}{{ if ne .Type 0 }}
"{{ .GoName }}" : validation.Validate(req.{{ .GoName }}, validation.Required),{{ end }}{{ end }}
}.Filter()
}
Expand Down
3 changes: 2 additions & 1 deletion templates/handler_test.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"

{{if .Service.APIImportPackage.AliasEqualsLastPackage}}{{ else }}{{.Service.APIImportPackage.Alias}} {{ end }}"{{.Service.APIImportPackage.FullName}}"
)

func Test{{.Handler.MethodName }}(t *testing.T) {
tEnv := newTestEnv()

resp, err := tEnv.service.{{.Handler.MethodName }}(tEnv.ctx, &{{.Service.APIImportPackage.Alias}}.{{.Handler.InputMsgStructName }}{ {{ range .Handler.InputMsg.Properties.Required }}{{ if ne .Type 0 }}
resp, err := tEnv.service.{{.Handler.MethodName }}(tEnv.ctx, &{{.Service.APIImportPackage.Alias}}.{{.Handler.InputMsgStructName }}{ {{ range .Handler.InputMsg.Properties.Validateable }}{{ if ne .Type 0 }}
{{ .GoName }}: {{ if eq .Type 1 }}"{{ .ExampleValue }}"{{ else }}{{ .ExampleValue }}{{ end }},{{ end }}
{{ end }}})
require.NoError(t, err)
Expand Down

0 comments on commit 8ecf81c

Please sign in to comment.