Skip to content

Commit

Permalink
Merge pull request #24 from SwiftPackageIndex/issue-3069
Browse files Browse the repository at this point in the history
Issue 3069
  • Loading branch information
finestructure committed May 27, 2024
2 parents 7079392 + 23e14bd commit 8e987c2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 37 deletions.
13 changes: 13 additions & 0 deletions Tests/DocUploadBundleTests/DocUploadBundleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,17 @@ final class DocUploadBundleTests: XCTestCase {
.init(bucket: "spi-prod-docs", path: "owner/name/feature-2.0.0"))
}

func test_issue_3069() async throws {
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/3069
try await withTempDir { tempDir in
let url = fixtureUrl(for: "prod-apple-swift-metrics-main-e6a00d36.zip")
XCTAssertNoThrow(
try DocUploadBundle.unzip(bundle: url.path, outputPath: tempDir)
)
XCTAssert(FileManager.default.fileExists(atPath: tempDir + "/metadata.json"))
XCTAssert(FileManager.default.fileExists(atPath: tempDir + "/main/index.html"))
XCTAssert(FileManager.default.fileExists(atPath: tempDir + "/main/index/index.json"))
}
}

}
Binary file not shown.
34 changes: 34 additions & 0 deletions Tests/DocUploadBundleTests/TempDir.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Foundation


enum TempDirError: LocalizedError {
case invalidPath(String)
}


class TempDir {
let path: String

init() throws {
let tempDir = FileManager.default.temporaryDirectory
.appendingPathComponent(UUID().uuidString)
path = tempDir.path
try FileManager.default.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
precondition(FileManager.default.fileExists(atPath: path), "failed to create temp dir")
}

deinit {
do {
try FileManager.default.removeItem(atPath: path)
} catch {
print("⚠️ failed to delete temp directory: \(error.localizedDescription)")
}
}

}


func withTempDir<T>(body: (String) async throws -> T) async throws -> T {
let tmp = try TempDir()
return try await body(tmp.path)
}
37 changes: 0 additions & 37 deletions Tests/DocUploadBundleTests/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import Foundation


// Helpers

func fixtureData(for fixture: String) throws -> Data {
try Data(contentsOf: fixtureUrl(for: fixture))
}
Expand All @@ -33,38 +31,3 @@ func fixturesDirectory(path: String = #file) -> URL {
let testsDir = url.deletingLastPathComponent()
return testsDir.appendingPathComponent("Fixtures")
}


// TempDir

enum TempDirError: LocalizedError {
case invalidPath(String)
}


class TempDir {
let path: String

init() throws {
let tempDir = FileManager.default.temporaryDirectory
.appendingPathComponent(UUID().uuidString)
path = tempDir.path
try FileManager.default.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
precondition(FileManager.default.fileExists(atPath: path), "failed to create temp dir")
}

deinit {
do {
try FileManager.default.removeItem(atPath: path)
} catch {
print("⚠️ failed to delete temp directory: \(error.localizedDescription)")
}
}

}


func withTempDir<T>(body: (String) async throws -> T) async throws -> T {
let tmp = try TempDir()
return try await body(tmp.path)
}

0 comments on commit 8e987c2

Please sign in to comment.