protoc-gen-go-grpc-mock

command module
Version: v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2020 License: AGPL-3.0 Imports: 5 Imported by: 0

README

protoc-gen-go-grpc-mock

protoc-gen-go-grpc-mock is a protobuf plugin that autogenerates gRPC services mocks in Go using the github.com/stretchr/testify/mock package

Requirements

In order to work, protoc-gen-grpc-go requires:

Installation

go get -u github.com/nefixestrada/protoc-gen-go-grpc-mock

Usage

Compilation
protoc \
    --go_out=. \
    --go_opt=paths=source_relative \
    --go-grpc_out=. \
    --go-grpc_opt=paths=source_relative \
    --go-grpc-mock_out=. \
    --go-grpc-mock_opt=paths=source_relative \
pkg/proto/hyper.proto
Testing
func TestMock(t *testing.T) {
	assert := assert.New(t)
	require := require.New(t)

	service, client, err := proto.NewHyperServiceMock()
	if err != nil {
		require.NoError(err)
	}
	defer service.Stop()

	service.On(proto.DesktopList, mock.Anything, &proto.DesktopListRequest{}).Return((*proto.DesktopListResponse)(nil), status.Error(codes.Internal, "custom error! :D"))

	list, err := client.DesktopList(context.Background(), &proto.DesktopListRequest{})

	assert.EqualError(err, status.Error(codes.Internal, "custom error! :D").Error())
	assert.Nil(list)
}

Missing

  • Streaming Methods

Documentation

The Go Gopher

There is no documentation for this package.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL