Template support for input parameters #4

Merged
javier merged 81 commits from feature/arguments-templating into main 2025-02-17 22:11:06 +00:00
2 changed files with 96 additions and 0 deletions
Showing only changes of commit 72230c5337 - Show all commits

View File

@ -0,0 +1,53 @@
import Foundation
public struct CopyFilesTask {
// MARK: Properties
private let fileService: FileServicing
// MARK: Initialisers
public init(fileService: FileServicing) {
self.fileService = fileService
}
// MARK: Functions
public func callAsFunction(to rootFolder: URL) async throws {
let filesFolder = URL(at: .folderFiles)
for fileToCopy in Self.filesToCopy {
try await fileService.copyItem(
from: filesFolder.appendingPath(fileToCopy),
to: rootFolder.appendingPath(fileToCopy)
)
}
}
}
// MARK: - Helpers
extension CopyFilesTask {
// MARK: Constants
static let filesToCopy: [String] = [
.fileDockerIgnore,
.fileGitIgnore,
.fileLicense,
.fileReadme
]
}
// MARK: - URL+Constants
private extension String {
static let folderFiles = "./Resources/Files"
static let fileDockerIgnore = ".dockerignore"
static let fileGitIgnore = ".gitignore"
static let fileLicense = "LICENSE"
static let fileReadme = "README.md"
}

View File

@ -0,0 +1,43 @@
import Foundation
import Testing
@testable import ColibriLibrary
struct CopyFilesTaskTests {
// MARK: Properties
private let spy = FileServiceSpy()
// MARK: Functions tests
@Test(arguments: zip([URL.someExistingFolder], [URL.someNewFolder]))
func copyFiles(from source: URL, to destination: URL) async throws {
// GIVEN
let filesToCopy = CopyFilesTask.filesToCopy
let destinations = filesToCopy.map { destination.appendingPath($0) }
let sources = filesToCopy.map { source.appendingPath($0) }
let actions = filesToCopy.indices.map { index -> FileServiceMock.Action in
.copyItem(sources[index], destinations[index])
}
let service = FileServiceMock(
currentFolder: .someCurrentFolder,
actions: actions,
spy: spy
)
let copyFiles = CopyFilesTask(fileService: service)
// WHEN
try await copyFiles(to: destination)
// THEN
#expect(spy.actions.count == actions.count)
for index in actions.indices {
#expect(spy.actions[index] == .itemCopied(sources[index], destinations[index]))
}
}
}