|
|
|
@ -85,6 +85,8 @@ DECLARE_bool(binary_input); |
|
|
|
|
DECLARE_bool(binary_output); |
|
|
|
|
DECLARE_bool(l); |
|
|
|
|
DECLARE_bool(batch); |
|
|
|
|
DECLARE_string(metadata); |
|
|
|
|
DECLARE_string(protofiles); |
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
@ -618,6 +620,8 @@ TEST_F(GrpcToolTest, ParseCommand) { |
|
|
|
|
// Expected output: ECHO_RESPONSE_MESSAGE
|
|
|
|
|
EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), ECHO_RESPONSE_MESSAGE)); |
|
|
|
|
|
|
|
|
|
FLAGS_binary_input = false; |
|
|
|
|
FLAGS_binary_output = false; |
|
|
|
|
ShutdownServer(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -652,6 +656,84 @@ TEST_F(GrpcToolTest, TooManyArguments) { |
|
|
|
|
EXPECT_TRUE(0 == output_stream.tellp()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(GrpcToolTest, CallCommandWithMetadata) { |
|
|
|
|
// Test input "grpc_cli call localhost:<port> Echo "message: 'Hello'"
|
|
|
|
|
const grpc::string server_address = SetUpServer(); |
|
|
|
|
const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "Echo", |
|
|
|
|
"message: 'Hello'"}; |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
std::stringstream output_stream; |
|
|
|
|
FLAGS_metadata = "key0:val0:key1:valq:key2:val2"; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, |
|
|
|
|
TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
// Expected output: "message: \"Hello\""
|
|
|
|
|
EXPECT_TRUE(nullptr != |
|
|
|
|
strstr(output_stream.str().c_str(), "message: \"Hello\"")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
std::stringstream output_stream; |
|
|
|
|
FLAGS_metadata = "key:val\\:val"; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, |
|
|
|
|
TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
// Expected output: "message: \"Hello\""
|
|
|
|
|
EXPECT_TRUE(nullptr != |
|
|
|
|
strstr(output_stream.str().c_str(), "message: \"Hello\"")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
std::stringstream output_stream; |
|
|
|
|
FLAGS_metadata = "key:val\\\\val"; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, |
|
|
|
|
TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
// Expected output: "message: \"Hello\""
|
|
|
|
|
EXPECT_TRUE(nullptr != |
|
|
|
|
strstr(output_stream.str().c_str(), "message: \"Hello\"")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
FLAGS_metadata = ""; |
|
|
|
|
ShutdownServer(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(GrpcToolTest, CallCommandWithBadMetadata) { |
|
|
|
|
// Test input "grpc_cli call localhost:10000 Echo "message: 'Hello'"
|
|
|
|
|
const char* argv[] = {"grpc_cli", "call", "localhost:10000", "Echo", |
|
|
|
|
"message: 'Hello'"}; |
|
|
|
|
FLAGS_protofiles = "src/proto/grpc/testing/echo.proto"; |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
std::stringstream output_stream; |
|
|
|
|
FLAGS_metadata = "key0:val0:key1"; |
|
|
|
|
// Exit with 1
|
|
|
|
|
EXPECT_EXIT( |
|
|
|
|
GrpcToolMainLib( |
|
|
|
|
ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, std::placeholders::_1)), |
|
|
|
|
::testing::ExitedWithCode(1), ".*Failed to parse metadata flag.*"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
std::stringstream output_stream; |
|
|
|
|
FLAGS_metadata = "key:val\\val"; |
|
|
|
|
// Exit with 1
|
|
|
|
|
EXPECT_EXIT( |
|
|
|
|
GrpcToolMainLib( |
|
|
|
|
ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, std::placeholders::_1)), |
|
|
|
|
::testing::ExitedWithCode(1), ".*Failed to parse metadata flag.*"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
FLAGS_metadata = ""; |
|
|
|
|
FLAGS_protofiles = ""; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace testing
|
|
|
|
|
} // namespace grpc
|
|
|
|
|
|
|
|
|
|