63 lines
1.5 KiB
Swift
63 lines
1.5 KiB
Swift
@_spi(Internal) import CliClient
|
|
import Dependencies
|
|
import ShellClient
|
|
import Testing
|
|
|
|
@Test
|
|
func testFindConfigPaths() throws {
|
|
try withTestLogger(key: "testFindConfigPaths") {
|
|
$0.fileClient = .liveValue
|
|
} operation: {
|
|
@Dependency(\.logger) var logger
|
|
let urls = try findConfigurationFiles()
|
|
logger.debug("urls: \(urls)")
|
|
// #expect(urls.count == 1)
|
|
}
|
|
}
|
|
|
|
@Test
|
|
func loadConfiguration() throws {
|
|
try withTestLogger(key: "loadConfiguration", logLevel: .debug) {
|
|
$0.cliClient = .liveValue
|
|
$0.fileClient = .liveValue
|
|
} operation: {
|
|
@Dependency(\.cliClient) var client
|
|
@Dependency(\.logger) var logger
|
|
let config = try client.loadConfiguration()
|
|
logger.debug("\(config)")
|
|
#expect(config.playbookDir != nil)
|
|
}
|
|
}
|
|
|
|
func withTestLogger(
|
|
key: String,
|
|
label: String = "CliClientTests",
|
|
logLevel: Logger.Level = .debug,
|
|
operation: @escaping @Sendable () throws -> Void
|
|
) rethrows {
|
|
try withDependencies {
|
|
$0.logger = .init(label: label)
|
|
$0.logger[metadataKey: "test"] = "\(key)"
|
|
$0.logger.logLevel = logLevel
|
|
} operation: {
|
|
try operation()
|
|
}
|
|
}
|
|
|
|
func withTestLogger(
|
|
key: String,
|
|
label: String = "CliClientTests",
|
|
logLevel: Logger.Level = .debug,
|
|
dependencies setupDependencies: @escaping (inout DependencyValues) -> Void,
|
|
operation: @escaping @Sendable () throws -> Void
|
|
) rethrows {
|
|
try withDependencies {
|
|
$0.logger = .init(label: label)
|
|
$0.logger[metadataKey: "test"] = "\(key)"
|
|
$0.logger.logLevel = logLevel
|
|
setupDependencies(&$0)
|
|
} operation: {
|
|
try operation()
|
|
}
|
|
}
|