Skip to content

Commit 5a8c78e

Browse files
Fix test failures for emulator tests (#8044)
1 parent 898b9fb commit 5a8c78e

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

FirebaseStorage/Sources/FIRStorage.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ @interface FIRStorage () {
4343
/// Stored Auth reference, if it exists. This needs to be stored for `copyWithZone:`.
4444
id<FIRAuthInterop> _Nullable _auth;
4545
id<FIRAppCheckInterop> _Nullable _appCheck;
46+
BOOL _usesEmulator;
4647
NSTimeInterval _maxUploadRetryTime;
4748
NSTimeInterval _maxDownloadRetryTime;
4849
NSTimeInterval _maxOperationRetryTime;
@@ -333,6 +334,7 @@ - (void)useEmulatorWithHost:(NSString *)host port:(NSInteger)port {
333334
@"reference or trying to load data."];
334335
}
335336

337+
_usesEmulator = YES;
336338
_scheme = @"http";
337339
_host = host;
338340
_port = @(port);
@@ -360,6 +362,7 @@ - (void)ensureConfigured {
360362
bucket:_storageBucket
361363
auth:_auth
362364
appCheck:_appCheck];
365+
_fetcherServiceForApp.allowLocalhostRequest = _usesEmulator;
363366
}
364367
}
365368

FirebaseStorage/Tests/Unit/FIRStorageDeleteTests.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ - (void)testSuccessfulFetchWithEmulator {
108108
[self expectationWithDescription:@"testSuccessfulFetchWithEmulator"];
109109

110110
[self.storage useEmulatorWithHost:@"localhost" port:8080];
111+
self.fetcherService.allowLocalhostRequest = YES;
111112
self.fetcherService.testBlock =
112113
[FIRStorageTestHelpers successBlockWithURL:@"http://localhost:8080/v0/b/bucket/o/object"];
113114

@@ -117,7 +118,7 @@ - (void)testSuccessfulFetchWithEmulator {
117118
fetcherService:self.fetcherService
118119
dispatchQueue:self.dispatchQueue
119120
completion:^(NSError *error) {
120-
XCTAssertEqual(error, nil);
121+
XCTAssertNil(error);
121122
[expectation fulfill];
122123
}];
123124
[task enqueue];

FirebaseStorage/Tests/Unit/FIRStorageGetMetadataTests.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ - (void)testSuccessfulFetchWithEmulator {
116116
[self expectationWithDescription:@"testSuccessfulFetchWithEmulator"];
117117

118118
[self.storage useEmulatorWithHost:@"localhost" port:8080];
119+
self.fetcherService.allowLocalhostRequest = YES;
119120
self.fetcherService.testBlock =
120121
[FIRStorageTestHelpers successBlockWithURL:@"http://localhost:8080/v0/b/bucket/o/object"];
121122

@@ -126,6 +127,7 @@ - (void)testSuccessfulFetchWithEmulator {
126127
fetcherService:self.fetcherService
127128
dispatchQueue:self.dispatchQueue
128129
completion:^(FIRStorageMetadata *metadata, NSError *error) {
130+
XCTAssertNil(error);
129131
[expectation fulfill];
130132
}];
131133
[task enqueue];

FirebaseStorage/Tests/Unit/FIRStorageListTests.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ - (void)testDefaultListWithEmulator {
140140
XCTestExpectation *expectation = [self expectationWithDescription:@"testDefaultListWithEmulator"];
141141

142142
[self.storage useEmulatorWithHost:@"localhost" port:8080];
143+
self.fetcherService.allowLocalhostRequest = YES;
143144
self.fetcherService.testBlock = [FIRStorageTestHelpers
144145
successBlockWithURL:@"http://localhost:8080/v0/b/bucket/o?prefix=object/&delimiter=/"];
145146

@@ -151,6 +152,7 @@ - (void)testDefaultListWithEmulator {
151152
pageSize:nil
152153
previousPageToken:nil
153154
completion:^(FIRStorageListResult *result, NSError *error) {
155+
XCTAssertNil(error);
154156
[expectation fulfill];
155157
}];
156158
[task enqueue];

FirebaseStorage/Tests/Unit/FIRStorageTestHelpers.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ + (GTMSessionFetcherTestBlock)successBlockWithMetadata:(nullable FIRStorageMetad
9494
return [FIRStorageTestHelpers blockForData:data URL:nil statusCode:200];
9595
}
9696

97-
+ (GTMSessionFetcherTestBlock)successBlockWithURL:(NSString *)url;
98-
{ return [FIRStorageTestHelpers blockForData:nil URL:url statusCode:200]; }
97+
+ (GTMSessionFetcherTestBlock)successBlockWithURL:(NSString *)url {
98+
NSData *data = [@"{}" dataUsingEncoding:NSUTF8StringEncoding];
99+
return [FIRStorageTestHelpers blockForData:data URL:url statusCode:200];
100+
}
99101

100102
+ (GTMSessionFetcherTestBlock)unauthenticatedBlock {
101103
NSData *data = [kUnauthenticatedResponseString dataUsingEncoding:NSUTF8StringEncoding];

0 commit comments

Comments
 (0)