feat: Adds vault client
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
@_spi(Internal) @_exported import CommandClient
|
||||
@_exported import Dependencies
|
||||
import Foundation
|
||||
import Logging
|
||||
@@ -7,6 +8,35 @@ public protocol TestCase {}
|
||||
|
||||
public extension TestCase {
|
||||
|
||||
static var loggingOptions: LoggingOptions {
|
||||
let levelString = ProcessInfo.processInfo.environment["LOG_LEVEL"] ?? "debug"
|
||||
let logLevel = Logger.Level(rawValue: levelString) ?? .debug
|
||||
return .init(commandName: "\(Self.self)", logLevel: logLevel)
|
||||
}
|
||||
|
||||
func withCapturingCommandClient(
|
||||
_ key: String,
|
||||
dependencies setupDependencies: @escaping (inout DependencyValues) -> Void = { _ in },
|
||||
run: @Sendable @escaping () async throws -> Void,
|
||||
assert: @Sendable @escaping (CommandClient.RunCommandOptions) -> Void
|
||||
) async throws {
|
||||
let captured = CommandClient.CapturingClient()
|
||||
try await withDependencies {
|
||||
$0.commandClient = .capturing(captured)
|
||||
setupDependencies(&$0)
|
||||
} operation: {
|
||||
try await Self.loggingOptions.withLogger {
|
||||
try await run()
|
||||
|
||||
guard let options = await captured.options else {
|
||||
throw TestSupportError.optionsNotSet
|
||||
}
|
||||
|
||||
assert(options)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func withTestLogger(
|
||||
key: String,
|
||||
logLevel: Logger.Level = .debug,
|
||||
@@ -131,3 +161,7 @@ public func withTestLogger(
|
||||
try await operation()
|
||||
}
|
||||
}
|
||||
|
||||
enum TestSupportError: Error {
|
||||
case optionsNotSet
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user