Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created September 5, 2025 21:59
Show Gist options
  • Select an option

  • Save jubishop/b0873ba098807e139e1712816cd6f8d0 to your computer and use it in GitHub Desktop.

Select an option

Save jubishop/b0873ba098807e139e1712816cd6f8d0 to your computer and use it in GitHub Desktop.
Staged changes in PodHaven FakeFileManager
diff --git a/PodHavenTests/Fakes/FakeFileManager.swift b/PodHavenTests/Fakes/FakeFileManager.swift
index 5d001e2..96972bb 100644
--- a/PodHavenTests/Fakes/FakeFileManager.swift
+++ b/PodHavenTests/Fakes/FakeFileManager.swift
@@ -3,115 +3,61 @@
import Foundation
@testable import PodHaven
final class FakeFileManager: FileManageable, @unchecked Sendable {
// MARK: - State
private let inMemoryFiles = ThreadSafe<[URL: Data]>([:])\n- private let inMemoryDirectories = ThreadSafe<Set<URL>>([]) // TODO: why do i need this?
// MARK: - Initialization
init() {}
// MARK: - Data Operations
func writeData(_ data: Data, to url: URL) async throws {
- // Ensure parent directories exist
- let parentURL = url.deletingLastPathComponent()
- if parentURL != url { // Prevent infinite recursion for root
- inMemoryDirectories { $0.insert(parentURL) }
- }
-
inMemoryFiles { $0[url] = data }
}
func readData(from url: URL) async throws -> Data {
- if let data = inMemoryFiles({ $0[url] }) {
- return data
- }
- throw TestError.fileNotFound(url)
+ guard let data = inMemoryFiles({ $0[url] })
+ else { throw TestError.fileNotFound(url) }
+
+ return data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment