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

protoc-gen-go-grpc-mock is a protobuf plugin that autogenerates gRPC mocks in Go

License

Notifications You must be signed in to change notification settings

NefixEstrada/protoc-gen-go-grpc-mock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

protoc-gen-go-grpc-mock is a protobuf plugin that autogenerates gRPC mocks in Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages