diff options
author | neksard <neksard@yandex-team.ru> | 2022-02-10 16:45:33 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:33 +0300 |
commit | 1d9c550e7c38e051d7961f576013a482003a70d9 (patch) | |
tree | b2cc84ee7850122e7ccf51d0ea21e4fa7e7a5685 /contrib/libs/grpc/test/cpp/util/grpc_tool_test.cc | |
parent | 8f7cf138264e0caa318144bf8a2c950e0b0a8593 (diff) | |
download | ydb-1d9c550e7c38e051d7961f576013a482003a70d9.tar.gz |
Restoring authorship annotation for <neksard@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/grpc/test/cpp/util/grpc_tool_test.cc')
-rw-r--r-- | contrib/libs/grpc/test/cpp/util/grpc_tool_test.cc | 836 |
1 files changed, 418 insertions, 418 deletions
diff --git a/contrib/libs/grpc/test/cpp/util/grpc_tool_test.cc b/contrib/libs/grpc/test/cpp/util/grpc_tool_test.cc index 1b217226cd..ff610daadd 100644 --- a/contrib/libs/grpc/test/cpp/util/grpc_tool_test.cc +++ b/contrib/libs/grpc/test/cpp/util/grpc_tool_test.cc @@ -57,7 +57,7 @@ using grpc::testing::EchoResponse; "Echo2\n" \ "CheckDeadlineUpperBound\n" \ "CheckDeadlineSet\n" \ - "CheckClientInitialMetadata\n" \ + "CheckClientInitialMetadata\n" \ "RequestStream\n" \ "ResponseStream\n" \ "BidiStream\n" \ @@ -94,32 +94,32 @@ using grpc::testing::EchoResponse; " rpc Echo(grpc.testing.EchoRequest) returns (grpc.testing.EchoResponse) " \ "{}\n" -#define ECHO_RESPONSE_MESSAGE_TEXT_FORMAT \ - "message: \"echo\"\n" \ - "param {\n" \ - " host: \"localhost\"\n" \ - " peer: \"peer\"\n" \ +#define ECHO_RESPONSE_MESSAGE_TEXT_FORMAT \ + "message: \"echo\"\n" \ + "param {\n" \ + " host: \"localhost\"\n" \ + " peer: \"peer\"\n" \ "}\n\n" -#define ECHO_RESPONSE_MESSAGE_JSON_FORMAT \ - "{\n" \ - " \"message\": \"echo\",\n" \ - " \"param\": {\n" \ - " \"host\": \"localhost\",\n" \ - " \"peer\": \"peer\"\n" \ - " }\n" \ - "}\n\n" - -DECLARE_string(channel_creds_type); -DECLARE_string(ssl_target); - +#define ECHO_RESPONSE_MESSAGE_JSON_FORMAT \ + "{\n" \ + " \"message\": \"echo\",\n" \ + " \"param\": {\n" \ + " \"host\": \"localhost\",\n" \ + " \"peer\": \"peer\"\n" \ + " }\n" \ + "}\n\n" + +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(json_input); +DECLARE_bool(json_output); DECLARE_bool(l); DECLARE_bool(batch); DECLARE_string(metadata); @@ -134,27 +134,27 @@ const int kServerDefaultResponseStreamsToSend = 3; class TestCliCredentials final : public grpc::testing::CliCredentials { public: - TestCliCredentials(bool secure = false) : secure_(secure) {} - std::shared_ptr<grpc::ChannelCredentials> GetChannelCredentials() - const override { - if (!secure_) { - return InsecureChannelCredentials(); - } + TestCliCredentials(bool secure = false) : secure_(secure) {} + std::shared_ptr<grpc::ChannelCredentials> GetChannelCredentials() + const override { + if (!secure_) { + return InsecureChannelCredentials(); + } grpc_slice ca_slice; GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file", grpc_load_file(CA_CERT_PATH, 1, &ca_slice))); const char* test_root_cert = reinterpret_cast<const char*> GRPC_SLICE_START_PTR(ca_slice); - SslCredentialsOptions ssl_opts = {test_root_cert, "", ""}; + SslCredentialsOptions ssl_opts = {test_root_cert, "", ""}; std::shared_ptr<grpc::ChannelCredentials> credential_ptr = grpc::SslCredentials(grpc::SslCredentialsOptions(ssl_opts)); grpc_slice_unref(ca_slice); return credential_ptr; } const TString GetCredentialUsage() const override { return ""; } - - private: - const bool secure_; + + private: + const bool secure_; }; bool PrintStream(std::stringstream* ss, const TString& output) { @@ -289,7 +289,7 @@ class GrpcToolTest : public ::testing::Test { server_address << "localhost:" << port; // Setup server ServerBuilder builder; - std::shared_ptr<grpc::ServerCredentials> creds; + std::shared_ptr<grpc::ServerCredentials> creds; grpc_slice cert_slice, key_slice; GPR_ASSERT(GRPC_LOG_IF_ERROR( "load_file", grpc_load_file(SERVER_CERT_PATH, 1, &cert_slice))); @@ -301,15 +301,15 @@ class GrpcToolTest : public ::testing::Test { reinterpret_cast<const char*> GRPC_SLICE_START_PTR(key_slice); SslServerCredentialsOptions::PemKeyCertPair pkcp = {server_key, server_cert}; - if (secure) { - SslServerCredentialsOptions ssl_opts; - ssl_opts.pem_root_certs = ""; - ssl_opts.pem_key_cert_pairs.push_back(pkcp); - creds = SslServerCredentials(ssl_opts); - } else { - creds = InsecureServerCredentials(); - } - builder.AddListeningPort(server_address.str(), creds); + if (secure) { + SslServerCredentialsOptions ssl_opts; + ssl_opts.pem_root_certs = ""; + ssl_opts.pem_key_cert_pairs.push_back(pkcp); + creds = SslServerCredentials(ssl_opts); + } else { + creds = InsecureServerCredentials(); + } + builder.AddListeningPort(server_address.str(), creds); builder.RegisterService(&service_); server_ = builder.BuildAndStart(); grpc_slice_unref(cert_slice); @@ -491,64 +491,64 @@ TEST_F(GrpcToolTest, CallCommand) { // Expected output: "message: \"Hello\"" EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), "message: \"Hello\"")); - - // with json_output + + // with json_output output_stream.str(TString()); - output_stream.clear(); - - FLAGS_json_output = true; - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - FLAGS_json_output = false; - - // Expected output: - // { - // "message": "Hello" - // } - EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), - "{\n \"message\": \"Hello\"\n}")); - + output_stream.clear(); + + FLAGS_json_output = true; + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + FLAGS_json_output = false; + + // Expected output: + // { + // "message": "Hello" + // } + EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), + "{\n \"message\": \"Hello\"\n}")); + ShutdownServer(); } -TEST_F(GrpcToolTest, CallCommandJsonInput) { - // Test input "grpc_cli call localhost:<port> Echo "{ \"message\": \"Hello\"}" - std::stringstream output_stream; - +TEST_F(GrpcToolTest, CallCommandJsonInput) { + // Test input "grpc_cli call localhost:<port> Echo "{ \"message\": \"Hello\"}" + std::stringstream output_stream; + const TString server_address = SetUpServer(); - const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "Echo", - "{ \"message\": \"Hello\"}"}; - - FLAGS_json_input = true; - 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\"")); - - // with json_output + const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "Echo", + "{ \"message\": \"Hello\"}"}; + + FLAGS_json_input = true; + 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\"")); + + // with json_output output_stream.str(TString()); - output_stream.clear(); - - FLAGS_json_output = true; - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - FLAGS_json_output = false; - FLAGS_json_input = false; - - // Expected output: - // { - // "message": "Hello" - // } - EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), - "{\n \"message\": \"Hello\"\n}")); - - ShutdownServer(); -} - + output_stream.clear(); + + FLAGS_json_output = true; + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + FLAGS_json_output = false; + FLAGS_json_input = false; + + // Expected output: + // { + // "message": "Hello" + // } + EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), + "{\n \"message\": \"Hello\"\n}")); + + ShutdownServer(); +} + TEST_F(GrpcToolTest, CallCommandBatch) { // Test input "grpc_cli call Echo" std::stringstream output_stream; @@ -573,105 +573,105 @@ TEST_F(GrpcToolTest, CallCommandBatch) { EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), "message: \"Hello0\"\nmessage: " "\"Hello1\"\nmessage: \"Hello2\"\n")); - // with json_output + // with json_output output_stream.str(TString()); - output_stream.clear(); - ss.clear(); - ss.seekg(0); - std::cin.rdbuf(ss.rdbuf()); - - FLAGS_batch = true; - FLAGS_json_output = true; - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - FLAGS_json_output = false; - FLAGS_batch = false; - - // Expected output: - // { - // "message": "Hello0" - // } - // { - // "message": "Hello1" - // } - // { - // "message": "Hello2" - // } - // Expected output: "message: "Hello0"\nmessage: "Hello1"\nmessage: - // "Hello2"\n" - EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), - "{\n \"message\": \"Hello0\"\n}\n" - "{\n \"message\": \"Hello1\"\n}\n" - "{\n \"message\": \"Hello2\"\n}\n")); - + output_stream.clear(); + ss.clear(); + ss.seekg(0); + std::cin.rdbuf(ss.rdbuf()); + + FLAGS_batch = true; + FLAGS_json_output = true; + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + FLAGS_json_output = false; + FLAGS_batch = false; + + // Expected output: + // { + // "message": "Hello0" + // } + // { + // "message": "Hello1" + // } + // { + // "message": "Hello2" + // } + // Expected output: "message: "Hello0"\nmessage: "Hello1"\nmessage: + // "Hello2"\n" + EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), + "{\n \"message\": \"Hello0\"\n}\n" + "{\n \"message\": \"Hello1\"\n}\n" + "{\n \"message\": \"Hello2\"\n}\n")); + std::cin.rdbuf(orig); ShutdownServer(); } -TEST_F(GrpcToolTest, CallCommandBatchJsonInput) { - // Test input "grpc_cli call Echo" - std::stringstream output_stream; - +TEST_F(GrpcToolTest, CallCommandBatchJsonInput) { + // Test input "grpc_cli call Echo" + std::stringstream output_stream; + const TString server_address = SetUpServer(); - const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "Echo", - "{\"message\": \"Hello0\"}"}; - - // Mock std::cin input "message: 'Hello1'\n\n message: 'Hello2'\n\n" - std::streambuf* orig = std::cin.rdbuf(); - std::istringstream ss( - "{\"message\": \"Hello1\"}\n\n{\"message\": \"Hello2\" }\n\n"); - std::cin.rdbuf(ss.rdbuf()); - - FLAGS_json_input = true; - FLAGS_batch = true; - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - FLAGS_batch = false; - - // Expected output: "message: "Hello0"\nmessage: "Hello1"\nmessage: - // "Hello2"\n" - EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), - "message: \"Hello0\"\nmessage: " - "\"Hello1\"\nmessage: \"Hello2\"\n")); - // with json_output + const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "Echo", + "{\"message\": \"Hello0\"}"}; + + // Mock std::cin input "message: 'Hello1'\n\n message: 'Hello2'\n\n" + std::streambuf* orig = std::cin.rdbuf(); + std::istringstream ss( + "{\"message\": \"Hello1\"}\n\n{\"message\": \"Hello2\" }\n\n"); + std::cin.rdbuf(ss.rdbuf()); + + FLAGS_json_input = true; + FLAGS_batch = true; + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + FLAGS_batch = false; + + // Expected output: "message: "Hello0"\nmessage: "Hello1"\nmessage: + // "Hello2"\n" + EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), + "message: \"Hello0\"\nmessage: " + "\"Hello1\"\nmessage: \"Hello2\"\n")); + // with json_output output_stream.str(TString()); - output_stream.clear(); - ss.clear(); - ss.seekg(0); - std::cin.rdbuf(ss.rdbuf()); - - FLAGS_batch = true; - FLAGS_json_output = true; - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - FLAGS_json_output = false; - FLAGS_batch = false; - FLAGS_json_input = false; - - // Expected output: - // { - // "message": "Hello0" - // } - // { - // "message": "Hello1" - // } - // { - // "message": "Hello2" - // } - // Expected output: "message: "Hello0"\nmessage: "Hello1"\nmessage: - // "Hello2"\n" - EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), - "{\n \"message\": \"Hello0\"\n}\n" - "{\n \"message\": \"Hello1\"\n}\n" - "{\n \"message\": \"Hello2\"\n}\n")); - - std::cin.rdbuf(orig); - ShutdownServer(); -} - + output_stream.clear(); + ss.clear(); + ss.seekg(0); + std::cin.rdbuf(ss.rdbuf()); + + FLAGS_batch = true; + FLAGS_json_output = true; + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + FLAGS_json_output = false; + FLAGS_batch = false; + FLAGS_json_input = false; + + // Expected output: + // { + // "message": "Hello0" + // } + // { + // "message": "Hello1" + // } + // { + // "message": "Hello2" + // } + // Expected output: "message: "Hello0"\nmessage: "Hello1"\nmessage: + // "Hello2"\n" + EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), + "{\n \"message\": \"Hello0\"\n}\n" + "{\n \"message\": \"Hello1\"\n}\n" + "{\n \"message\": \"Hello2\"\n}\n")); + + std::cin.rdbuf(orig); + ShutdownServer(); +} + TEST_F(GrpcToolTest, CallCommandBatchWithBadRequest) { // Test input "grpc_cli call Echo" std::stringstream output_stream; @@ -694,99 +694,99 @@ TEST_F(GrpcToolTest, CallCommandBatchWithBadRequest) { // Expected output: "message: "Hello0"\nmessage: "Hello2"\n" EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), "message: \"Hello0\"\nmessage: \"Hello2\"\n")); - - // with json_output + + // with json_output output_stream.str(TString()); - output_stream.clear(); - ss.clear(); - ss.seekg(0); - std::cin.rdbuf(ss.rdbuf()); - - FLAGS_batch = true; - FLAGS_json_output = true; - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - FLAGS_json_output = false; - FLAGS_batch = false; - - // Expected output: - // { - // "message": "Hello0" - // } - // { - // "message": "Hello2" - // } - // Expected output: "message: "Hello0"\nmessage: "Hello1"\nmessage: - // "Hello2"\n" - EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), - "{\n \"message\": \"Hello0\"\n}\n" - "{\n \"message\": \"Hello2\"\n}\n")); - + output_stream.clear(); + ss.clear(); + ss.seekg(0); + std::cin.rdbuf(ss.rdbuf()); + + FLAGS_batch = true; + FLAGS_json_output = true; + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + FLAGS_json_output = false; + FLAGS_batch = false; + + // Expected output: + // { + // "message": "Hello0" + // } + // { + // "message": "Hello2" + // } + // Expected output: "message: "Hello0"\nmessage: "Hello1"\nmessage: + // "Hello2"\n" + EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), + "{\n \"message\": \"Hello0\"\n}\n" + "{\n \"message\": \"Hello2\"\n}\n")); + std::cin.rdbuf(orig); ShutdownServer(); } -TEST_F(GrpcToolTest, CallCommandBatchJsonInputWithBadRequest) { - // Test input "grpc_cli call Echo" - std::stringstream output_stream; - +TEST_F(GrpcToolTest, CallCommandBatchJsonInputWithBadRequest) { + // Test input "grpc_cli call Echo" + std::stringstream output_stream; + const TString server_address = SetUpServer(); - const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "Echo", - "{ \"message\": \"Hello0\"}"}; - - // Mock std::cin input "message: 1\n\n message: 'Hello2'\n\n" - std::streambuf* orig = std::cin.rdbuf(); - std::istringstream ss( - "{ \"message\": 1 }\n\n { \"message\": \"Hello2\" }\n\n"); - std::cin.rdbuf(ss.rdbuf()); - - FLAGS_batch = true; - FLAGS_json_input = true; - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - FLAGS_json_input = false; - FLAGS_batch = false; - - // Expected output: "message: "Hello0"\nmessage: "Hello2"\n" - EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), - "message: \"Hello0\"\nmessage: \"Hello2\"\n")); - - // with json_output + const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "Echo", + "{ \"message\": \"Hello0\"}"}; + + // Mock std::cin input "message: 1\n\n message: 'Hello2'\n\n" + std::streambuf* orig = std::cin.rdbuf(); + std::istringstream ss( + "{ \"message\": 1 }\n\n { \"message\": \"Hello2\" }\n\n"); + std::cin.rdbuf(ss.rdbuf()); + + FLAGS_batch = true; + FLAGS_json_input = true; + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + FLAGS_json_input = false; + FLAGS_batch = false; + + // Expected output: "message: "Hello0"\nmessage: "Hello2"\n" + EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), + "message: \"Hello0\"\nmessage: \"Hello2\"\n")); + + // with json_output output_stream.str(TString()); - output_stream.clear(); - ss.clear(); - ss.seekg(0); - std::cin.rdbuf(ss.rdbuf()); - - 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))); - FLAGS_json_output = false; - FLAGS_json_input = false; - FLAGS_batch = false; - - // Expected output: - // { - // "message": "Hello0" - // } - // { - // "message": "Hello2" - // } - // Expected output: "message: "Hello0"\nmessage: "Hello1"\nmessage: - // "Hello2"\n" - EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), - "{\n \"message\": \"Hello0\"\n}\n" - "{\n \"message\": \"Hello2\"\n}\n")); - - std::cin.rdbuf(orig); - ShutdownServer(); -} - + output_stream.clear(); + ss.clear(); + ss.seekg(0); + std::cin.rdbuf(ss.rdbuf()); + + 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))); + FLAGS_json_output = false; + FLAGS_json_input = false; + FLAGS_batch = false; + + // Expected output: + // { + // "message": "Hello0" + // } + // { + // "message": "Hello2" + // } + // Expected output: "message: "Hello0"\nmessage: "Hello1"\nmessage: + // "Hello2"\n" + EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), + "{\n \"message\": \"Hello0\"\n}\n" + "{\n \"message\": \"Hello2\"\n}\n")); + + std::cin.rdbuf(orig); + ShutdownServer(); +} + TEST_F(GrpcToolTest, CallCommandRequestStream) { // Test input: grpc_cli call localhost:<port> RequestStream "message: // 'Hello0'" @@ -812,34 +812,34 @@ TEST_F(GrpcToolTest, CallCommandRequestStream) { ShutdownServer(); } -TEST_F(GrpcToolTest, CallCommandRequestStreamJsonInput) { - // Test input: grpc_cli call localhost:<port> RequestStream "{ \"message\": - // \"Hello0\"}" - std::stringstream output_stream; - +TEST_F(GrpcToolTest, CallCommandRequestStreamJsonInput) { + // Test input: grpc_cli call localhost:<port> RequestStream "{ \"message\": + // \"Hello0\"}" + std::stringstream output_stream; + const TString server_address = SetUpServer(); - const char* argv[] = {"grpc_cli", "call", server_address.c_str(), - "RequestStream", "{ \"message\": \"Hello0\" }"}; - - // Mock std::cin input "message: 'Hello1'\n\n message: 'Hello2'\n\n" - std::streambuf* orig = std::cin.rdbuf(); - std::istringstream ss( - "{ \"message\": \"Hello1\" }\n\n{ \"message\": \"Hello2\" }\n\n"); - std::cin.rdbuf(ss.rdbuf()); - - FLAGS_json_input = true; - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - FLAGS_json_input = false; - - // Expected output: "message: \"Hello0Hello1Hello2\"" - EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), - "message: \"Hello0Hello1Hello2\"")); - std::cin.rdbuf(orig); - ShutdownServer(); -} - + const char* argv[] = {"grpc_cli", "call", server_address.c_str(), + "RequestStream", "{ \"message\": \"Hello0\" }"}; + + // Mock std::cin input "message: 'Hello1'\n\n message: 'Hello2'\n\n" + std::streambuf* orig = std::cin.rdbuf(); + std::istringstream ss( + "{ \"message\": \"Hello1\" }\n\n{ \"message\": \"Hello2\" }\n\n"); + std::cin.rdbuf(ss.rdbuf()); + + FLAGS_json_input = true; + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + FLAGS_json_input = false; + + // Expected output: "message: \"Hello0Hello1Hello2\"" + EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), + "message: \"Hello0Hello1Hello2\"")); + std::cin.rdbuf(orig); + ShutdownServer(); +} + TEST_F(GrpcToolTest, CallCommandRequestStreamWithBadRequest) { // Test input: grpc_cli call localhost:<port> RequestStream "message: // 'Hello0'" @@ -865,34 +865,34 @@ TEST_F(GrpcToolTest, CallCommandRequestStreamWithBadRequest) { ShutdownServer(); } -TEST_F(GrpcToolTest, CallCommandRequestStreamWithBadRequestJsonInput) { - // Test input: grpc_cli call localhost:<port> RequestStream "message: - // 'Hello0'" - std::stringstream output_stream; - +TEST_F(GrpcToolTest, CallCommandRequestStreamWithBadRequestJsonInput) { + // Test input: grpc_cli call localhost:<port> RequestStream "message: + // 'Hello0'" + std::stringstream output_stream; + const TString server_address = SetUpServer(); - const char* argv[] = {"grpc_cli", "call", server_address.c_str(), - "RequestStream", "{ \"message\": \"Hello0\" }"}; - - // Mock std::cin input "bad_field: 'Hello1'\n\n message: 'Hello2'\n\n" - std::streambuf* orig = std::cin.rdbuf(); - std::istringstream ss( - "{ \"bad_field\": \"Hello1\" }\n\n{ \"message\": \"Hello2\" }\n\n"); - std::cin.rdbuf(ss.rdbuf()); - - FLAGS_json_input = true; - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - FLAGS_json_input = false; - - // Expected output: "message: \"Hello0Hello2\"" - EXPECT_TRUE(nullptr != - strstr(output_stream.str().c_str(), "message: \"Hello0Hello2\"")); - std::cin.rdbuf(orig); - ShutdownServer(); -} - + const char* argv[] = {"grpc_cli", "call", server_address.c_str(), + "RequestStream", "{ \"message\": \"Hello0\" }"}; + + // Mock std::cin input "bad_field: 'Hello1'\n\n message: 'Hello2'\n\n" + std::streambuf* orig = std::cin.rdbuf(); + std::istringstream ss( + "{ \"bad_field\": \"Hello1\" }\n\n{ \"message\": \"Hello2\" }\n\n"); + std::cin.rdbuf(ss.rdbuf()); + + FLAGS_json_input = true; + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + FLAGS_json_input = false; + + // Expected output: "message: \"Hello0Hello2\"" + EXPECT_TRUE(nullptr != + strstr(output_stream.str().c_str(), "message: \"Hello0Hello2\"")); + std::cin.rdbuf(orig); + ShutdownServer(); +} + TEST_F(GrpcToolTest, CallCommandWithTimeoutDeadlineSet) { // Test input "grpc_cli call CheckDeadlineSet --timeout=5000.25" std::stringstream output_stream; @@ -1001,24 +1001,24 @@ TEST_F(GrpcToolTest, CallCommandResponseStream) { expected_response_text.c_str())); } - // with json_output + // with json_output output_stream.str(TString()); - output_stream.clear(); - - FLAGS_json_output = true; - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - FLAGS_json_output = false; - - // Expected output: "{\n \"message\": \"Hello{n}\"\n}\n" - for (int i = 0; i < kServerDefaultResponseStreamsToSend; i++) { + output_stream.clear(); + + FLAGS_json_output = true; + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + FLAGS_json_output = false; + + // Expected output: "{\n \"message\": \"Hello{n}\"\n}\n" + for (int i = 0; i < kServerDefaultResponseStreamsToSend; i++) { TString expected_response_text = "{\n \"message\": \"Hello" + ToString(i) + "\"\n}\n"; - EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), - expected_response_text.c_str())); - } - + EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), + expected_response_text.c_str())); + } + ShutdownServer(); } @@ -1082,32 +1082,32 @@ TEST_F(GrpcToolTest, ParseCommand) { const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "parse", server_address.c_str(), - "grpc.testing.EchoResponse", - ECHO_RESPONSE_MESSAGE_TEXT_FORMAT}; + "grpc.testing.EchoResponse", + ECHO_RESPONSE_MESSAGE_TEXT_FORMAT}; FLAGS_binary_input = false; FLAGS_binary_output = false; EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), std::bind(PrintStream, &output_stream, std::placeholders::_1))); - // Expected output: ECHO_RESPONSE_MESSAGE_TEXT_FORMAT - EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), - ECHO_RESPONSE_MESSAGE_TEXT_FORMAT)); + // Expected output: ECHO_RESPONSE_MESSAGE_TEXT_FORMAT + EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), + ECHO_RESPONSE_MESSAGE_TEXT_FORMAT)); - // with json_output + // with json_output output_stream.str(TString()); - output_stream.clear(); - - FLAGS_json_output = true; - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - FLAGS_json_output = false; - - // Expected output: ECHO_RESPONSE_MESSAGE_JSON_FORMAT - EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), - ECHO_RESPONSE_MESSAGE_JSON_FORMAT)); - + output_stream.clear(); + + FLAGS_json_output = true; + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + FLAGS_json_output = false; + + // Expected output: ECHO_RESPONSE_MESSAGE_JSON_FORMAT + EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), + ECHO_RESPONSE_MESSAGE_JSON_FORMAT)); + // Parse text message to binary message and then parse it back to text message output_stream.str(TString()); output_stream.clear(); @@ -1126,52 +1126,52 @@ TEST_F(GrpcToolTest, ParseCommand) { std::placeholders::_1))); // Expected output: ECHO_RESPONSE_MESSAGE - EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), - ECHO_RESPONSE_MESSAGE_TEXT_FORMAT)); + EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), + ECHO_RESPONSE_MESSAGE_TEXT_FORMAT)); FLAGS_binary_input = false; FLAGS_binary_output = false; ShutdownServer(); } -TEST_F(GrpcToolTest, ParseCommandJsonFormat) { - // Test input "grpc_cli parse localhost:<port> grpc.testing.EchoResponse - // ECHO_RESPONSE_MESSAGE_JSON_FORMAT" - std::stringstream output_stream; - std::stringstream binary_output_stream; - +TEST_F(GrpcToolTest, ParseCommandJsonFormat) { + // Test input "grpc_cli parse localhost:<port> grpc.testing.EchoResponse + // ECHO_RESPONSE_MESSAGE_JSON_FORMAT" + std::stringstream output_stream; + std::stringstream binary_output_stream; + const TString server_address = SetUpServer(); - const char* argv[] = {"grpc_cli", "parse", server_address.c_str(), - "grpc.testing.EchoResponse", - ECHO_RESPONSE_MESSAGE_JSON_FORMAT}; - - FLAGS_json_input = true; - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - - // Expected output: ECHO_RESPONSE_MESSAGE_TEXT_FORMAT - EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), - ECHO_RESPONSE_MESSAGE_TEXT_FORMAT)); - - // with json_output + const char* argv[] = {"grpc_cli", "parse", server_address.c_str(), + "grpc.testing.EchoResponse", + ECHO_RESPONSE_MESSAGE_JSON_FORMAT}; + + FLAGS_json_input = true; + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + + // Expected output: ECHO_RESPONSE_MESSAGE_TEXT_FORMAT + EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), + ECHO_RESPONSE_MESSAGE_TEXT_FORMAT)); + + // with json_output output_stream.str(TString()); - output_stream.clear(); - - FLAGS_json_output = true; - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - FLAGS_json_output = false; - FLAGS_json_input = false; - - // Expected output: ECHO_RESPONSE_MESSAGE_JSON_FORMAT - EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), - ECHO_RESPONSE_MESSAGE_JSON_FORMAT)); - - ShutdownServer(); -} - + output_stream.clear(); + + FLAGS_json_output = true; + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + FLAGS_json_output = false; + FLAGS_json_input = false; + + // Expected output: ECHO_RESPONSE_MESSAGE_JSON_FORMAT + EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), + ECHO_RESPONSE_MESSAGE_JSON_FORMAT)); + + ShutdownServer(); +} + TEST_F(GrpcToolTest, TooFewArguments) { // Test input "grpc_cli call Echo" std::stringstream output_stream; @@ -1288,29 +1288,29 @@ TEST_F(GrpcToolTest, CallCommandWithBadMetadata) { gpr_free(test_srcdir); } -TEST_F(GrpcToolTest, ListCommand_OverrideSslHostName) { +TEST_F(GrpcToolTest, ListCommand_OverrideSslHostName) { const TString server_address = SetUpServer(true); - - // Test input "grpc_cli ls localhost:<port> --channel_creds_type=ssl - // --ssl_target=z.test.google.fr" - std::stringstream output_stream; - const char* argv[] = {"grpc_cli", "ls", server_address.c_str()}; - FLAGS_l = false; - FLAGS_channel_creds_type = "ssl"; - FLAGS_ssl_target = "z.test.google.fr"; - EXPECT_TRUE( - 0 == GrpcToolMainLib( - ArraySize(argv), argv, TestCliCredentials(true), - std::bind(PrintStream, &output_stream, std::placeholders::_1))); - EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), - "grpc.testing.EchoTestService\n" - "grpc.reflection.v1alpha.ServerReflection\n")); - - FLAGS_channel_creds_type = ""; - FLAGS_ssl_target = ""; - ShutdownServer(); -} - + + // Test input "grpc_cli ls localhost:<port> --channel_creds_type=ssl + // --ssl_target=z.test.google.fr" + std::stringstream output_stream; + const char* argv[] = {"grpc_cli", "ls", server_address.c_str()}; + FLAGS_l = false; + FLAGS_channel_creds_type = "ssl"; + FLAGS_ssl_target = "z.test.google.fr"; + EXPECT_TRUE( + 0 == GrpcToolMainLib( + ArraySize(argv), argv, TestCliCredentials(true), + std::bind(PrintStream, &output_stream, std::placeholders::_1))); + EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), + "grpc.testing.EchoTestService\n" + "grpc.reflection.v1alpha.ServerReflection\n")); + + FLAGS_channel_creds_type = ""; + FLAGS_ssl_target = ""; + ShutdownServer(); +} + TEST_F(GrpcToolTest, ConfiguringDefaultServiceConfig) { // Test input "grpc_cli list localhost:<port> // --default_service_config={\"loadBalancingConfig\":[{\"pick_first\":{}}]}" @@ -1337,7 +1337,7 @@ TEST_F(GrpcToolTest, ConfiguringDefaultServiceConfig) { } // namespace grpc int main(int argc, char** argv) { - grpc::testing::TestEnvironment env(argc, argv); + grpc::testing::TestEnvironment env(argc, argv); ::testing::InitGoogleTest(&argc, argv); ::testing::FLAGS_gtest_death_test_style = "threadsafe"; return RUN_ALL_TESTS(); |