aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/util/create_test_channel.cc
diff options
context:
space:
mode:
authorGravatar yangg <yangg@google.com>2014-12-19 14:47:49 -0800
committerGravatar Jan Tattermusch <jtattermusch@google.com>2014-12-29 17:00:21 -0800
commit3f1af6ee2d5eb9898e9b21270f7fc1f5ee39b37a (patch)
treea33f790566f45b6ecacc0cc52bf492e1324a4e5a /test/cpp/util/create_test_channel.cc
parent59dfc90f578baedce8bbf8bb07e3e1a24ec1fb68 (diff)
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
Diffstat (limited to 'test/cpp/util/create_test_channel.cc')
-rw-r--r--test/cpp/util/create_test_channel.cc27
1 files changed, 23 insertions, 4 deletions
diff --git a/test/cpp/util/create_test_channel.cc b/test/cpp/util/create_test_channel.cc
index afac38abd3..14b566fb12 100644
--- a/test/cpp/util/create_test_channel.cc
+++ b/test/cpp/util/create_test_channel.cc
@@ -40,8 +40,17 @@
namespace grpc {
-std::shared_ptr<ChannelInterface> CreateTestChannel(const grpc::string& server,
- bool enable_ssl) {
+// 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) {
SslCredentialsOptions ssl_opts = {
@@ -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