diff options
author | yang-g <yangg@google.com> | 2015-07-09 12:32:48 -0700 |
---|---|---|
committer | yang-g <yangg@google.com> | 2015-07-09 12:32:48 -0700 |
commit | 3315a845efaf2116cce6184b459f8bb4e642bdde (patch) | |
tree | 47ca40731d6f9ba689a060f1734738769ed4d35e /test/cpp/end2end | |
parent | f9e8e59b1c113b614736b89cb2cb4e543ba82d9f (diff) | |
parent | 494886a1be23865af7eb223b1a190fb9d2e2cc30 (diff) |
Merge remote-tracking branch 'upstream/master' into security_context2
Diffstat (limited to 'test/cpp/end2end')
-rw-r--r-- | test/cpp/end2end/end2end_test.cc | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 60af84100a..0912b19243 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -98,12 +98,16 @@ void CheckAuthContext(T* context) { class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { public: - TestServiceImpl() : signal_client_(false) {} + TestServiceImpl() : signal_client_(false), host_(nullptr) {} + explicit TestServiceImpl(const grpc::string& host) : signal_client_(false), host_(new grpc::string(host)) {} Status Echo(ServerContext* context, const EchoRequest* request, EchoResponse* response) GRPC_OVERRIDE { response->set_message(request->message()); MaybeEchoDeadline(context, request, response); + if (host_) { + response->mutable_param()->set_host(*host_); + } if (request->has_param() && request->param().client_cancel_after_us()) { { std::unique_lock<std::mutex> lock(mu_); @@ -205,6 +209,7 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { private: bool signal_client_; std::mutex mu_; + std::unique_ptr<grpc::string> host_; }; class TestServiceImplDupPkg @@ -219,7 +224,7 @@ class TestServiceImplDupPkg class End2endTest : public ::testing::Test { protected: - End2endTest() : kMaxMessageSize_(8192), thread_pool_(2) {} + End2endTest() : kMaxMessageSize_(8192), special_service_("special"), thread_pool_(2) {} void SetUp() GRPC_OVERRIDE { int port = grpc_pick_unused_port_or_die(); @@ -229,6 +234,7 @@ class End2endTest : public ::testing::Test { builder.AddListeningPort(server_address_.str(), FakeTransportSecurityServerCredentials()); builder.RegisterService(&service_); + builder.RegisterService("special", &special_service_); builder.SetMaxMessageSize( kMaxMessageSize_); // For testing max message size. builder.RegisterService(&dup_pkg_service_); @@ -250,6 +256,7 @@ class End2endTest : public ::testing::Test { std::ostringstream server_address_; const int kMaxMessageSize_; TestServiceImpl service_; + TestServiceImpl special_service_; TestServiceImplDupPkg dup_pkg_service_; ThreadPool thread_pool_; }; @@ -268,6 +275,22 @@ static void SendRpc(grpc::cpp::test::util::TestService::Stub* stub, } } +TEST_F(End2endTest, SimpleRpcWithHost) { + ResetStub(); + + EchoRequest request; + EchoResponse response; + request.set_message("Hello"); + + ClientContext context; + context.set_authority("special"); + Status s = stub_->Echo(&context, request, &response); + EXPECT_EQ(response.message(), request.message()); + EXPECT_TRUE(response.has_param()); + EXPECT_EQ(response.param().host(), "special"); + EXPECT_TRUE(s.ok()); +} + TEST_F(End2endTest, SimpleRpc) { ResetStub(); SendRpc(stub_.get(), 1); |