@@ -49,13 +49,21 @@ import XCTest
49
49
let result = try await ref. putDataAsync ( data)
50
50
XCTAssertNotNil ( result)
51
51
_ = try await ref. delete ( )
52
+ // Next delete should fail and verify the first delete succeeded.
53
+ do {
54
+ _ = try await ref. delete ( )
55
+ } catch {
56
+ XCTAssertEqual ( ( error as NSError ) . code, StorageErrorCode . objectNotFound. rawValue)
57
+ }
52
58
}
53
59
54
- func testDeleteWithNilCompletion ( ) async throws {
60
+ func testDeleteAfterPut ( ) async throws {
55
61
let ref = storage. reference ( withPath: " ios/public/fileToDelete " )
56
62
let data = try XCTUnwrap ( " Hello Swift World " . data ( using: . utf8) , " Data construction failed " )
57
63
let result = try await ref. putDataAsync ( data)
58
64
XCTAssertNotNil ( result)
65
+ let result2 : Void = try await ref. delete ( )
66
+ XCTAssertNotNil ( result2)
59
67
}
60
68
61
69
func testSimplePutData( ) async throws {
@@ -67,14 +75,15 @@ import XCTest
67
75
68
76
func testSimplePutSpecialCharacter( ) async throws {
69
77
let ref = storage. reference ( withPath: " ios/public/-._~!$'()*,=:@&+; " )
70
- let data = try XCTUnwrap ( " Hello Swift World " . data ( using: . utf8) , " Data construction failed " )
78
+ let data = try XCTUnwrap ( " Hello Swift World-._~!$'()*,=:@&+; " . data ( using: . utf8) ,
79
+ " Data construction failed " )
71
80
let result = try await ref. putDataAsync ( data)
72
81
XCTAssertNotNil ( result)
73
82
}
74
83
75
84
func testSimplePutDataInBackgroundQueue( ) async throws {
76
- actor MyBackground {
77
- func doit ( _ ref: StorageReference ) async throws -> StorageMetadata {
85
+ actor Background {
86
+ func uploadData ( _ ref: StorageReference ) async throws -> StorageMetadata {
78
87
let data = try XCTUnwrap (
79
88
" Hello Swift World " . data ( using: . utf8) ,
80
89
" Data construction failed "
@@ -84,7 +93,7 @@ import XCTest
84
93
}
85
94
}
86
95
let ref = storage. reference ( withPath: " ios/public/testBytesUpload " )
87
- let result = try await MyBackground ( ) . doit ( ref)
96
+ let result = try await Background ( ) . uploadData ( ref)
88
97
XCTAssertNotNil ( result)
89
98
}
90
99
@@ -106,38 +115,8 @@ import XCTest
106
115
}
107
116
}
108
117
109
- func testSimplePutFile( ) throws {
110
- let expectation = self . expectation ( description: #function)
111
- let putFileExpectation = self . expectation ( description: " putFile " )
112
- let ref = storage. reference ( withPath: " ios/public/testSimplePutFile " )
113
- let data = try XCTUnwrap ( " Hello Swift World " . data ( using: . utf8) , " Data construction failed " )
114
- let tmpDirURL = URL ( fileURLWithPath: NSTemporaryDirectory ( ) )
115
- let fileURL = tmpDirURL. appendingPathComponent ( " hello.txt " )
116
- try data. write ( to: fileURL, options: . atomicWrite)
117
- let task = ref. putFile ( from: fileURL) { result in
118
- self . assertResultSuccess ( result)
119
- putFileExpectation. fulfill ( )
120
- }
121
-
122
- task. observe ( StorageTaskStatus . success) { snapshot in
123
- XCTAssertEqual ( snapshot. description, " <State: Success> " )
124
- expectation. fulfill ( )
125
- }
126
-
127
- var uploadedBytes : Int64 = - 1
128
-
129
- task. observe ( StorageTaskStatus . progress) { snapshot in
130
- XCTAssertTrue ( snapshot. description. starts ( with: " <State: Progress " ) ||
131
- snapshot. description. starts ( with: " <State: Resume " ) )
132
- guard let progress = snapshot. progress else {
133
- XCTFail ( " Failed to get snapshot.progress " )
134
- return
135
- }
136
- XCTAssertGreaterThanOrEqual ( progress. completedUnitCount, uploadedBytes)
137
- uploadedBytes = progress. completedUnitCount
138
- }
139
- waitForExpectations ( )
140
- }
118
+ // TODO: Update this function when the task handle APIs are updated for the new Swift Concurrency.
119
+ func testSimplePutFile( ) throws { }
141
120
142
121
func testAttemptToUploadDirectoryShouldFail( ) async throws {
143
122
// This `.numbers` file is actually a directory.
@@ -200,14 +179,14 @@ import XCTest
200
179
}
201
180
202
181
func testSimpleGetDataInBackgroundQueue( ) async throws {
203
- actor MyBackground {
204
- func doit ( _ ref: StorageReference ) async throws -> Data {
182
+ actor Background {
183
+ func data ( from ref: StorageReference ) async throws -> Data {
205
184
XCTAssertFalse ( Thread . isMainThread)
206
185
return try await ref. data ( maxSize: 1024 * 1024 )
207
186
}
208
187
}
209
188
let ref = storage. reference ( withPath: " ios/public/1mb2 " )
210
- let result = try await MyBackground ( ) . doit ( ref)
189
+ let result = try await Background ( ) . data ( from : ref)
211
190
XCTAssertNotNil ( result)
212
191
}
213
192
@@ -233,9 +212,8 @@ import XCTest
233
212
let downloadURL = try await ref. downloadURL ( )
234
213
let testRegex = try NSRegularExpression ( pattern: downloadURLPattern)
235
214
let urlString = downloadURL. absoluteString
236
- XCTAssertEqual ( testRegex. numberOfMatches ( in: urlString,
237
- range: NSRange ( location: 0 ,
238
- length: urlString. count) ) , 1 )
215
+ let range = NSRange ( location: 0 , length: urlString. count)
216
+ XCTAssertNotNil ( testRegex. firstMatch ( in: urlString, options: [ ] , range: range) )
239
217
}
240
218
241
219
func testAsyncWrite( ) async throws {
@@ -350,10 +328,7 @@ import XCTest
350
328
let listResult = try await ref. list ( maxResults: 2 )
351
329
XCTAssertEqual ( listResult. items, [ ref. child ( " a " ) , ref. child ( " b " ) ] )
352
330
XCTAssertEqual ( listResult. prefixes, [ ] )
353
- guard let pageToken = listResult. pageToken else {
354
- XCTFail ( " pageToken should not be nil " )
355
- return
356
- }
331
+ let pageToken = try XCTUnwrap ( listResult. pageToken)
357
332
let listResult2 = try await ref. list ( maxResults: 2 , pageToken: pageToken)
358
333
XCTAssertEqual ( listResult2. items, [ ] )
359
334
XCTAssertEqual ( listResult2. prefixes, [ ref. child ( " prefix " ) ] )
@@ -369,23 +344,13 @@ import XCTest
369
344
}
370
345
371
346
private func waitForExpectations( ) {
372
- let kFIRStorageIntegrationTestTimeout = 60.0
373
- waitForExpectations ( timeout: kFIRStorageIntegrationTestTimeout ,
347
+ let kTestTimeout = 60.0
348
+ waitForExpectations ( timeout: kTestTimeout ,
374
349
handler: { ( error) -> Void in
375
350
if let error = error {
376
351
print ( error)
377
352
}
378
353
} )
379
354
}
380
-
381
- private func assertResultSuccess< T> ( _ result: Result < T , Error > ,
382
- file: StaticString = #file, line: UInt = #line) {
383
- switch result {
384
- case let . success( value) :
385
- XCTAssertNotNil ( value, file: file, line: line)
386
- case let . failure( error) :
387
- XCTFail ( " Unexpected error \( error) " )
388
- }
389
- }
390
355
}
391
356
#endif
0 commit comments