Improved the implementation for the CreateFolderTask task in the library target.
This commit is contained in:
parent
9ee7592902
commit
026251ad6d
12
Library/Sources/Internal/Enumerations/Folder.swift
Normal file
12
Library/Sources/Internal/Enumerations/Folder.swift
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
enum Folder: String {
|
||||||
|
case app = "App/Sources"
|
||||||
|
case libraryPublic = "Library/Sources/Public"
|
||||||
|
case libraryInternal = "Library/Sources/Internal"
|
||||||
|
case testCasesPublic = "Test/Sources/Cases/Public"
|
||||||
|
case testCasesInternal = "Test/Sources/Cases/Internal"
|
||||||
|
case testHelpers = "Test/Sources/Helpers"
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - CaseIterable
|
||||||
|
|
||||||
|
extension Folder: CaseIterable {}
|
@ -15,7 +15,7 @@ public struct CreateFoldersTask {
|
|||||||
// MARK: Functions
|
// MARK: Functions
|
||||||
|
|
||||||
public func callAsFunction(at rootFolder: URL) async throws {
|
public func callAsFunction(at rootFolder: URL) async throws {
|
||||||
let folders = Self.foldersToCreate.map { rootFolder.appendingPath($0) }
|
let folders = Folder.allCases.map { rootFolder.appendingPath($0.rawValue) }
|
||||||
|
|
||||||
for folder in folders {
|
for folder in folders {
|
||||||
try await fileService.createFolder(at: folder)
|
try await fileService.createFolder(at: folder)
|
||||||
@ -23,18 +23,3 @@ public struct CreateFoldersTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Helpers
|
|
||||||
|
|
||||||
extension CreateFoldersTask {
|
|
||||||
|
|
||||||
// MARK: Constants
|
|
||||||
|
|
||||||
static let foldersToCreate: [String] = [
|
|
||||||
"Sources/App",
|
|
||||||
"Sources/AppInfrastructure",
|
|
||||||
"Tests/App/Cases",
|
|
||||||
"Tests/App/Sources"
|
|
||||||
]
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -14,24 +14,36 @@ struct CreateFoldersTaskTests {
|
|||||||
@Test(arguments: [URL.someCurrentFolder, .someDotFolder, .someTildeFolder])
|
@Test(arguments: [URL.someCurrentFolder, .someDotFolder, .someTildeFolder])
|
||||||
func createFolders(with rootFolder: URL) async throws {
|
func createFolders(with rootFolder: URL) async throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let folders = CreateFoldersTask.foldersToCreate.map { rootFolder.appendingPath($0) }
|
let folders = Folder.allCases.map { rootFolder.appendingPath($0.rawValue) }
|
||||||
let actions: [FileServiceMock.Action] = folders.map { .createFolder($0) }
|
let actions = folders.map { FileServiceMock.Action.createFolder($0) }
|
||||||
|
|
||||||
let service = FileServiceMock(
|
let createFolders = task(actions: actions)
|
||||||
currentFolder: .someCurrentFolder,
|
|
||||||
actions: actions,
|
|
||||||
spy: spy
|
|
||||||
)
|
|
||||||
|
|
||||||
let createFolders = CreateFoldersTask(fileService: service)
|
|
||||||
|
|
||||||
// WHEN
|
// WHEN
|
||||||
try await createFolders(at: rootFolder)
|
try await createFolders(at: rootFolder)
|
||||||
|
|
||||||
// THEN
|
// THEN
|
||||||
|
#expect(spy.actions.count == actions.count)
|
||||||
|
|
||||||
for index in actions.indices {
|
for index in actions.indices {
|
||||||
#expect(spy.actions[index] == .folderCreated(folders[index]))
|
#expect(spy.actions[index] == .folderCreated(folders[index]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Helpers
|
||||||
|
|
||||||
|
private extension CreateFoldersTaskTests {
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
func task(actions: [FileServiceMock.Action]) -> CreateFoldersTask {
|
||||||
|
.init(fileService: FileServiceMock(
|
||||||
|
currentFolder: .someCurrentFolder,
|
||||||
|
actions: actions,
|
||||||
|
spy: spy
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user