protoc-gen-moq

command module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2022 License: MIT Imports: 5 Imported by: 0

README

protoc-gen-moq

protoc-gen-moq is a plugin of the Google protocol buffers compiler protoc. It reads protobuf service definitions and generates a mocked service client structs. It generates its mocked struct using the matryer/moq template.

How to use it ?

You first need to install the plugin by placing it in your $PATH:

$ go install github.com/alexandrevilain/protoc-gen-moq@latest

Make sure that your $GOBIN is in your $PATH.

Then run it with protoc alongside the protoc-gen-go-grpc plugin:

$ protoc \
	--go_out=. \
	--go_opt=paths=source_relative \
	--go-grpc_out=. \
	--go-grpc_opt=paths=source_relative \
	--moq_out=. \
	--moq_opt=paths=source_relative \
   	hello.proto

Running tests

To run both unit and conformance tests run:

$ make test

Why not using the template package of github.com/matryer/moq ?

I can't use the template package from moq for two reasons:

  • the template package is inside the internal package which prevents external usage of the code inside.
  • the template package makes an extensive usage of go/types which is not used by protogen.

To ensure the 100% compatibility between struct generated by protoc-gen-moq and moq I created conformance tests which generate the mock for https://github.com/grpc/grpc-go/blob/master/test/grpc_testing/test.proto. The rendered moq file is then checked using go vet which will report an error if the generated struct does not implement the interface methods.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
examples
internal

Jump to

Keyboard shortcuts

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