Implemented the "createFile(at: with: )" function for the FileService service in the library target.

This commit is contained in:
2025-02-07 21:50:50 +01:00
parent 3dcb110de1
commit 33ae67fc58
5 changed files with 78 additions and 9 deletions
@@ -64,6 +64,19 @@ extension FileServiceMock: FileServicing {
}
}
func createFile(at location: URL, with data: Data) async throws (FileServiceError) {
guard let nextAction else { return }
switch nextAction {
case .error(let error):
throw error
case let .createFile(location, data):
try await spy?.createFile(at: location, with: data)
default:
break
}
}
func createFolder(at location: URL) async throws (FileServiceError) {
guard let nextAction else { return }
@@ -127,6 +140,7 @@ private extension FileServiceMock {
extension FileServiceMock {
enum Action {
case copyFile(URL, URL)
case createFile(URL, Data)
case createFolder(URL)
case deleteItem(URL)
case error(FileServiceError)
@@ -21,6 +21,10 @@ extension FileServiceSpy: FileServicing {
actions.append(.fileCopied(source, destination))
}
func createFile(at location: URL, with data: Data) async throws (FileServiceError) {
actions.append(.fileCreated(location, data))
}
func createFolder(at location: URL) async throws (FileServiceError) {
actions.append(.folderCreated(location))
}
@@ -42,6 +46,7 @@ extension FileServiceSpy: FileServicing {
extension FileServiceSpy {
enum Action: Equatable {
case fileCreated(_ location: URL, _ data: Data)
case fileCopied(_ source: URL, _ destination: URL)
case folderCreated(_ location: URL)
case itemDeleted(_ location: URL)