Restructured the folder structure in the library and test targets.
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import Foundation
|
||||
import Testing
|
||||
|
||||
@testable import ColibriLibrary
|
||||
|
||||
struct CopyFilesTaskTests {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
private let resourceFolder = URL.someExistingFolder
|
||||
private let rootFolder = URL.someNewFolder
|
||||
|
||||
private let spy = FileServiceSpy()
|
||||
|
||||
// MARK: Functions tests
|
||||
|
||||
@Test func copyFiles() async throws {
|
||||
// GIVEN
|
||||
let files = files(of: ResourceFile.allCases)
|
||||
let actions = files.map { FileServiceMock.Action.copyFile($0.source, $0.destination) }
|
||||
|
||||
let copyFiles = CopyFilesTask(fileService: FileServiceMock(
|
||||
currentFolder: .someCurrentFolder,
|
||||
actions: actions,
|
||||
spy: spy
|
||||
))
|
||||
|
||||
// WHEN
|
||||
try await copyFiles(to: rootFolder)
|
||||
|
||||
// THEN
|
||||
#expect(spy.actions.count == actions.count)
|
||||
|
||||
files.enumerated().forEach { index, file in
|
||||
#expect(spy.actions[index] == .fileCopied(file.source, file.destination))
|
||||
}
|
||||
}
|
||||
|
||||
@Test(arguments: [FileServiceError.itemAlreadyExists, .itemEmptyData, .itemNotCopied])
|
||||
func copyFiles(throws error: FileServiceError) async throws {
|
||||
// GIVEN
|
||||
let files = files(of: Array(ResourceFile.allCases[0...2]))
|
||||
let actions = files.map { FileServiceMock.Action.copyFile($0.source, $0.destination) }
|
||||
|
||||
let copyFiles = CopyFilesTask(fileService: FileServiceMock(
|
||||
currentFolder: .someCurrentFolder,
|
||||
actions: actions + [.error(error)],
|
||||
spy: spy
|
||||
))
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: error) {
|
||||
try await copyFiles(to: rootFolder)
|
||||
}
|
||||
|
||||
#expect(spy.actions.count == actions.count)
|
||||
|
||||
files.enumerated().forEach { index, file in
|
||||
#expect(spy.actions[index] == .fileCopied(file.source, file.destination))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private extension CopyFilesTaskTests {
|
||||
|
||||
// MARK: Type aliases
|
||||
|
||||
typealias File = (source: URL, destination: URL)
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
func files(of resourceFiles: [ResourceFile]) -> [File] {
|
||||
resourceFiles.map { (resourceFolder.appendingPath($0.rawValue), rootFolder.appendingPath($0.fileName)) }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user