-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Conversation
…rpc-go into mmukhi_gomock_example
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
proto "github.com/golang/protobuf/proto" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
No description provided.