|
14 | 14 |
|
15 | 15 | import FirebaseAuth
|
16 | 16 | import FirebaseCore
|
17 |
| -import FirebaseStorage |
| 17 | +@testable import FirebaseStorage |
18 | 18 | import XCTest
|
19 | 19 |
|
20 | 20 | /**
|
@@ -475,6 +475,42 @@ class StorageResultTests: StorageIntegrationCommon {
|
475 | 475 | waitForExpectations()
|
476 | 476 | }
|
477 | 477 |
|
| 478 | + func testCancelErrorCode() throws { |
| 479 | + let expectation = self.expectation(description: #function) |
| 480 | + let ref = storage.reference(withPath: "ios/public/helloworld") |
| 481 | + let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory()) |
| 482 | + let fileURL = tmpDirURL.appendingPathComponent("hello.txt") |
| 483 | + let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed") |
| 484 | + |
| 485 | + ref.putData(data) { result in |
| 486 | + switch result { |
| 487 | + case .success: |
| 488 | + let task = ref.write(toFile: fileURL) |
| 489 | + task.cancel() |
| 490 | + |
| 491 | + task.observe(StorageTaskStatus.success) { snapshot in |
| 492 | + XCTFail("Error processing success snapshot") |
| 493 | + expectation.fulfill() |
| 494 | + } |
| 495 | + |
| 496 | + task.observe(StorageTaskStatus.failure) { snapshot in |
| 497 | + let expected = "User cancelled the upload/download." |
| 498 | + if let error = snapshot.error { |
| 499 | + let errorDescription = error.localizedDescription |
| 500 | + XCTAssertEqual(errorDescription, expected) |
| 501 | + let code = (error as NSError).code |
| 502 | + XCTAssertEqual(code, StorageErrorCode.cancelled.rawValue) |
| 503 | + } |
| 504 | + expectation.fulfill() |
| 505 | + } |
| 506 | + case let .failure(error): |
| 507 | + XCTFail("Unexpected error \(error) from putData") |
| 508 | + expectation.fulfill() |
| 509 | + } |
| 510 | + } |
| 511 | + waitForExpectations() |
| 512 | + } |
| 513 | + |
478 | 514 | private func assertMetadata(actualMetadata: StorageMetadata,
|
479 | 515 | expectedContentType: String,
|
480 | 516 | expectedCustomMetadata: [String: String]) {
|
|
0 commit comments