Skip to content

Commit

Permalink
Move the helper for making urls with params to the test server.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasvl committed Nov 8, 2024
1 parent 2a315c5 commit 2a38f99
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
13 changes: 1 addition & 12 deletions UnitTests/GTMSessionFetcherFetchingTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions UnitTests/GTMSessionFetcherTestServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions UnitTests/GTMSessionFetcherTestServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 2a38f99

Please sign in to comment.