Add status_code_and_message interop test. (Does not yet work, because

the server does not yet support the response_status field.)
This commit is contained in:
Mark D. Roth
2016-06-30 14:57:30 -07:00
parent 714db19b0b
commit d7ac54924b
2 changed files with 44 additions and 1 deletions

View File

@ -70,7 +70,8 @@ var (
per_rpc_creds: large_unary with per rpc token;
oauth2_auth_token: large_unary with oauth2 token auth;
cancel_after_begin: cancellation after metadata has been sent but before payloads are sent;
cancel_after_first_response: cancellation after receiving 1st message from the server.`)
cancel_after_first_response: cancellation after receiving 1st message from the server;
status_code_and_message: status code propagated back to client.`)
// The test CA root cert file
testCAFile = "testdata/ca.pem"
@ -180,6 +181,9 @@ func main() {
case "cancel_after_first_response":
interop.DoCancelAfterFirstResponse(tc)
grpclog.Println("CancelAfterFirstResponse done")
case "status_code_and_message":
interop.DoStatusCodeAndMessage(tc)
grpclog.Println("StatusCodeAndMessage done")
default:
grpclog.Fatal("Unsupported test case: ", *testCase)
}

View File

@ -454,6 +454,45 @@ func DoCancelAfterFirstResponse(tc testpb.TestServiceClient) {
}
}
// DoStatusCodeAndMessage checks that the status code is propagated back to the client.
func DoStatusCodeAndMessage(tc testpb.TestServiceClient) {
// Test UnaryCall.
var code int32 = 2
msg := "test status message"
respStatus := &testpb.EchoStatus{
Code: &code,
Message: &msg,
}
req := &testpb.SimpleRequest{
ResponseStatus: respStatus,
}
_, err := tc.UnaryCall(context.Background(), req)
if grpc.Code(err) != 2 {
grpclog.Fatalf("/TestService/UnaryCall RPC compleled with error code %d, want %d", grpc.Code(err), code)
}
if err.Error() != msg {
grpclog.Fatal("/TestService/UnaryCall unexpected RPC error message: ", err)
}
// Test FullDuplexCall.
stream, err := tc.FullDuplexCall(context.Background())
if err != nil {
grpclog.Fatalf("%v.FullDuplexCall(_) = _, %v", tc, err)
}
stream_req := &testpb.StreamingOutputCallRequest{
ResponseStatus: respStatus,
}
if err := stream.Send(stream_req); err != nil {
grpclog.Fatalf("%v.Send(%v) = %v", stream, stream_req, err)
}
err = stream.CloseSend()
if grpc.Code(err) != 2 {
grpclog.Fatalf("%v compleled with error code %d, want %d", stream, grpc.Code(err), code)
}
if err.Error() != msg {
grpclog.Fatalf("%v unexpected RPC error message: %v", stream, err)
}
}
type testServer struct {
}