aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Makarand Dharmapurikar <makarandd@google.com>2016-02-26 16:38:17 -0800
committerGravatar Makarand Dharmapurikar <makarandd@google.com>2016-02-26 16:38:17 -0800
commitc2b3490fc5af4a9acd029014055b9614300a6408 (patch)
treec54896b6a18212439d45aeac5f438f2f5a87a3d0 /src
parentf7806b766bf88d2173ef37a4205d1393bbd73d60 (diff)
Added a test to verify user agent prefix can be set correctly.
Diffstat (limited to 'src')
-rw-r--r--src/objective-c/tests/GRPCClientTests.m32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/objective-c/tests/GRPCClientTests.m b/src/objective-c/tests/GRPCClientTests.m
index 9a3e5b5009..d052f31a3d 100644
--- a/src/objective-c/tests/GRPCClientTests.m
+++ b/src/objective-c/tests/GRPCClientTests.m
@@ -103,6 +103,8 @@ static ProtoMethod *kUnaryCallMethod;
@implementation GRPCClientTests
- (void)setUp {
+ // Add a custom user agent prefix that will be used in test
+ [GRPCCall setUserAgentPrefix:@"Foo" forHost:kHostAddress];
// Register test server as non-SSL.
[GRPCCall useInsecureConnectionsForHost:kHostAddress];
@@ -257,6 +259,36 @@ static ProtoMethod *kUnaryCallMethod;
[self waitForExpectationsWithTimeout:8 handler:nil];
}
+- (void)testUserAgentPrefix {
+ __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
+ // user-agent value, which we confirm.
+ call.requestHeaders[@"x-grpc-test-echo-useragent"] = @"";
+
+ id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+ XCTAssertNotNil(value, @"nil value received as response.");
+ XCTAssertEqual([value length], 0, @"Non-empty response received: %@", value);
+ XCTAssertEqualObjects(call.responseHeaders[@"x-grpc-test-echo-useragent"],
+ @"Foo grpc-objc/0.13.0 grpc-c/0.14.0-dev (ios)",
+ @"Did not receive expected user agent %@",
+ call.responseHeaders[@"x-grpc-test-echo-useragent"]);
+
+ [response fulfill];
+ } completionHandler:^(NSError *errorOrNil) {
+ XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil);
+ [completion fulfill];
+ }];
+
+ [call startWithWriteable:responsesWriteable];
+
+ [self waitForExpectationsWithTimeout:8 handler:nil];
+}
+
// TODO(makarandd): Move to a different file that contains only unit tests
- (void)testExceptions {
// Try to set userAgentPrefix for host that is nil. This should cause