colibri/Test/Sources/Helpers/Mocks/TerminalServiceMock.swift
Javier Cicchelli 212ca52279 Template support for input parameters (#4)
This PR contains the work done to support input parameters for the `create` command of the executable target, and to render content dynamically for the newly-generated project.

Reviewed-on: #4
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
2025-02-17 22:11:05 +00:00

74 lines
1.4 KiB
Swift

import ColibriLibrary
import Foundation
final class TerminalServiceMock {
// MARK: Properties
private var actions: [Action] = []
private weak var spy: TerminalServiceSpy?
// MARK: Initialisers
init(
action: Action,
spy: TerminalServiceSpy? = nil
) {
self.actions.append(action)
self.spy = spy
}
}
// MARK: - TerminalServicing
extension TerminalServiceMock: TerminalServicing {
// MARK: Functions
func run(_ executableURL: URL, arguments: [String]) async throws (TerminalServiceError) -> String {
guard let nextAction else { return .empty }
switch nextAction {
case .error(let error):
throw error
case let .run(executableURL, arguments):
try await spy?.run(executableURL, arguments: arguments)
return .empty
}
}
}
// MARK: - Helpers
private extension TerminalServiceMock {
// MARK: Computed
var nextAction: Action? {
guard !actions.isEmpty else {
return nil
}
return actions.removeFirst()
}
}
// MARK: - Actions
extension TerminalServiceMock {
enum Action {
case error(TerminalServiceError)
case run(URL, [String])
}
}
// MARK: - String+Constants
private extension String {
static let empty = ""
}