From 2a38f994f356cd0c008396b913cec5d5e9c3ab03 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Thu, 7 Nov 2024 15:01:21 -0500 Subject: [PATCH] Move the helper for making urls with params to the test server. --- UnitTests/GTMSessionFetcherFetchingTest.m | 13 +------------ UnitTests/GTMSessionFetcherTestServer.h | 1 + UnitTests/GTMSessionFetcherTestServer.m | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/UnitTests/GTMSessionFetcherFetchingTest.m b/UnitTests/GTMSessionFetcherFetchingTest.m index deba99c0..2aae8855 100644 --- a/UnitTests/GTMSessionFetcherFetchingTest.m +++ b/UnitTests/GTMSessionFetcherFetchingTest.m @@ -135,18 +135,7 @@ - (NSString *)localURLStringToTestFileName:(NSString *)name { } - (NSString *)localURLStringToTestFileName:(NSString *)name parameters:(NSDictionary *)params { - NSString *localURLString = [self localURLStringToTestFileName:name]; - - // Add any parameters from the dictionary. - if (params.count) { - NSMutableArray *array = [NSMutableArray array]; - for (NSString *key in params) { - [array addObject:[NSString stringWithFormat:@"%@=%@", key, - [[params objectForKey:key] description]]]; - } - NSString *paramsStr = [array componentsJoinedByString:@"&"]; - localURLString = [localURLString stringByAppendingFormat:@"?%@", paramsStr]; - } + NSString *localURLString = [[_testServer localURLForFile:name parameters:params] absoluteString]; return localURLString; } diff --git a/UnitTests/GTMSessionFetcherTestServer.h b/UnitTests/GTMSessionFetcherTestServer.h index 78f99c00..7987ee59 100644 --- a/UnitTests/GTMSessionFetcherTestServer.h +++ b/UnitTests/GTMSessionFetcherTestServer.h @@ -46,6 +46,7 @@ typedef enum { // Utilities for users. - (NSURL *)localURLForFile:(NSString *)name; // http://localhost:port/filename - (NSURL *)localv6URLForFile:(NSString *)name; // http://[::1]:port/filename +- (NSURL *)localURLForFile:(NSString *)name parameters:(NSDictionary *)params; - (NSData *)documentDataAtPath:(NSString *)requestPath; + (NSString *)JSONBodyStringForStatus:(NSInteger)code; diff --git a/UnitTests/GTMSessionFetcherTestServer.m b/UnitTests/GTMSessionFetcherTestServer.m index 20db57ab..cf90e8fa 100644 --- a/UnitTests/GTMSessionFetcherTestServer.m +++ b/UnitTests/GTMSessionFetcherTestServer.m @@ -231,6 +231,22 @@ - (NSURL *)localv6URLForFile:(NSString *)name { return [NSURL URLWithString:urlString]; } +- (NSURL *)localURLForFile:(NSString *)name parameters:(NSDictionary *)params { + NSURL *url = [self localURLForFile:name]; + if (!params.count) { + return url; + } + NSString *urlString = [url absoluteString]; + NSMutableArray *array = [NSMutableArray array]; + for (NSString *key in params) { + [array addObject:[NSString + stringWithFormat:@"%@=%@", key, [[params objectForKey:key] description]]]; + } + NSString *paramsStr = [array componentsJoinedByString:@"&"]; + urlString = [urlString stringByAppendingFormat:@"?%@", paramsStr]; + return [NSURL URLWithString:urlString]; +} + - (NSData *)documentDataAtPath:(NSString *)requestPath { if ([requestPath hasPrefix:@"/"]) { requestPath = [requestPath substringFromIndex:1];