Allow configuring default service configs in grpc_cli

pull/23110/head
Alexander Polcyn 5 years ago
parent 6a2880a1ac
commit 0a452b9d19
  1. 3
      test/cpp/util/grpc_cli.cc
  2. 9
      test/cpp/util/grpc_tool.cc
  3. 23
      test/cpp/util/grpc_tool_test.cc

@ -51,6 +51,9 @@
--decode=grpc.testing.SimpleResponse \
src/proto/grpc/testing/messages.proto \
< output.bin > output.txt
10. --default_service_config, optional default service config to use
on the channel. Note that this may be ignored if the name resolver
returns a service config.
*/
#include <fstream>

@ -57,6 +57,11 @@ DEFINE_string(proto_path, ".", "Path to look for the proto file.");
DEFINE_string(protofiles, "", "Name of the proto file.");
DEFINE_bool(binary_input, false, "Input in binary format");
DEFINE_bool(binary_output, false, "Output in binary format");
DEFINE_string(
default_service_config, "",
"Default service config to use on the channel, if non-empty. Note "
"that this will be ignored if the name resolver returns a service "
"config.");
DEFINE_bool(json_input, false, "Input in json format");
DEFINE_bool(json_output, false, "Output in json format");
DEFINE_string(infile, "", "Input file (default is stdin)");
@ -217,6 +222,10 @@ std::shared_ptr<grpc::Channel> CreateCliChannel(
if (!cred.GetSslTargetNameOverride().empty()) {
args.SetSslTargetNameOverride(cred.GetSslTargetNameOverride());
}
if (!FLAGS_default_service_config.empty()) {
args.SetString(GRPC_ARG_SERVICE_CONFIG,
FLAGS_default_service_config.c_str());
}
return ::grpc::CreateCustomChannel(server_address, cred.GetCredentials(),
args);
}

@ -118,6 +118,7 @@ DECLARE_bool(batch);
DECLARE_string(metadata);
DECLARE_string(protofiles);
DECLARE_string(proto_path);
DECLARE_string(default_service_config);
namespace {
@ -1192,6 +1193,28 @@ TEST_F(GrpcToolTest, ListCommand_OverrideSslHostName) {
ShutdownServer();
}
TEST_F(GrpcToolTest, ConfiguringDefaultServiceConfig) {
// Test input "grpc_cli list localhost:<port>
// --default_service_config={\"loadBalancingConfig\":[{\"pick_first\":{}}]}"
std::stringstream output_stream;
const grpc::string server_address = SetUpServer();
const char* argv[] = {"grpc_cli", "ls", server_address.c_str()};
// 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.
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)));
FLAGS_default_service_config = "";
EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(),
"grpc.testing.EchoTestService\n"
"grpc.reflection.v1alpha.ServerReflection\n"));
ShutdownServer();
}
} // namespace testing
} // namespace grpc

Loading…
Cancel
Save