Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Sep 10, 2024
1 parent af87289 commit 3a0e530
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Tests/ZipTests/ZipTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,30 @@ final class ZipTests: XCTestCase {
XCTAssertNil(zip)
}

func testUnzipWithoutPassword() throws {
let imageURL1 = url(forResource: "3crBXeO", withExtension: "gif")!
let imageURL2 = url(forResource: "kYkLkPf", withExtension: "gif")!
let zipFilePath = try autoRemovingSandbox().appendingPathComponent("archive.zip")
try Zip.zipFiles(paths: [imageURL1, imageURL2], zipFilePath: zipFilePath, password: "password")
XCTAssertTrue(FileManager.default.fileExists(atPath: zipFilePath.path))
let directoryName = zipFilePath.lastPathComponent.replacingOccurrences(of: ".\(zipFilePath.pathExtension)", with: "")
let destinationUrl = try autoRemovingSandbox().appendingPathComponent(directoryName, isDirectory: true)
XCTAssertThrowsError(try Zip.unzipFile(zipFilePath, destination: destinationUrl))
}

func testFileHandler() throws {
let filePath = url(forResource: "bb8", withExtension: "zip")!
let destinationPath = try autoRemovingSandbox()

XCTAssertNoThrow(try Zip.unzipFile(filePath, destination: destinationPath, password: "password", fileOutputHandler: { fileURL in
XCTAssertTrue(FileManager.default.fileExists(atPath: fileURL.path))
}))

XCTAssertTrue(FileManager.default.fileExists(atPath: destinationPath.path))
try XCTAssertGreaterThan(Data(contentsOf: destinationPath.appendingPathComponent("3crBXeO.gif")).count, 0)
try XCTAssertGreaterThan(Data(contentsOf: destinationPath.appendingPathComponent("kYkLkPf.gif")).count, 0)
}

// Tests if https://github.com/vapor-community/Zip/issues/4 does not occur anymore.
func testRoundTripping() throws {
// "prod-apple-swift-metrics-main-e6a00d36.zip" is the original zip file from the issue.
Expand Down

0 comments on commit 3a0e530

Please sign in to comment.