|
|
|
@ -18,6 +18,7 @@ |
|
|
|
|
|
|
|
|
|
#include "test/cpp/util/grpc_tool.h" |
|
|
|
|
|
|
|
|
|
#include <gflags/gflags.h> |
|
|
|
|
#include <grpc/grpc.h> |
|
|
|
|
#include <grpc/support/alloc.h> |
|
|
|
|
#include <grpcpp/channel.h> |
|
|
|
@ -32,7 +33,6 @@ |
|
|
|
|
#include <chrono> |
|
|
|
|
#include <sstream> |
|
|
|
|
|
|
|
|
|
#include "absl/flags/flag.h" |
|
|
|
|
#include "src/core/lib/gpr/env.h" |
|
|
|
|
#include "src/core/lib/iomgr/load_file.h" |
|
|
|
|
#include "src/proto/grpc/testing/echo.grpc.pb.h" |
|
|
|
@ -110,22 +110,24 @@ using grpc::testing::EchoResponse; |
|
|
|
|
" }\n" \
|
|
|
|
|
"}\n\n" |
|
|
|
|
|
|
|
|
|
ABSL_DECLARE_FLAG(std::string, channel_creds_type); |
|
|
|
|
ABSL_DECLARE_FLAG(std::string, ssl_target); |
|
|
|
|
ABSL_DECLARE_FLAG(bool, binary_input); |
|
|
|
|
ABSL_DECLARE_FLAG(bool, binary_output); |
|
|
|
|
ABSL_DECLARE_FLAG(bool, json_input); |
|
|
|
|
ABSL_DECLARE_FLAG(bool, json_output); |
|
|
|
|
ABSL_DECLARE_FLAG(bool, l); |
|
|
|
|
ABSL_DECLARE_FLAG(bool, batch); |
|
|
|
|
ABSL_DECLARE_FLAG(std::string, metadata); |
|
|
|
|
ABSL_DECLARE_FLAG(std::string, protofiles); |
|
|
|
|
ABSL_DECLARE_FLAG(std::string, proto_path); |
|
|
|
|
ABSL_DECLARE_FLAG(std::string, default_service_config); |
|
|
|
|
ABSL_DECLARE_FLAG(double, timeout); |
|
|
|
|
DECLARE_string(channel_creds_type); |
|
|
|
|
DECLARE_string(ssl_target); |
|
|
|
|
|
|
|
|
|
namespace grpc { |
|
|
|
|
namespace testing { |
|
|
|
|
|
|
|
|
|
DECLARE_bool(binary_input); |
|
|
|
|
DECLARE_bool(binary_output); |
|
|
|
|
DECLARE_bool(json_input); |
|
|
|
|
DECLARE_bool(json_output); |
|
|
|
|
DECLARE_bool(l); |
|
|
|
|
DECLARE_bool(batch); |
|
|
|
|
DECLARE_string(metadata); |
|
|
|
|
DECLARE_string(protofiles); |
|
|
|
|
DECLARE_string(proto_path); |
|
|
|
|
DECLARE_string(default_service_config); |
|
|
|
|
DECLARE_double(timeout); |
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
const int kServerDefaultResponseStreamsToSend = 3; |
|
|
|
@ -202,8 +204,7 @@ class TestServiceImpl : public ::grpc::testing::EchoTestService::Service { |
|
|
|
|
|
|
|
|
|
// Returning string instead of bool to avoid using embedded messages in
|
|
|
|
|
// proto3
|
|
|
|
|
response->set_message( |
|
|
|
|
seconds.count() <= absl::GetFlag(FLAGS_timeout) ? "true" : "false"); |
|
|
|
|
response->set_message(seconds.count() <= FLAGS_timeout ? "true" : "false"); |
|
|
|
|
return Status::OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -371,7 +372,7 @@ TEST_F(GrpcToolTest, ListCommand) { |
|
|
|
|
const std::string server_address = SetUpServer(); |
|
|
|
|
const char* argv[] = {"grpc_cli", "ls", server_address.c_str()}; |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_l, false); |
|
|
|
|
FLAGS_l = false; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
@ -390,7 +391,7 @@ TEST_F(GrpcToolTest, ListOneService) { |
|
|
|
|
const char* argv[] = {"grpc_cli", "ls", server_address.c_str(), |
|
|
|
|
"grpc.testing.EchoTestService"}; |
|
|
|
|
// without -l flag
|
|
|
|
|
absl::SetFlag(&FLAGS_l, false); |
|
|
|
|
FLAGS_l = false; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
@ -401,7 +402,7 @@ TEST_F(GrpcToolTest, ListOneService) { |
|
|
|
|
// with -l flag
|
|
|
|
|
output_stream.str(std::string()); |
|
|
|
|
output_stream.clear(); |
|
|
|
|
absl::SetFlag(&FLAGS_l, true); |
|
|
|
|
FLAGS_l = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
@ -441,7 +442,7 @@ TEST_F(GrpcToolTest, ListOneMethod) { |
|
|
|
|
const char* argv[] = {"grpc_cli", "ls", server_address.c_str(), |
|
|
|
|
"grpc.testing.EchoTestService.Echo"}; |
|
|
|
|
// without -l flag
|
|
|
|
|
absl::SetFlag(&FLAGS_l, false); |
|
|
|
|
FLAGS_l = false; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
@ -451,7 +452,7 @@ TEST_F(GrpcToolTest, ListOneMethod) { |
|
|
|
|
// with -l flag
|
|
|
|
|
output_stream.str(std::string()); |
|
|
|
|
output_stream.clear(); |
|
|
|
|
absl::SetFlag(&FLAGS_l, true); |
|
|
|
|
FLAGS_l = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
@ -495,12 +496,11 @@ TEST_F(GrpcToolTest, CallCommand) { |
|
|
|
|
output_stream.str(std::string()); |
|
|
|
|
output_stream.clear(); |
|
|
|
|
|
|
|
|
|
// TODO(Capstan): Consider using absl::FlagSaver
|
|
|
|
|
absl::SetFlag(&FLAGS_json_output, true); |
|
|
|
|
FLAGS_json_output = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
absl::SetFlag(&FLAGS_json_output, false); |
|
|
|
|
FLAGS_json_output = false; |
|
|
|
|
|
|
|
|
|
// Expected output:
|
|
|
|
|
// {
|
|
|
|
@ -520,7 +520,7 @@ TEST_F(GrpcToolTest, CallCommandJsonInput) { |
|
|
|
|
const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "Echo", |
|
|
|
|
"{ \"message\": \"Hello\"}"}; |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_json_input, true); |
|
|
|
|
FLAGS_json_input = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
@ -532,12 +532,12 @@ TEST_F(GrpcToolTest, CallCommandJsonInput) { |
|
|
|
|
output_stream.str(std::string()); |
|
|
|
|
output_stream.clear(); |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_json_output, true); |
|
|
|
|
FLAGS_json_output = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
absl::SetFlag(&FLAGS_json_output, false); |
|
|
|
|
absl::SetFlag(&FLAGS_json_input, false); |
|
|
|
|
FLAGS_json_output = false; |
|
|
|
|
FLAGS_json_input = false; |
|
|
|
|
|
|
|
|
|
// Expected output:
|
|
|
|
|
// {
|
|
|
|
@ -562,11 +562,11 @@ TEST_F(GrpcToolTest, CallCommandBatch) { |
|
|
|
|
std::istringstream ss("message: 'Hello1'\n\n message: 'Hello2'\n\n"); |
|
|
|
|
std::cin.rdbuf(ss.rdbuf()); |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_batch, true); |
|
|
|
|
FLAGS_batch = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
absl::SetFlag(&FLAGS_batch, false); |
|
|
|
|
FLAGS_batch = false; |
|
|
|
|
|
|
|
|
|
// Expected output: "message: "Hello0"\nmessage: "Hello1"\nmessage:
|
|
|
|
|
// "Hello2"\n"
|
|
|
|
@ -580,13 +580,13 @@ TEST_F(GrpcToolTest, CallCommandBatch) { |
|
|
|
|
ss.seekg(0); |
|
|
|
|
std::cin.rdbuf(ss.rdbuf()); |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_batch, true); |
|
|
|
|
absl::SetFlag(&FLAGS_json_output, true); |
|
|
|
|
FLAGS_batch = true; |
|
|
|
|
FLAGS_json_output = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
absl::SetFlag(&FLAGS_json_output, false); |
|
|
|
|
absl::SetFlag(&FLAGS_batch, false); |
|
|
|
|
FLAGS_json_output = false; |
|
|
|
|
FLAGS_batch = false; |
|
|
|
|
|
|
|
|
|
// Expected output:
|
|
|
|
|
// {
|
|
|
|
@ -623,12 +623,12 @@ TEST_F(GrpcToolTest, CallCommandBatchJsonInput) { |
|
|
|
|
"{\"message\": \"Hello1\"}\n\n{\"message\": \"Hello2\" }\n\n"); |
|
|
|
|
std::cin.rdbuf(ss.rdbuf()); |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_json_input, true); |
|
|
|
|
absl::SetFlag(&FLAGS_batch, true); |
|
|
|
|
FLAGS_json_input = true; |
|
|
|
|
FLAGS_batch = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
absl::SetFlag(&FLAGS_batch, false); |
|
|
|
|
FLAGS_batch = false; |
|
|
|
|
|
|
|
|
|
// Expected output: "message: "Hello0"\nmessage: "Hello1"\nmessage:
|
|
|
|
|
// "Hello2"\n"
|
|
|
|
@ -642,14 +642,14 @@ TEST_F(GrpcToolTest, CallCommandBatchJsonInput) { |
|
|
|
|
ss.seekg(0); |
|
|
|
|
std::cin.rdbuf(ss.rdbuf()); |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_batch, true); |
|
|
|
|
absl::SetFlag(&FLAGS_json_output, true); |
|
|
|
|
FLAGS_batch = true; |
|
|
|
|
FLAGS_json_output = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
absl::SetFlag(&FLAGS_json_output, false); |
|
|
|
|
absl::SetFlag(&FLAGS_batch, false); |
|
|
|
|
absl::SetFlag(&FLAGS_json_input, false); |
|
|
|
|
FLAGS_json_output = false; |
|
|
|
|
FLAGS_batch = false; |
|
|
|
|
FLAGS_json_input = false; |
|
|
|
|
|
|
|
|
|
// Expected output:
|
|
|
|
|
// {
|
|
|
|
@ -685,11 +685,11 @@ TEST_F(GrpcToolTest, CallCommandBatchWithBadRequest) { |
|
|
|
|
std::istringstream ss("message: 1\n\n message: 'Hello2'\n\n"); |
|
|
|
|
std::cin.rdbuf(ss.rdbuf()); |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_batch, true); |
|
|
|
|
FLAGS_batch = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
absl::SetFlag(&FLAGS_batch, false); |
|
|
|
|
FLAGS_batch = false; |
|
|
|
|
|
|
|
|
|
// Expected output: "message: "Hello0"\nmessage: "Hello2"\n"
|
|
|
|
|
EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), |
|
|
|
@ -702,13 +702,13 @@ TEST_F(GrpcToolTest, CallCommandBatchWithBadRequest) { |
|
|
|
|
ss.seekg(0); |
|
|
|
|
std::cin.rdbuf(ss.rdbuf()); |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_batch, true); |
|
|
|
|
absl::SetFlag(&FLAGS_json_output, true); |
|
|
|
|
FLAGS_batch = true; |
|
|
|
|
FLAGS_json_output = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
absl::SetFlag(&FLAGS_json_output, false); |
|
|
|
|
absl::SetFlag(&FLAGS_batch, false); |
|
|
|
|
FLAGS_json_output = false; |
|
|
|
|
FLAGS_batch = false; |
|
|
|
|
|
|
|
|
|
// Expected output:
|
|
|
|
|
// {
|
|
|
|
@ -741,13 +741,13 @@ TEST_F(GrpcToolTest, CallCommandBatchJsonInputWithBadRequest) { |
|
|
|
|
"{ \"message\": 1 }\n\n { \"message\": \"Hello2\" }\n\n"); |
|
|
|
|
std::cin.rdbuf(ss.rdbuf()); |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_batch, true); |
|
|
|
|
absl::SetFlag(&FLAGS_json_input, true); |
|
|
|
|
FLAGS_batch = true; |
|
|
|
|
FLAGS_json_input = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
absl::SetFlag(&FLAGS_json_input, false); |
|
|
|
|
absl::SetFlag(&FLAGS_batch, false); |
|
|
|
|
FLAGS_json_input = false; |
|
|
|
|
FLAGS_batch = false; |
|
|
|
|
|
|
|
|
|
// Expected output: "message: "Hello0"\nmessage: "Hello2"\n"
|
|
|
|
|
EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), |
|
|
|
@ -760,15 +760,15 @@ TEST_F(GrpcToolTest, CallCommandBatchJsonInputWithBadRequest) { |
|
|
|
|
ss.seekg(0); |
|
|
|
|
std::cin.rdbuf(ss.rdbuf()); |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_batch, true); |
|
|
|
|
absl::SetFlag(&FLAGS_json_input, true); |
|
|
|
|
absl::SetFlag(&FLAGS_json_output, true); |
|
|
|
|
FLAGS_batch = true; |
|
|
|
|
FLAGS_json_input = true; |
|
|
|
|
FLAGS_json_output = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
absl::SetFlag(&FLAGS_json_output, false); |
|
|
|
|
absl::SetFlag(&FLAGS_json_input, false); |
|
|
|
|
absl::SetFlag(&FLAGS_batch, false); |
|
|
|
|
FLAGS_json_output = false; |
|
|
|
|
FLAGS_json_input = false; |
|
|
|
|
FLAGS_batch = false; |
|
|
|
|
|
|
|
|
|
// Expected output:
|
|
|
|
|
// {
|
|
|
|
@ -827,11 +827,11 @@ TEST_F(GrpcToolTest, CallCommandRequestStreamJsonInput) { |
|
|
|
|
"{ \"message\": \"Hello1\" }\n\n{ \"message\": \"Hello2\" }\n\n"); |
|
|
|
|
std::cin.rdbuf(ss.rdbuf()); |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_json_input, true); |
|
|
|
|
FLAGS_json_input = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
absl::SetFlag(&FLAGS_json_input, false); |
|
|
|
|
FLAGS_json_input = false; |
|
|
|
|
|
|
|
|
|
// Expected output: "message: \"Hello0Hello1Hello2\""
|
|
|
|
|
EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), |
|
|
|
@ -880,11 +880,11 @@ TEST_F(GrpcToolTest, CallCommandRequestStreamWithBadRequestJsonInput) { |
|
|
|
|
"{ \"bad_field\": \"Hello1\" }\n\n{ \"message\": \"Hello2\" }\n\n"); |
|
|
|
|
std::cin.rdbuf(ss.rdbuf()); |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_json_input, true); |
|
|
|
|
FLAGS_json_input = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
absl::SetFlag(&FLAGS_json_input, false); |
|
|
|
|
FLAGS_json_input = false; |
|
|
|
|
|
|
|
|
|
// Expected output: "message: \"Hello0Hello2\""
|
|
|
|
|
EXPECT_TRUE(nullptr != |
|
|
|
@ -902,7 +902,7 @@ TEST_F(GrpcToolTest, CallCommandWithTimeoutDeadlineSet) { |
|
|
|
|
"CheckDeadlineSet"}; |
|
|
|
|
|
|
|
|
|
// Set timeout to 5000.25 seconds
|
|
|
|
|
absl::SetFlag(&FLAGS_timeout, 5000.25); |
|
|
|
|
FLAGS_timeout = 5000.25; |
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
@ -923,7 +923,7 @@ TEST_F(GrpcToolTest, CallCommandWithTimeoutDeadlineUpperBound) { |
|
|
|
|
"CheckDeadlineUpperBound"}; |
|
|
|
|
|
|
|
|
|
// Set timeout to 900 seconds
|
|
|
|
|
absl::SetFlag(&FLAGS_timeout, 900); |
|
|
|
|
FLAGS_timeout = 900; |
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
@ -945,7 +945,7 @@ TEST_F(GrpcToolTest, CallCommandWithNegativeTimeoutValue) { |
|
|
|
|
"CheckDeadlineSet"}; |
|
|
|
|
|
|
|
|
|
// Set timeout to -5 (deadline not set)
|
|
|
|
|
absl::SetFlag(&FLAGS_timeout, -5); |
|
|
|
|
FLAGS_timeout = -5; |
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
@ -967,7 +967,7 @@ TEST_F(GrpcToolTest, CallCommandWithDefaultTimeoutValue) { |
|
|
|
|
"CheckDeadlineSet"}; |
|
|
|
|
|
|
|
|
|
// Set timeout to -1 (default value, deadline not set)
|
|
|
|
|
absl::SetFlag(&FLAGS_timeout, -1); |
|
|
|
|
FLAGS_timeout = -1; |
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
@ -1005,11 +1005,11 @@ TEST_F(GrpcToolTest, CallCommandResponseStream) { |
|
|
|
|
output_stream.str(std::string()); |
|
|
|
|
output_stream.clear(); |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_json_output, true); |
|
|
|
|
FLAGS_json_output = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
absl::SetFlag(&FLAGS_json_output, false); |
|
|
|
|
FLAGS_json_output = false; |
|
|
|
|
|
|
|
|
|
// Expected output: "{\n \"message\": \"Hello{n}\"\n}\n"
|
|
|
|
|
for (int i = 0; i < kServerDefaultResponseStreamsToSend; i++) { |
|
|
|
@ -1085,8 +1085,8 @@ TEST_F(GrpcToolTest, ParseCommand) { |
|
|
|
|
"grpc.testing.EchoResponse", |
|
|
|
|
ECHO_RESPONSE_MESSAGE_TEXT_FORMAT}; |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_binary_input, false); |
|
|
|
|
absl::SetFlag(&FLAGS_binary_output, false); |
|
|
|
|
FLAGS_binary_input = false; |
|
|
|
|
FLAGS_binary_output = false; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
@ -1098,11 +1098,11 @@ TEST_F(GrpcToolTest, ParseCommand) { |
|
|
|
|
output_stream.str(std::string()); |
|
|
|
|
output_stream.clear(); |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_json_output, true); |
|
|
|
|
FLAGS_json_output = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
absl::SetFlag(&FLAGS_json_output, false); |
|
|
|
|
FLAGS_json_output = false; |
|
|
|
|
|
|
|
|
|
// Expected output: ECHO_RESPONSE_MESSAGE_JSON_FORMAT
|
|
|
|
|
EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), |
|
|
|
@ -1111,7 +1111,7 @@ TEST_F(GrpcToolTest, ParseCommand) { |
|
|
|
|
// Parse text message to binary message and then parse it back to text message
|
|
|
|
|
output_stream.str(std::string()); |
|
|
|
|
output_stream.clear(); |
|
|
|
|
absl::SetFlag(&FLAGS_binary_output, true); |
|
|
|
|
FLAGS_binary_output = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
@ -1119,8 +1119,8 @@ TEST_F(GrpcToolTest, ParseCommand) { |
|
|
|
|
output_stream.str(std::string()); |
|
|
|
|
output_stream.clear(); |
|
|
|
|
argv[4] = binary_data.c_str(); |
|
|
|
|
absl::SetFlag(&FLAGS_binary_input, true); |
|
|
|
|
absl::SetFlag(&FLAGS_binary_output, false); |
|
|
|
|
FLAGS_binary_input = true; |
|
|
|
|
FLAGS_binary_output = false; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(5, argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
@ -1129,8 +1129,8 @@ TEST_F(GrpcToolTest, ParseCommand) { |
|
|
|
|
EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), |
|
|
|
|
ECHO_RESPONSE_MESSAGE_TEXT_FORMAT)); |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_binary_input, false); |
|
|
|
|
absl::SetFlag(&FLAGS_binary_output, false); |
|
|
|
|
FLAGS_binary_input = false; |
|
|
|
|
FLAGS_binary_output = false; |
|
|
|
|
ShutdownServer(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1145,7 +1145,7 @@ TEST_F(GrpcToolTest, ParseCommandJsonFormat) { |
|
|
|
|
"grpc.testing.EchoResponse", |
|
|
|
|
ECHO_RESPONSE_MESSAGE_JSON_FORMAT}; |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_json_input, true); |
|
|
|
|
FLAGS_json_input = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
@ -1158,12 +1158,12 @@ TEST_F(GrpcToolTest, ParseCommandJsonFormat) { |
|
|
|
|
output_stream.str(std::string()); |
|
|
|
|
output_stream.clear(); |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_json_output, true); |
|
|
|
|
FLAGS_json_output = true; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
absl::SetFlag(&FLAGS_json_output, false); |
|
|
|
|
absl::SetFlag(&FLAGS_json_input, false); |
|
|
|
|
FLAGS_json_output = false; |
|
|
|
|
FLAGS_json_input = false; |
|
|
|
|
|
|
|
|
|
// Expected output: ECHO_RESPONSE_MESSAGE_JSON_FORMAT
|
|
|
|
|
EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), |
|
|
|
@ -1211,7 +1211,7 @@ TEST_F(GrpcToolTest, CallCommandWithMetadata) { |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
std::stringstream output_stream; |
|
|
|
|
absl::SetFlag(&FLAGS_metadata, "key0:val0:key1:valq:key2:val2"); |
|
|
|
|
FLAGS_metadata = "key0:val0:key1:valq:key2:val2"; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, |
|
|
|
|
TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
@ -1223,7 +1223,7 @@ TEST_F(GrpcToolTest, CallCommandWithMetadata) { |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
std::stringstream output_stream; |
|
|
|
|
absl::SetFlag(&FLAGS_metadata, "key:val\\:val"); |
|
|
|
|
FLAGS_metadata = "key:val\\:val"; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, |
|
|
|
|
TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
@ -1235,7 +1235,7 @@ TEST_F(GrpcToolTest, CallCommandWithMetadata) { |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
std::stringstream output_stream; |
|
|
|
|
absl::SetFlag(&FLAGS_metadata, "key:val\\\\val"); |
|
|
|
|
FLAGS_metadata = "key:val\\\\val"; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, |
|
|
|
|
TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
@ -1245,7 +1245,7 @@ TEST_F(GrpcToolTest, CallCommandWithMetadata) { |
|
|
|
|
strstr(output_stream.str().c_str(), "message: \"Hello\"")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_metadata, ""); |
|
|
|
|
FLAGS_metadata = ""; |
|
|
|
|
ShutdownServer(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1254,16 +1254,15 @@ TEST_F(GrpcToolTest, CallCommandWithBadMetadata) { |
|
|
|
|
const char* argv[] = {"grpc_cli", "call", "localhost:10000", |
|
|
|
|
"grpc.testing.EchoTestService.Echo", |
|
|
|
|
"message: 'Hello'"}; |
|
|
|
|
absl::SetFlag(&FLAGS_protofiles, "src/proto/grpc/testing/echo.proto"); |
|
|
|
|
FLAGS_protofiles = "src/proto/grpc/testing/echo.proto"; |
|
|
|
|
char* test_srcdir = gpr_getenv("TEST_SRCDIR"); |
|
|
|
|
if (test_srcdir != nullptr) { |
|
|
|
|
absl::SetFlag(&FLAGS_proto_path, |
|
|
|
|
test_srcdir + std::string("/com_github_grpc_grpc")); |
|
|
|
|
FLAGS_proto_path = test_srcdir + std::string("/com_github_grpc_grpc"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
std::stringstream output_stream; |
|
|
|
|
absl::SetFlag(&FLAGS_metadata, "key0:val0:key1"); |
|
|
|
|
FLAGS_metadata = "key0:val0:key1"; |
|
|
|
|
// Exit with 1
|
|
|
|
|
EXPECT_EXIT( |
|
|
|
|
GrpcToolMainLib( |
|
|
|
@ -1274,7 +1273,7 @@ TEST_F(GrpcToolTest, CallCommandWithBadMetadata) { |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
std::stringstream output_stream; |
|
|
|
|
absl::SetFlag(&FLAGS_metadata, "key:val\\val"); |
|
|
|
|
FLAGS_metadata = "key:val\\val"; |
|
|
|
|
// Exit with 1
|
|
|
|
|
EXPECT_EXIT( |
|
|
|
|
GrpcToolMainLib( |
|
|
|
@ -1283,8 +1282,8 @@ TEST_F(GrpcToolTest, CallCommandWithBadMetadata) { |
|
|
|
|
::testing::ExitedWithCode(1), ".*Failed to parse metadata flag.*"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_metadata, ""); |
|
|
|
|
absl::SetFlag(&FLAGS_protofiles, ""); |
|
|
|
|
FLAGS_metadata = ""; |
|
|
|
|
FLAGS_protofiles = ""; |
|
|
|
|
|
|
|
|
|
gpr_free(test_srcdir); |
|
|
|
|
} |
|
|
|
@ -1296,9 +1295,9 @@ TEST_F(GrpcToolTest, ListCommand_OverrideSslHostName) { |
|
|
|
|
// --ssl_target=z.test.google.fr"
|
|
|
|
|
std::stringstream output_stream; |
|
|
|
|
const char* argv[] = {"grpc_cli", "ls", server_address.c_str()}; |
|
|
|
|
absl::SetFlag(&FLAGS_l, false); |
|
|
|
|
absl::SetFlag(&FLAGS_channel_creds_type, "ssl"); |
|
|
|
|
absl::SetFlag(&FLAGS_ssl_target, "z.test.google.fr"); |
|
|
|
|
FLAGS_l = false; |
|
|
|
|
FLAGS_channel_creds_type = "ssl"; |
|
|
|
|
FLAGS_ssl_target = "z.test.google.fr"; |
|
|
|
|
EXPECT_TRUE( |
|
|
|
|
0 == GrpcToolMainLib( |
|
|
|
|
ArraySize(argv), argv, TestCliCredentials(true), |
|
|
|
@ -1307,8 +1306,8 @@ TEST_F(GrpcToolTest, ListCommand_OverrideSslHostName) { |
|
|
|
|
"grpc.testing.EchoTestService\n" |
|
|
|
|
"grpc.reflection.v1alpha.ServerReflection\n")); |
|
|
|
|
|
|
|
|
|
absl::SetFlag(&FLAGS_channel_creds_type, ""); |
|
|
|
|
absl::SetFlag(&FLAGS_ssl_target, ""); |
|
|
|
|
FLAGS_channel_creds_type = ""; |
|
|
|
|
FLAGS_ssl_target = ""; |
|
|
|
|
ShutdownServer(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1321,13 +1320,13 @@ TEST_F(GrpcToolTest, ConfiguringDefaultServiceConfig) { |
|
|
|
|
// Just check that the tool is still operational when --default_service_config
|
|
|
|
|
// is configured. This particular service config is in reality redundant with
|
|
|
|
|
// the channel's default configuration.
|
|
|
|
|
absl::SetFlag(&FLAGS_l, false); |
|
|
|
|
absl::SetFlag(&FLAGS_default_service_config, |
|
|
|
|
"{\"loadBalancingConfig\":[{\"pick_first\":{}}]}"); |
|
|
|
|
FLAGS_l = false; |
|
|
|
|
FLAGS_default_service_config = |
|
|
|
|
"{\"loadBalancingConfig\":[{\"pick_first\":{}}]}"; |
|
|
|
|
EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), |
|
|
|
|
std::bind(PrintStream, &output_stream, |
|
|
|
|
std::placeholders::_1))); |
|
|
|
|
absl::SetFlag(&FLAGS_default_service_config, ""); |
|
|
|
|
FLAGS_default_service_config = ""; |
|
|
|
|
EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), |
|
|
|
|
"grpc.testing.EchoTestService\n" |
|
|
|
|
"grpc.reflection.v1alpha.ServerReflection\n")); |
|
|
|
|