feat: Initial commit
This commit is contained in:
62
Tests/CliClientTests/CliClientTests.swift
Normal file
62
Tests/CliClientTests/CliClientTests.swift
Normal file
@@ -0,0 +1,62 @@
|
||||
@_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: .trace) {
|
||||
$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: "instance"] = "\(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: "instance"] = "\(key)"
|
||||
$0.logger.logLevel = logLevel
|
||||
setupDependencies(&$0)
|
||||
} operation: {
|
||||
try operation()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user