Skip to content

Commit 590ca3f

Browse files
Merge pull request #22 from SwiftPackageIndex/extend-zip-tests
Make sure we also test sub directory behaviour
2 parents dd73918 + 4aabf7c commit 590ca3f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed
14 Bytes
Binary file not shown.

Tests/DocUploadBundleTests/ZipTests.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,23 @@ final class ZipTests: XCTestCase {
2222
func test_zip() async throws {
2323
// Test basic zip behaviour we expect from the library we use
2424
try await withTempDir { tempDir in
25+
// temp
2526
let tempURL = URL(fileURLWithPath: tempDir)
27+
28+
// temp/a.txt
2629
let fileA = tempURL.appendingPathComponent("a.txt")
27-
let fileB = tempURL.appendingPathComponent("b.txt")
2830
try "a".write(to: fileA, atomically: true, encoding: .utf8)
31+
32+
// temp/subdir/
33+
let subdir = tempURL.appendingPathComponent("subdir")
34+
try FileManager.default.createDirectory(at: subdir, withIntermediateDirectories: false)
35+
36+
// temp/subdir/b.txt
37+
let fileB = subdir.appendingPathComponent("b.txt")
2938
try "b".write(to: fileB, atomically: true, encoding: .utf8)
39+
3040
let zipFile = tempURL.appendingPathComponent("out.zip")
31-
try Zipper.zip(paths: [fileA, fileB], to: zipFile)
41+
try Zipper.zip(paths: [fileA, subdir], to: zipFile)
3242
XCTAssert(FileManager.default.fileExists(atPath: zipFile.path))
3343
}
3444
}
@@ -41,8 +51,11 @@ final class ZipTests: XCTestCase {
4151
let outDir = tempURL.appendingPathComponent("out")
4252
try Zipper.unzip(from: zipFile, to: outDir)
4353
XCTAssert(FileManager.default.fileExists(atPath: outDir.path))
54+
55+
// out/a.txt
56+
// out/subdir/b.txt
4457
let fileA = outDir.appendingPathComponent("a.txt")
45-
let fileB = outDir.appendingPathComponent("b.txt")
58+
let fileB = outDir.appendingPathComponent("subdir").appendingPathComponent("b.txt")
4659
XCTAssert(FileManager.default.fileExists(atPath: fileA.path))
4760
XCTAssert(FileManager.default.fileExists(atPath: fileB.path))
4861
XCTAssertEqual(try String(contentsOf: fileA), "a")

0 commit comments

Comments
 (0)