From c2b3490fc5af4a9acd029014055b9614300a6408 Mon Sep 17 00:00:00 2001 From: Makarand Dharmapurikar Date: Fri, 26 Feb 2016 16:38:17 -0800 Subject: [PATCH 1/3] Added a test to verify user agent prefix can be set correctly. --- src/objective-c/tests/GRPCClientTests.m | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/objective-c/tests/GRPCClientTests.m b/src/objective-c/tests/GRPCClientTests.m index 9a3e5b5009b..d052f31a3d5 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 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 From c9dbf645e43515269b61b7337692afc037dbea5a Mon Sep 17 00:00:00 2001 From: Makarand Dharmapurikar Date: Fri, 26 Feb 2016 16:59:08 -0800 Subject: [PATCH 2/3] fixed indentation and removed unnecessary empty line --- src/objective-c/tests/GRPCClientTests.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/objective-c/tests/GRPCClientTests.m b/src/objective-c/tests/GRPCClientTests.m index d052f31a3d5..d6f1b8f232a 100644 --- a/src/objective-c/tests/GRPCClientTests.m +++ b/src/objective-c/tests/GRPCClientTests.m @@ -277,8 +277,7 @@ static ProtoMethod *kUnaryCallMethod; @"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]; + [response fulfill]; } completionHandler:^(NSError *errorOrNil) { XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil); [completion fulfill]; From f1588b5154c01b0282f36cde07f0a8fcdb84d2e2 Mon Sep 17 00:00:00 2001 From: Makarand Dharmapurikar Date: Fri, 26 Feb 2016 17:05:47 -0800 Subject: [PATCH 3/3] Another nit fix.. --- src/objective-c/tests/GRPCClientTests.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/objective-c/tests/GRPCClientTests.m b/src/objective-c/tests/GRPCClientTests.m index d6f1b8f232a..624958f4b97 100644 --- a/src/objective-c/tests/GRPCClientTests.m +++ b/src/objective-c/tests/GRPCClientTests.m @@ -274,9 +274,9 @@ static ProtoMethod *kUnaryCallMethod; 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"]); + @"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);