Replaced the "test" static constant for the Logger+Constants extension in the test target with a "test(level: handler: )" function for the Logger+Helpers extension.
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
//
|
||||
// ===----------------------------------------------------------------------===
|
||||
|
||||
/// A type that provides a relative path representation.
|
||||
/// A protocol that provides a relative path representation.
|
||||
protocol Pathable {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
@@ -79,7 +79,7 @@ private extension LoggerMetadata_HelpersTests {
|
||||
redirect: String? = nil
|
||||
) {
|
||||
// GIVEN
|
||||
let logger: Logger = .test
|
||||
let logger: Logger = .test()
|
||||
let context: MockRequestContext = .init(logger: logger)
|
||||
let request: Request = .test(method: method)
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
|
||||
import Testing
|
||||
|
||||
import protocol Hummingbird.FileProvider
|
||||
|
||||
import struct Hummingbird.LocalFileSystem
|
||||
import struct Logging.Logger
|
||||
|
||||
import protocol Hummingbird.FileProvider
|
||||
|
||||
@testable import struct DocCMiddleware.DocCMiddleware
|
||||
|
||||
@Suite("DocC Middleware", .tags(.middleware))
|
||||
@@ -79,7 +79,7 @@ private extension DocCMiddlewareTests {
|
||||
/// - fileProvider: A type that conforms to the protocol that defines file system interactions, if any.
|
||||
func assertInit(
|
||||
configuration: DocCMiddleware.Configuration,
|
||||
logger: Logger = .test,
|
||||
logger: Logger = .test(),
|
||||
fileProvider: (any FileProvider)? = nil
|
||||
) {
|
||||
// GIVEN
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
// ===----------------------------------------------------------------------===
|
||||
//
|
||||
// This source file is part of the Hummingbird DocC Middleware open source project
|
||||
//
|
||||
// Copyright (c) 2025 Röck+Cöde VoF. and the Hummingbird DocC Middleware project authors
|
||||
// Licensed under the EUPL 1.2 or later.
|
||||
//
|
||||
// See LICENSE for license information
|
||||
// See CONTRIBUTORS for the list of Hummingbird DocC Middleware project authors
|
||||
//
|
||||
// ===----------------------------------------------------------------------===
|
||||
|
||||
import Foundation
|
||||
import Logging
|
||||
import Testing
|
||||
|
||||
extension Logger {
|
||||
|
||||
// MARK: Constants
|
||||
|
||||
/// Creates a logger instance that is ready to use in test cases.
|
||||
static let test: Self = {
|
||||
var logger = Logger(label: "test.hummingbird-docc-middleware.logger")
|
||||
|
||||
logger.logLevel = try! #require(Logger.Level.allCases.randomElement())
|
||||
|
||||
logger[metadataKey: "hb.request.id"] = "\(UUID().uuidString)"
|
||||
|
||||
return logger
|
||||
}()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// ===----------------------------------------------------------------------===
|
||||
//
|
||||
// This source file is part of the Hummingbird DocC Middleware open source project
|
||||
//
|
||||
// Copyright (c) 2025 Röck+Cöde VoF. and the Hummingbird DocC Middleware project authors
|
||||
// Licensed under the EUPL 1.2 or later.
|
||||
//
|
||||
// See LICENSE for license information
|
||||
// See CONTRIBUTORS for the list of Hummingbird DocC Middleware project authors
|
||||
//
|
||||
// ===----------------------------------------------------------------------===
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
|
||||
import protocol Logging.LogHandler
|
||||
|
||||
import struct Logging.Logger
|
||||
|
||||
extension Logger {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
/// Generates a logger instance that is ready to use in test cases.
|
||||
/// - Parameters:
|
||||
/// - level: A logger level, if any.
|
||||
/// - handler: A custom log handler, if any.
|
||||
/// - Returns: A generated logger instance ready to use in test cases.
|
||||
static func test(
|
||||
level: Logger.Level? = nil,
|
||||
handler: (any LogHandler)? = nil
|
||||
) -> Self {
|
||||
var logger: Logger = if let handler {
|
||||
.init(label: .loggerLabel) { _ in handler }
|
||||
} else {
|
||||
.init(label: .loggerLabel)
|
||||
}
|
||||
|
||||
logger.logLevel = if let level {
|
||||
level
|
||||
} else {
|
||||
try! #require(Logger.Level.allCases.randomElement())
|
||||
}
|
||||
|
||||
logger[metadataKey: "hb.request.id"] = "\(UUID().uuidString)"
|
||||
|
||||
return logger
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
private extension String {
|
||||
/// A label to assign to a test logger instance.
|
||||
static let loggerLabel = "test.hummingbird-docc-middleware.logger"
|
||||
}
|
||||
Reference in New Issue
Block a user