Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Enable custom httpbin URL with HTTPBIN_BASE_URL environment variable
Browse files Browse the repository at this point in the history
Editing the scheme and checking the `HTTPBIN_BASE_URL` box enables running the test suites on a default local installation of httpbin.
  • Loading branch information
0xced committed Oct 11, 2016
1 parent 0e947a7 commit 5d6867c
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldUseLaunchSchemeArgsEnv = "NO"
codeCoverageEnabled = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -54,6 +54,13 @@
ReferencedContainer = "container:AFNetworking.xcodeproj">
</BuildableReference>
</MacroExpansion>
<EnvironmentVariables>
<EnvironmentVariable
key = "HTTPBIN_BASE_URL"
value = "http://127.0.0.1:5000"
isEnabled = "NO">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldUseLaunchSchemeArgsEnv = "NO"
codeCoverageEnabled = "YES"
enableAddressSanitizer = "YES">
<Testables>
Expand Down Expand Up @@ -69,6 +69,18 @@
ReferencedContainer = "container:AFNetworking.xcodeproj">
</BuildableReference>
</MacroExpansion>
<EnvironmentVariables>
<EnvironmentVariable
key = "OS_ACTIVITY_MODE"
value = "disable"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "HTTPBIN_BASE_URL"
value = "http://127.0.0.1:5000"
isEnabled = "NO">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldUseLaunchSchemeArgsEnv = "NO"
enableAddressSanitizer = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -54,6 +54,18 @@
ReferencedContainer = "container:AFNetworking.xcodeproj">
</BuildableReference>
</MacroExpansion>
<EnvironmentVariables>
<EnvironmentVariable
key = "OS_ACTIVITY_MODE"
value = "disable"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "HTTPBIN_BASE_URL"
value = "http://127.0.0.1:5000"
isEnabled = "NO">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
<AdditionalOption
key = "NSZombieEnabled"
Expand Down
8 changes: 4 additions & 4 deletions Tests/Tests/AFJSONSerializationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ - (void)setUp {
- (void)testThatJSONRequestSerializationHandlesParametersDictionary {
NSDictionary *parameters = @{@"key":@"value"};
NSError *error = nil;
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:AFNetworkingTestsBaseURLString parameters:parameters error:&error];
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:self.baseURL.absoluteString parameters:parameters error:&error];

XCTAssertNil(error, @"Serialization error should be nil");

Expand All @@ -57,7 +57,7 @@ - (void)testThatJSONRequestSerializationHandlesParametersDictionary {
- (void)testThatJSONRequestSerializationHandlesParametersArray {
NSArray *parameters = @[@{@"key":@"value"}];
NSError *error = nil;
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:AFNetworkingTestsBaseURLString parameters:parameters error:&error];
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:self.baseURL.absoluteString parameters:parameters error:&error];

XCTAssertNil(error, @"Serialization error should be nil");

Expand All @@ -71,7 +71,7 @@ - (void)testThatJSONRequestSerializationHandlesInvalidParameters {

NSDictionary *parameters = @{@"key":string};
NSError *error = nil;
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:AFNetworkingTestsBaseURLString parameters:parameters error:&error];
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:self.baseURL.absoluteString parameters:parameters error:&error];

XCTAssertNil(request, @"Expected nil request.");
XCTAssertNotNil(error, @"Expected non-nil error.");
Expand All @@ -80,7 +80,7 @@ - (void)testThatJSONRequestSerializationHandlesInvalidParameters {
- (void)testThatJSONRequestSerializationErrorsWithInvalidJSON {
NSDictionary *parameters = @{@"key":[NSSet setWithObject:@"value"]};
NSError *error = nil;
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:AFNetworkingTestsBaseURLString parameters:parameters error:&error];
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:self.baseURL.absoluteString parameters:parameters error:&error];

XCTAssertNil(request, @"Request should be nil");
XCTAssertNotNil(error, @"Serialization error should be not nil");
Expand Down
4 changes: 2 additions & 2 deletions Tests/Tests/AFPropertyListRequestSerializerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ - (void)setUp {
- (void)testThatPropertyListRequestSerializerAcceptsPlist {
NSDictionary *parameters = @{@"key":@"value"};
NSError *error = nil;
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:AFNetworkingTestsBaseURLString parameters:parameters error:&error];
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:self.baseURL.absoluteString parameters:parameters error:&error];

XCTAssertNotNil(request, @"Expected non-nil request.");
}

- (void)testThatPropertyListRequestSerializerHandlesInvalidPlist {
NSDictionary *parameters = @{@42:@"value"};
NSError *error = nil;
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:AFNetworkingTestsBaseURLString parameters:parameters error:&error];
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:self.baseURL.absoluteString parameters:parameters error:&error];

XCTAssertNil(request, @"Expected nil request.");
XCTAssertNotNil(error, @"Expected non-nil error.");
Expand Down
2 changes: 0 additions & 2 deletions Tests/Tests/AFTestCase.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

#import <XCTest/XCTest.h>

extern NSString * const AFNetworkingTestsBaseURLString;

@interface AFTestCase : XCTestCase

@property (nonatomic, strong, readonly) NSURL *baseURL;
Expand Down
5 changes: 2 additions & 3 deletions Tests/Tests/AFTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

#import "AFTestCase.h"

NSString * const AFNetworkingTestsBaseURLString = @"https://httpbin.org/";

@implementation AFTestCase

- (void)setUp {
Expand All @@ -37,7 +35,8 @@ - (void)tearDown {
#pragma mark -

- (NSURL *)baseURL {
return [NSURL URLWithString:AFNetworkingTestsBaseURLString];
NSDictionary *environment = [[NSProcessInfo processInfo] environment];
return [NSURL URLWithString:environment[@"HTTPBIN_BASE_URL"] ?: @"https://httpbin.org"];
}

- (NSURL *)pngURL {
Expand Down

0 comments on commit 5d6867c

Please sign in to comment.