-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from vsbogd/return-incorrect-nonce-error
Return incorrect nonce error
- Loading branch information
Showing
13 changed files
with
204 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//go:generate protoc grpc_test.proto --go_out=plugins=grpc:. | ||
|
||
package handler | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/suite" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
type GrpcTestSuite struct { | ||
suite.Suite | ||
} | ||
|
||
func (suite *GrpcTestSuite) SetupSuite() { | ||
} | ||
|
||
func (suite *GrpcTestSuite) TearDownSuite() { | ||
} | ||
|
||
func TestGrpcTestSuite(t *testing.T) { | ||
suite.Run(t, new(GrpcTestSuite)) | ||
} | ||
|
||
type exampleServiceMock struct { | ||
output *Output | ||
err error | ||
} | ||
|
||
func (service *exampleServiceMock) Ping(context context.Context, input *Input) (output *Output, err error) { | ||
return service.output, service.err | ||
} | ||
|
||
func startServiceAndClient(service ExampleServiceServer) (ExampleServiceClient, *grpc.ClientConn) { | ||
ch := make(chan int) | ||
go func() { | ||
listener, err := net.Listen("tcp", ":12345") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
server := grpc.NewServer() | ||
RegisterExampleServiceServer(server, service) | ||
|
||
ch <- 0 | ||
|
||
server.Serve(listener) | ||
}() | ||
|
||
_ = <-ch | ||
|
||
connection, err := grpc.Dial("localhost:12345", grpc.WithInsecure()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
client := NewExampleServiceClient(connection) | ||
|
||
return client, connection | ||
} | ||
|
||
func (suite *GrpcTestSuite) TestReturnCustomErrorCodeViaGrpc() { | ||
expectedErr := status.Newf(1000, "error message").Err() | ||
client, connection := startServiceAndClient(&exampleServiceMock{err: expectedErr}) | ||
defer connection.Close() | ||
|
||
_, err := client.Ping(context.Background(), &Input{Message: "ping"}) | ||
|
||
assert.Equal(suite.T(), err, expectedErr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
syntax = "proto3"; | ||
|
||
package handler; | ||
|
||
service ExampleService { | ||
rpc Ping(Input) returns (Output) {} | ||
} | ||
|
||
message Input { | ||
string message = 1; | ||
} | ||
|
||
message Output { | ||
string message = 1; | ||
} |
Oops, something went wrong.