Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Latest commit

 

History

History
57 lines (41 loc) · 1.26 KB

README.md

File metadata and controls

57 lines (41 loc) · 1.26 KB

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