2025-02-18 23:50:54 +00:00
|
|
|
import Foundation
|
|
|
|
import Testing
|
|
|
|
|
|
|
|
@testable import ColibriLibrary
|
|
|
|
|
2025-02-19 00:14:00 +00:00
|
|
|
struct UpdateDependenciesTaskTests {
|
2025-02-18 23:50:54 +00:00
|
|
|
|
2025-02-19 00:14:00 +00:00
|
|
|
@Test(arguments: [nil, URL.someCurrentFolder], [false, true])
|
|
|
|
func task(at location: URL?, checkOutdated: Bool) async throws {
|
2025-02-18 23:50:54 +00:00
|
|
|
// GIVEN
|
|
|
|
let terminalService = TerminalServiceSpy()
|
2025-02-19 00:14:00 +00:00
|
|
|
let task = UpdateDependenciesTask(terminalService: terminalService)
|
2025-02-18 23:50:54 +00:00
|
|
|
|
|
|
|
// WHEN
|
2025-02-19 00:14:00 +00:00
|
|
|
try await task(at: location, checkOutdated: checkOutdated)
|
2025-02-18 23:50:54 +00:00
|
|
|
|
|
|
|
// THEN
|
|
|
|
let executableURL = URL(at: "/usr/bin/swift")
|
2025-02-19 00:14:00 +00:00
|
|
|
|
|
|
|
var arguments = if let location {
|
|
|
|
["package", "update", "--package-path", location.pathString]
|
2025-02-18 23:50:54 +00:00
|
|
|
} else {
|
2025-02-19 00:14:00 +00:00
|
|
|
["package", "update"]
|
|
|
|
}
|
|
|
|
|
|
|
|
if checkOutdated {
|
|
|
|
arguments.append("--dry-run")
|
2025-02-18 23:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#expect(terminalService.actions.count == 1)
|
|
|
|
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(arguments: [nil, URL.someCurrentFolder], [TerminalServiceError.unexpected, .output(""), .captured("")])
|
|
|
|
func task(at location: URL?, throws error: TerminalServiceError) async throws {
|
|
|
|
// GIVEN
|
|
|
|
let terminalService = TerminalServiceMock(action: .error(error))
|
2025-02-19 00:14:00 +00:00
|
|
|
let task = UpdateDependenciesTask(terminalService: terminalService)
|
2025-02-18 23:50:54 +00:00
|
|
|
|
|
|
|
// WHEN
|
|
|
|
// THEN
|
|
|
|
await #expect(throws: error) {
|
2025-02-19 00:14:00 +00:00
|
|
|
try await task(at: location, checkOutdated: .random())
|
2025-02-18 23:50:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|