Implemented the "createFile(at: with: )" function for the FileService service in the library target.
This commit is contained in:
@@ -35,7 +35,7 @@ struct FileServiceTests {
|
||||
// WHEN
|
||||
try await service.copyFile(from: source, to: destination)
|
||||
|
||||
// THENn
|
||||
// THEN
|
||||
#expect(spy.actions.count == 1)
|
||||
|
||||
let action = try #require(spy.actions.last)
|
||||
@@ -57,6 +57,37 @@ struct FileServiceTests {
|
||||
#expect(spy.actions.isEmpty == true)
|
||||
}
|
||||
|
||||
@Test(arguments: zip([URL.someNewFile],
|
||||
[Data("some data goes here...".utf8)]))
|
||||
func createFile(with location: URL, and data: Data) async throws {
|
||||
// GIVEN
|
||||
let service = service(action: .createFile(location, data))
|
||||
|
||||
// WHEN
|
||||
try await service.createFile(at: location, with: data)
|
||||
|
||||
// THEN
|
||||
#expect(spy.actions.count == 1)
|
||||
|
||||
let action = try #require(spy.actions.last)
|
||||
|
||||
#expect(action == .fileCreated(location, data))
|
||||
}
|
||||
|
||||
@Test(arguments: [FileServiceError.itemAlreadyExists, .fileDataIsEmpty, .fileNotCreated])
|
||||
func createFile(throws error: FileServiceError) async throws {
|
||||
// GIVEN
|
||||
let service = service(action: .error(error))
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: error) {
|
||||
try await service.createFile(at: .someNewFile, with: .init())
|
||||
}
|
||||
|
||||
#expect(spy.actions.isEmpty == true)
|
||||
}
|
||||
|
||||
@Test(arguments: [URL.someNewFolder, .someNewFile])
|
||||
func createFolder(with location: URL) async throws {
|
||||
// GIVEN
|
||||
|
||||
Reference in New Issue
Block a user