Skip to content

Commit

Permalink
Removed commented code and added tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcomi committed Mar 20, 2024
1 parent e4b75e7 commit 52f1e29
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
26 changes: 0 additions & 26 deletions FirebaseStorage/Sources/StorageReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,32 +237,6 @@ import Foundation
return task
}

/*
open func putFileHandle(_ fileHandle: FileHandle, metadata: StorageMetadata? = nil) -> StorageUploadTask {
return putFileHandle(fileHandle, metadata: metadata, completion: nil)
}

open func putFileHandle(_ fileHandle: FileHandle,
metadata: StorageMetadata? = nil,
completion: ((_: StorageMetadata?, _: Error?) -> Void)?) -> StorageUploadTask {
print("called this one")
let putMetadata: StorageMetadata = metadata ?? StorageMetadata()

if let path = path.object {
putMetadata.path = path
putMetadata.name = (path as NSString).lastPathComponent as String
}

let task = StorageUploadTask(reference: self,
service: storage.fetcherServiceForApp,
queue: storage.dispatchQueue,
fileHandle: fileHandle,
metadata: putMetadata)
startAndObserveUploadTask(task: task, completion: completion)
return task
}
*/

// MARK: - Downloads

/// Asynchronously downloads the object at the `StorageReference` to a `Data` instance in memory.
Expand Down
33 changes: 33 additions & 0 deletions FirebaseStorage/Tests/Integration/StorageAsyncAwait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ class StorageAsyncAwait: StorageIntegrationCommon {
XCTAssertNotNil(result)
}

func testSimplePutFileHandleNoMetadata() async throws {
let ref = storage.reference(withPath: "ios/public/testSimplePutFileHandleNoMetadata")
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")
let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory())
let fileURL = tmpDirURL.appendingPathComponent(#function + "hello.txt")
try data.write(to: fileURL, options: .atomicWrite)

let fileHandle = try XCTUnwrap(FileHandle(forReadingFrom: fileURL), "FileHandle init failed")

let result = try await ref.putFileHandleAsync(fileHandle)
XCTAssertNotNil(result)
}

func testSimplePutFileWithAsyncProgress() async throws {
var checkedProgress = false
let ref = storage.reference(withPath: "ios/public/testSimplePutFile")
Expand All @@ -196,6 +209,26 @@ class StorageAsyncAwait: StorageIntegrationCommon {
XCTAssertTrue(checkedProgress)
}

func testSimplePutFileHandleWithAsyncProgress() async throws {
var checkedProgress = false
let ref = storage.reference(withPath: "ios/public/testSimplePutFileHandle")
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")
let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory())
let fileURL = tmpDirURL.appendingPathComponent(#function + "hello.txt")
try data.write(to: fileURL, options: .atomicWrite)
let fileHandle = try XCTUnwrap(FileHandle(forReadingFrom: fileURL), "FileHandle init failed")
var uploadedBytes: Int64 = -1
let successMetadata = try await ref.putFileHandleAsync(fileHandle) { progress in
if let completed = progress?.completedUnitCount {
checkedProgress = true
XCTAssertGreaterThanOrEqual(completed, uploadedBytes)
uploadedBytes = completed
}
}
XCTAssertEqual(successMetadata.size, 17)
XCTAssertTrue(checkedProgress)
}

func testSimpleGetData() async throws {
let ref = storage.reference(withPath: "ios/public/1mb2")
let result = try await ref.data(maxSize: 1024 * 1024)
Expand Down
4 changes: 2 additions & 2 deletions FirebaseStorage/Tests/Integration/StorageIntegration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ class StorageResultTests: StorageIntegrationCommon {

let fileHandle = try XCTUnwrap(FileHandle(forReadingFrom: fileURL), "FileHandle init failed")

let task = ref.putFileHandle(from: fileURL) { result in
let task = ref.putFileHandle(fileHandle) { result in
self.assertResultSuccess(result)
putFileExpectation.fulfill()
putFileHandleExpectation.fulfill()
}

task.observe(StorageTaskStatus.success) { snapshot in
Expand Down

0 comments on commit 52f1e29

Please sign in to comment.