diff --git a/Sources/BinaryDependencyManager/Utils/FileManagerProtocol.swift b/Sources/BinaryDependencyManager/Utils/FileManagerProtocol.swift index 362c27a..65362c7 100644 --- a/Sources/BinaryDependencyManager/Utils/FileManagerProtocol.swift +++ b/Sources/BinaryDependencyManager/Utils/FileManagerProtocol.swift @@ -27,6 +27,8 @@ public protocol FileManagerProtocol { func contentsOfDirectory(atPath path: String) throws -> [String] func createFile(atPath path: String, contents data: Data?, attributes attr: [FileAttributeKey : Any]?) -> Bool + + func copyItem(at srcURL: URL, to dstURL: URL) throws } extension FileManagerProtocol { diff --git a/Tests/BinaryDependencyManagerTests/Mocks/FileManagerProtocolMock.swift b/Tests/BinaryDependencyManagerTests/Mocks/FileManagerProtocolMock.swift index 3cd9206..db6d0a5 100644 --- a/Tests/BinaryDependencyManagerTests/Mocks/FileManagerProtocolMock.swift +++ b/Tests/BinaryDependencyManagerTests/Mocks/FileManagerProtocolMock.swift @@ -2,12 +2,20 @@ import Foundation class FileManagerProtocolMock: FileManagerProtocol { + var copiedFiles: [URL: URL] = [:] + func copyItem(at srcURL: URL, to dstURL: URL) throws { + copiedFiles[srcURL] = dstURL + existingFiles.insert(dstURL.filePath) + contentsMap[dstURL] = contentsMap[srcURL] + } + func createDirectory(at url: URL, withIntermediateDirectories createIntermediates: Bool, attributes: [FileAttributeKey : Any]?) throws { createdDirectories.append(url) } + var directoryContents: [String: [String]] = [:] func contentsOfDirectory(atPath path: String) throws -> [String] { - [] + directoryContents[path] ?? [] } var existingFiles: Set = [] @@ -31,7 +39,11 @@ class FileManagerProtocolMock: FileManagerProtocol { var temporaryDirectory: URL { tempDir } func contents(at url: URL) -> Data? { contentsMap[url] } - func removeItem(at url: URL) throws { removedItems.append(url) } + func removeItem(at url: URL) throws { + removedItems.append(url) + existingFiles.remove(url.filePath) + contentsMap[url] = .none + } var createdFiles: [String] = [] func createFile(atPath path: String, contents data: Data?, attributes attr: [FileAttributeKey : Any]?) -> Bool {