Skip to content

Commit 8e987c2

Browse files
Merge pull request #24 from SwiftPackageIndex/issue-3069
Issue 3069
2 parents 7079392 + 23e14bd commit 8e987c2

File tree

4 files changed

+47
-37
lines changed

4 files changed

+47
-37
lines changed

Tests/DocUploadBundleTests/DocUploadBundleTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,17 @@ final class DocUploadBundleTests: XCTestCase {
100100
.init(bucket: "spi-prod-docs", path: "owner/name/feature-2.0.0"))
101101
}
102102

103+
func test_issue_3069() async throws {
104+
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/3069
105+
try await withTempDir { tempDir in
106+
let url = fixtureUrl(for: "prod-apple-swift-metrics-main-e6a00d36.zip")
107+
XCTAssertNoThrow(
108+
try DocUploadBundle.unzip(bundle: url.path, outputPath: tempDir)
109+
)
110+
XCTAssert(FileManager.default.fileExists(atPath: tempDir + "/metadata.json"))
111+
XCTAssert(FileManager.default.fileExists(atPath: tempDir + "/main/index.html"))
112+
XCTAssert(FileManager.default.fileExists(atPath: tempDir + "/main/index/index.json"))
113+
}
114+
}
115+
103116
}
Binary file not shown.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import Foundation
2+
3+
4+
enum TempDirError: LocalizedError {
5+
case invalidPath(String)
6+
}
7+
8+
9+
class TempDir {
10+
let path: String
11+
12+
init() throws {
13+
let tempDir = FileManager.default.temporaryDirectory
14+
.appendingPathComponent(UUID().uuidString)
15+
path = tempDir.path
16+
try FileManager.default.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
17+
precondition(FileManager.default.fileExists(atPath: path), "failed to create temp dir")
18+
}
19+
20+
deinit {
21+
do {
22+
try FileManager.default.removeItem(atPath: path)
23+
} catch {
24+
print("⚠️ failed to delete temp directory: \(error.localizedDescription)")
25+
}
26+
}
27+
28+
}
29+
30+
31+
func withTempDir<T>(body: (String) async throws -> T) async throws -> T {
32+
let tmp = try TempDir()
33+
return try await body(tmp.path)
34+
}

Tests/DocUploadBundleTests/Utils.swift

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
import Foundation
1717

1818

19-
// Helpers
20-
2119
func fixtureData(for fixture: String) throws -> Data {
2220
try Data(contentsOf: fixtureUrl(for: fixture))
2321
}
@@ -33,38 +31,3 @@ func fixturesDirectory(path: String = #file) -> URL {
3331
let testsDir = url.deletingLastPathComponent()
3432
return testsDir.appendingPathComponent("Fixtures")
3533
}
36-
37-
38-
// TempDir
39-
40-
enum TempDirError: LocalizedError {
41-
case invalidPath(String)
42-
}
43-
44-
45-
class TempDir {
46-
let path: String
47-
48-
init() throws {
49-
let tempDir = FileManager.default.temporaryDirectory
50-
.appendingPathComponent(UUID().uuidString)
51-
path = tempDir.path
52-
try FileManager.default.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
53-
precondition(FileManager.default.fileExists(atPath: path), "failed to create temp dir")
54-
}
55-
56-
deinit {
57-
do {
58-
try FileManager.default.removeItem(atPath: path)
59-
} catch {
60-
print("⚠️ failed to delete temp directory: \(error.localizedDescription)")
61-
}
62-
}
63-
64-
}
65-
66-
67-
func withTempDir<T>(body: (String) async throws -> T) async throws -> T {
68-
let tmp = try TempDir()
69-
return try await body(tmp.path)
70-
}

0 commit comments

Comments
 (0)