Make override hostname an argument for testing against prod gfe.

Change on 2014/12/19 by yangg <yangg@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=82544544
pull/1/merge
yangg 10 years ago committed by Jan Tattermusch
parent 59dfc90f57
commit 3f1af6ee2d
  1. 25
      test/cpp/util/create_test_channel.cc
  2. 4
      test/cpp/util/create_test_channel.h

@ -40,7 +40,16 @@
namespace grpc {
std::shared_ptr<ChannelInterface> CreateTestChannel(const grpc::string& server,
// When ssl is enabled, if server is empty, override_hostname is used to
// create channel. Otherwise, connect to server and override hostname if
// override_hostname is provided.
// When ssl is not enabled, override_hostname is ignored.
// Use examples:
// CreateTestChannel("1.1.1.1:12345", "override.hostname.com", true);
// CreateTestChannel("test.google.com:443", "", true);
// CreateTestChannel("", "test.google.com:443", true); // same as above
std::shared_ptr<ChannelInterface> CreateTestChannel(
const grpc::string& server, const grpc::string& override_hostname,
bool enable_ssl) {
ChannelArguments channel_args;
if (enable_ssl) {
@ -52,11 +61,21 @@ std::shared_ptr<ChannelInterface> CreateTestChannel(const grpc::string& server,
std::unique_ptr<Credentials> creds =
CredentialsFactory::SslCredentials(ssl_opts);
channel_args.SetSslTargetNameOverride("foo.test.google.com");
return CreateChannel(server, creds, channel_args);
if (!server.empty() && !override_hostname.empty()) {
channel_args.SetSslTargetNameOverride(override_hostname);
}
const grpc::string& connect_to =
server.empty() ? override_hostname : server;
return CreateChannel(connect_to, creds, channel_args);
} else {
return CreateChannel(server, channel_args);
}
}
// Shortcut for end2end and interop tests.
std::shared_ptr<ChannelInterface> CreateTestChannel(const grpc::string& server,
bool enable_ssl) {
return CreateTestChannel(server, "foo.test.google.com", enable_ssl);
}
} // namespace grpc

@ -41,6 +41,10 @@
namespace grpc {
class ChannelInterface;
std::shared_ptr<ChannelInterface> CreateTestChannel(
const grpc::string& server, const grpc::string& override_hostname,
bool enable_ssl);
std::shared_ptr<ChannelInterface> CreateTestChannel(const grpc::string& server,
bool enable_ssl);

Loading…
Cancel
Save