aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/tests/GRPCClientTests.m
diff options
context:
space:
mode:
authorGravatar Makarand Dharmapurikar <makarandd@google.com>2017-05-09 13:04:41 -0700
committerGravatar Makarand Dharmapurikar <makarandd@google.com>2017-05-09 13:04:41 -0700
commit716c7c52ba5da2b34241bf893496575a99c1c2f2 (patch)
tree9a0baf720144346ddccad47ae03e06f9fc6b97b9 /src/objective-c/tests/GRPCClientTests.m
parentd64a4bea823c85642e57b831fffdc34308bfcb93 (diff)
Added a binary trailer test
This test validates that ObjC client can receive binary data sent via grpc trailer.
Diffstat (limited to 'src/objective-c/tests/GRPCClientTests.m')
-rw-r--r--src/objective-c/tests/GRPCClientTests.m29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/objective-c/tests/GRPCClientTests.m b/src/objective-c/tests/GRPCClientTests.m
index e36f5c3ee9..deaaf17b07 100644
--- a/src/objective-c/tests/GRPCClientTests.m
+++ b/src/objective-c/tests/GRPCClientTests.m
@@ -293,6 +293,35 @@ static GRPCProtoMethod *kUnaryCallMethod;
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
}
+- (void)testTrailers {
+ __weak XCTestExpectation *response = [self expectationWithDescription:@"Empty response received."];
+ __weak XCTestExpectation *completion = [self expectationWithDescription:@"Empty RPC completed."];
+
+ GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
+ path:kEmptyCallMethod.HTTPPath
+ requestsWriter:[GRXWriter writerWithValue:[NSData data]]];
+ // Setting this special key in the header will cause the interop server to echo back the
+ // trailer data.
+ const unsigned char raw_bytes[] = {1,2,3,4};
+ NSData *trailer_data = [NSData dataWithBytes:raw_bytes length:sizeof(raw_bytes)];
+ call.requestHeaders[@"x-grpc-test-echo-trailing-bin"] = trailer_data;
+
+ id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+ XCTAssertNotNil(value, @"nil value received as response.");
+ XCTAssertEqual([value length], 0, @"Non-empty response received: %@", value);
+ [response fulfill];
+ } completionHandler:^(NSError *errorOrNil) {
+ XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil);
+ XCTAssertEqualObjects((NSData *)call.responseTrailers[@"x-grpc-test-echo-trailing-bin"],
+ trailer_data,
+ @"Did not receive expected trailer");
+ [completion fulfill];
+ }];
+
+ [call startWithWriteable:responsesWriteable];
+ [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
+}
+
// TODO(makarandd): Move to a different file that contains only unit tests
- (void)testExceptions {
// Try to set parameters to nil for GRPCCall. This should cause an exception