Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example code and documentation on how to mock gRPC services #1021

Merged
merged 9 commits into from
Feb 14, 2017

Conversation

MakMukhi
Copy link
Contributor

No description provided.

@MakMukhi MakMukhi changed the title Mmukhi gomock example Example code and documentation on how to mock gRPC services Dec 13, 2016
"testing"

"github.com/golang/mock/gomock"
proto "github.com/golang/protobuf/proto"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The renaming is unnecessary.

@@ -0,0 +1,2 @@
mockgen google.golang.org/grpc/examples/helloworld/helloworld GreeterClient > mock_helloworld/hw_mock.go
gofmt -w mock_helloworld/hw_mock.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file necessary? We already have the commands in the md file.
(And why do we need the gofmt here?

"github.com/golang/mock/gomock"
proto "github.com/golang/protobuf/proto"
"golang.org/x/net/context"
"google.golang.org/grpc/examples/helloworld/helloworld"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add alias for this import because it is a proto.

}

func TestSayHello(t *testing.T) {
ctrl := gomock.NewController(t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap this in a function createMock returning a mocking client?

@@ -0,0 +1,121 @@
# Mocking Service for gRPC

Example code: examples/helloworld/mock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a link here to the folder.
And a one line file summary?

mockGreeterClient.EXPECT().SayHello(
gomock.Any(), // expect any value for first parameter
gomock.Any(), // expect any value for second parameter
).Return(&helloworld.HelloReply{Message: “Mocked RPC”},nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a space before nil

@menghanl menghanl merged commit cbcceb2 into grpc:master Feb 14, 2017
@MakMukhi MakMukhi deleted the mmukhi_gomock_example branch May 4, 2018 02:07
@lock lock bot locked as resolved and limited conversation to collaborators Oct 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants