diff options
author | Yuchen Zeng <zyc@google.com> | 2016-09-21 14:10:47 -0700 |
---|---|---|
committer | Yuchen Zeng <zyc@google.com> | 2016-09-21 14:10:47 -0700 |
commit | 24129f010cb2b9ebccb44b4e0486d89aff7a74ae (patch) | |
tree | 6fe3d15f4b12ad79f96fa022aab6adccf0c16fea /test/cpp/util/grpc_tool_test.cc | |
parent | 2579bf394175637e44e9696959deac9d3c867c8e (diff) | |
parent | d53957cf4e3924d2abd201fa60ba1e2ae9ba2526 (diff) |
Merge remote-tracking branch 'upstream/master' into cli_list
Diffstat (limited to 'test/cpp/util/grpc_tool_test.cc')
-rw-r--r-- | test/cpp/util/grpc_tool_test.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/cpp/util/grpc_tool_test.cc b/test/cpp/util/grpc_tool_test.cc index 32ac093ec8..bad1579f11 100644 --- a/test/cpp/util/grpc_tool_test.cc +++ b/test/cpp/util/grpc_tool_test.cc @@ -154,6 +154,14 @@ class GrpcToolTest : public ::testing::Test { void ShutdownServer() { server_->Shutdown(); } + void ExitWhenError(int argc, const char** argv, const CliCredentials& cred, + GrpcToolOutputCallback callback) { + int result = GrpcToolMainLib(argc, argv, cred, callback); + if (result) { + exit(result); + } + } + std::unique_ptr<Server> server_; TestServiceImpl service_; reflection::ProtoServerReflectionPlugin plugin_; @@ -248,6 +256,27 @@ TEST_F(GrpcToolTest, ListOneService) { ShutdownServer(); } +TEST_F(GrpcToolTest, TypeCommand) { + // Test input "grpc_cli type localhost:<port> grpc.testing.EchoRequest" + std::stringstream output_stream; + + const grpc::string server_address = SetUpServer(); + const char* argv[] = {"grpc_cli", "type", server_address.c_str(), + "grpc.testing.EchoRequest"}; + + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + const grpc::protobuf::Descriptor* desc = + grpc::protobuf::DescriptorPool::generated_pool()->FindMessageTypeByName( + "grpc.testing.EchoRequest"); + // Expected output: the DebugString of grpc.testing.EchoRequest + EXPECT_TRUE(0 == + strcmp(output_stream.str().c_str(), desc->DebugString().c_str())); + + ShutdownServer(); +} + TEST_F(GrpcToolTest, ListOneMethod) { // Test input "grpc_cli list localhost:<port> grpc.testing.EchoTestService" std::stringstream output_stream; @@ -277,6 +306,22 @@ TEST_F(GrpcToolTest, ListOneMethod) { ShutdownServer(); } +TEST_F(GrpcToolTest, TypeNotFound) { + // Test input "grpc_cli type localhost:<port> grpc.testing.DummyRequest" + std::stringstream output_stream; + + const grpc::string server_address = SetUpServer(); + const char* argv[] = {"grpc_cli", "type", server_address.c_str(), + "grpc.testing.DummyRequest"}; + + EXPECT_DEATH(ExitWhenError(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1)), + ".*Type grpc.testing.DummyRequest not found.*"); + + ShutdownServer(); +} + TEST_F(GrpcToolTest, CallCommand) { // Test input "grpc_cli call localhost:<port> Echo "message: 'Hello'" std::stringstream output_stream; |