protoc-gen-grpc-mock

command
v0.0.0-...-4b711b1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

protoc-gen-grpc-mock

This is a protoc-gen-* binary to be used for generating GRPC server mock implementations in a convenient and type-safe way.

There is two different variants: for example, with UsersMgmtServer, you can chose either

mockLocalUser := local_users_api.NewUsersMgmtServerMock()

or

mockLocalUser := local_users_api.NewUsersMgmtServerMockWithoutValidation()

The former will attempt to validate incoming requests in its mock handler functions: if the request satisfies the interface

Validate() error

it will call this function, and return a status with codes.InvalidArgument if it exits non-nil.

This interface is what PGV gives us, which is currently used for API validation in authz-service.

Generate mock code

Use it via a component's grpc.sh script, after having installed it (the studio takes care of this for you).

The relevant snippet that goes into the components scripts/grpc.sh looks like this:

protoc -I. \
  -I$GOPATH/src \
  -Iprotovendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
  --grpc-mock_out=$GOPATH/src \
  path/to/your/*.proto

Note that the script is meant to be run from the top-level a2 directory in the studio, using its compile_go_protobuf_component helper. For example, generating the mocks for authz-service:

[0][default:/src:0]# compile_go_protobuf_component authz-service

For developing this, or to manually install this, run

install_go_tool github.com/chef/automate/components/automate-grpc/protoc-gen-grpc-mock

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL