Skip to content

Commit 886b06f

Browse files
committed
Update ZipTests to show that ZipFoundation isn't recursing into directories
1 parent dc4ba4b commit 886b06f

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

Tests/DocUploadBundleTests/ZipTests.swift

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,29 @@ import XCTest
1818

1919

2020
final class ZipTests: XCTestCase {
21+
22+
func test_unzip() async throws {
23+
// Test basic unzip behaviour we expect from the library we use
24+
try await withTempDir { tempDir in
25+
let tempURL = URL(fileURLWithPath: tempDir)
26+
let zipFile = fixtureUrl(for: "out.zip")
27+
let outDir = tempURL.appendingPathComponent("out")
28+
try Zipper.unzip(from: zipFile, to: outDir)
29+
XCTAssert(FileManager.default.fileExists(atPath: outDir.path))
30+
31+
// out/a.txt
32+
// out/subdir/b.txt
33+
let fileA = outDir.appendingPathComponent("a.txt")
34+
let fileB = outDir.appendingPathComponent("subdir").appendingPathComponent("b.txt")
35+
XCTAssert(FileManager.default.fileExists(atPath: fileA.path))
36+
XCTAssert(FileManager.default.fileExists(atPath: fileB.path))
37+
XCTAssertEqual(try String(contentsOf: fileA), "a")
38+
XCTAssertEqual(try String(contentsOf: fileB), "b")
39+
}
40+
}
2141

22-
func test_zip() async throws {
23-
// Test basic zip behaviour we expect from the library we use
42+
func test_zip_roundtrip() async throws {
43+
// Test basic zip roundtrip
2444
try await withTempDir { tempDir in
2545
// temp
2646
let tempURL = URL(fileURLWithPath: tempDir)
@@ -40,26 +60,20 @@ final class ZipTests: XCTestCase {
4060
let zipFile = tempURL.appendingPathComponent("out.zip")
4161
try Zipper.zip(paths: [fileA, subdir], to: zipFile)
4262
XCTAssert(FileManager.default.fileExists(atPath: zipFile.path))
43-
}
44-
}
4563

46-
func test_unzip() async throws {
47-
// Test basic unzip behaviour we expect from the library we use
48-
try await withTempDir { tempDir in
49-
let tempURL = URL(fileURLWithPath: tempDir)
50-
let zipFile = fixtureUrl(for: "out.zip")
51-
let outDir = tempURL.appendingPathComponent("out")
52-
try Zipper.unzip(from: zipFile, to: outDir)
53-
XCTAssert(FileManager.default.fileExists(atPath: outDir.path))
54-
55-
// out/a.txt
56-
// out/subdir/b.txt
57-
let fileA = outDir.appendingPathComponent("a.txt")
58-
let fileB = outDir.appendingPathComponent("subdir").appendingPathComponent("b.txt")
59-
XCTAssert(FileManager.default.fileExists(atPath: fileA.path))
60-
XCTAssert(FileManager.default.fileExists(atPath: fileB.path))
61-
XCTAssertEqual(try String(contentsOf: fileA), "a")
62-
XCTAssertEqual(try String(contentsOf: fileB), "b")
64+
do { // unzip what we zipped and check results
65+
let roundtrip = tempURL.appendingPathComponent("roundtrip")
66+
try Zipper.unzip(from: zipFile, to: roundtrip)
67+
XCTAssert(FileManager.default.fileExists(atPath: roundtrip.path))
68+
// roundtrip/a.txt
69+
// roundtrip/subdir/b.txt
70+
let fileA = roundtrip.appendingPathComponent("a.txt")
71+
let fileB = roundtrip.appendingPathComponent("subdir").appendingPathComponent("b.txt")
72+
XCTAssert(FileManager.default.fileExists(atPath: fileA.path))
73+
XCTAssert(FileManager.default.fileExists(atPath: fileB.path))
74+
XCTAssertEqual(try String(contentsOf: fileA), "a")
75+
XCTAssertEqual(try String(contentsOf: fileB), "b")
76+
}
6377
}
6478
}
6579

0 commit comments

Comments
 (0)