This repository has been archived by the owner on Mar 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a test for validating the RPC signature.
- Loading branch information
Showing
4 changed files
with
102 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include "gtest/gtest.h" | ||
|
||
// https://github.com/grpc/grpc/blob/master/examples/protos/helloworld.proto | ||
#include "examples/protos/helloworld.grpc.pb.h" | ||
|
||
// https://github.com/grpc/grpc/blob/master/examples/protos/keyvaluestore.proto | ||
#include "examples/protos/keyvaluestore.grpc.pb.h" | ||
|
||
#include "stout/grpc/server.h" | ||
|
||
using helloworld::HelloRequest; | ||
using helloworld::HelloReply; | ||
using helloworld::Greeter; | ||
|
||
using stout::grpc::ServerBuilder; | ||
using stout::grpc::Stream; | ||
|
||
|
||
TEST(GrpcTest, ServeValidate) | ||
{ | ||
ServerBuilder builder; | ||
|
||
builder.AddListeningPort("0.0.0.0:0", grpc::InsecureServerCredentials()); | ||
|
||
auto build = builder.BuildAndStart(); | ||
|
||
ASSERT_TRUE(build.status.ok()); | ||
|
||
auto server = std::move(build.server); | ||
|
||
ASSERT_TRUE(server); | ||
|
||
auto serve = server->Serve< | ||
keyvaluestore::Request, | ||
Stream<keyvaluestore::Response>>( | ||
"keyvaluestore.KeyValueStore.GetValues", | ||
[](auto&& call) {}); | ||
|
||
ASSERT_FALSE(serve.ok()); | ||
EXPECT_EQ("Method has streaming requests", serve.error()); | ||
|
||
serve = server->Serve< | ||
Stream<keyvaluestore::Request>, | ||
keyvaluestore::Response>( | ||
"keyvaluestore.KeyValueStore.GetValues", | ||
[](auto&& call) {}); | ||
|
||
ASSERT_FALSE(serve.ok()); | ||
EXPECT_EQ("Method has streaming responses", serve.error()); | ||
|
||
serve = server->Serve<Greeter, Stream<HelloRequest>, HelloReply>( | ||
"SayHello", | ||
[](auto&& call) {}); | ||
|
||
ASSERT_FALSE(serve.ok()); | ||
EXPECT_EQ("Method does not have streaming requests", serve.error()); | ||
|
||
serve = server->Serve<Greeter, HelloRequest, Stream<HelloReply>>( | ||
"SayHello", | ||
[](auto&& call) {}); | ||
|
||
ASSERT_FALSE(serve.ok()); | ||
EXPECT_EQ("Method does not have streaming responses", serve.error()); | ||
|
||
serve = server->Serve< | ||
Stream<HelloRequest>, | ||
Stream<keyvaluestore::Response>>( | ||
"keyvaluestore.KeyValueStore.GetValues", | ||
[](auto&& call) {}); | ||
|
||
ASSERT_FALSE(serve.ok()); | ||
EXPECT_EQ( | ||
"Method does not have requests of type helloworld.HelloRequest", | ||
serve.error()); | ||
|
||
serve = server->Serve< | ||
Stream<keyvaluestore::Request>, | ||
Stream<HelloReply>>( | ||
"keyvaluestore.KeyValueStore.GetValues", | ||
[](auto&& call) {}); | ||
|
||
ASSERT_FALSE(serve.ok()); | ||
EXPECT_EQ( | ||
"Method does not have responses of type helloworld.HelloReply", | ||
serve.error()); | ||
} |