diff options
author | Abhishek Kumar <abhikumar@google.com> | 2015-08-05 11:04:45 -0700 |
---|---|---|
committer | Abhishek Kumar <abhikumar@google.com> | 2015-08-05 11:04:45 -0700 |
commit | e1c867dbee903353ac7b701776429b236837f7f0 (patch) | |
tree | c9c70d928808f7a03ef1466c717ee019edcab90e /test/cpp | |
parent | 65b074925161a2ff28447ebac4b311cab80c37ae (diff) |
Added interop test for status_code_with_message
Diffstat (limited to 'test/cpp')
-rw-r--r-- | test/cpp/interop/client.cc | 6 | ||||
-rw-r--r-- | test/cpp/interop/interop_client.cc | 19 | ||||
-rw-r--r-- | test/cpp/interop/interop_client.h | 1 | ||||
-rw-r--r-- | test/cpp/interop/server.cc | 7 |
4 files changed, 32 insertions, 1 deletions
diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index d0393fafb2..ebc5cfc85a 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -70,6 +70,7 @@ DEFINE_string(test_case, "large_unary", "jwt_token_creds: large_unary with JWT token auth; " "oauth2_auth_token: raw oauth2 access token auth; " "per_rpc_creds: raw oauth2 access token on a single rpc; " + "status_code_and_message: verify status code & message; " "all : all of above."); DEFINE_string(default_service_account, "", "Email of GCE default service account"); @@ -82,7 +83,7 @@ using grpc::testing::GetServiceAccountJsonKey; int main(int argc, char** argv) { grpc::testing::InitTest(&argc, &argv, true); - + gpr_log(GPR_INFO, "Testing these cases: %s", FLAGS_test_case.c_str()); int ret = 0; grpc::testing::InteropClient client( CreateChannelForTestCase(FLAGS_test_case)); @@ -121,6 +122,8 @@ int main(int argc, char** argv) { } else if (FLAGS_test_case == "per_rpc_creds") { grpc::string json_key = GetServiceAccountJsonKey(); client.DoPerRpcCreds(json_key, FLAGS_oauth_scope); + } else if (FLAGS_test_case == "status_code_and_message") { + client.DoStatusWithMessage(); } else if (FLAGS_test_case == "all") { client.DoEmpty(); client.DoLargeUnary(); @@ -131,6 +134,7 @@ int main(int argc, char** argv) { client.DoCancelAfterBegin(); client.DoCancelAfterFirstResponse(); client.DoTimeoutOnSleepingServer(); + client.DoStatusWithMessage(); // service_account_creds and jwt_token_creds can only run with ssl. if (FLAGS_enable_ssl) { grpc::string json_key = GetServiceAccountJsonKey(); diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index e5c0e4631f..dfb90fadc2 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -423,5 +423,24 @@ void InteropClient::DoTimeoutOnSleepingServer() { gpr_log(GPR_INFO, "Pingpong streaming timeout done."); } +void InteropClient::DoStatusWithMessage() { + gpr_log(GPR_INFO, "Sending RPC with a request for status code 2 and message"); + std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel_)); + + ClientContext context; + SimpleRequest request; + SimpleResponse response; + EchoStatus *requested_status = request.mutable_response_status(); + requested_status->set_code(grpc::StatusCode::UNKNOWN); + grpc::string test_msg = "This is a test message"; + requested_status->set_message(test_msg); + + Status s = stub->UnaryCall(&context, request, &response); + + GPR_ASSERT(s.error_code() == grpc::StatusCode::UNKNOWN); + GPR_ASSERT(s.error_message() == test_msg); + gpr_log(GPR_INFO, "Done testing Status and Message"); +} + } // namespace testing } // namespace grpc diff --git a/test/cpp/interop/interop_client.h b/test/cpp/interop/interop_client.h index bf8188325e..6e26c49e5d 100644 --- a/test/cpp/interop/interop_client.h +++ b/test/cpp/interop/interop_client.h @@ -60,6 +60,7 @@ class InteropClient { void DoCancelAfterBegin(); void DoCancelAfterFirstResponse(); void DoTimeoutOnSleepingServer(); + void DoStatusWithMessage(); // Auth tests. // username is a string containing the user email void DoJwtTokenCreds(const grpc::string& username); diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server.cc index db87872cf5..05a10de51e 100644 --- a/test/cpp/interop/server.cc +++ b/test/cpp/interop/server.cc @@ -105,6 +105,13 @@ class TestServiceImpl : public TestService::Service { return Status(grpc::StatusCode::INTERNAL, "Error creating payload."); } } + + if (request->has_response_status()) { + return Status(static_cast<grpc::StatusCode> + (request->response_status().code()), + request->response_status().message()); + } + return Status::OK; } |