Improved the initializers for the DocCMiddleware type in the library target.

This commit is contained in:
2025-09-25 02:41:52 +02:00
parent 36f14cfb51
commit edeaf219a0
2 changed files with 69 additions and 29 deletions
@@ -72,22 +72,48 @@ private extension DocCMiddlewareTests {
// MARK: Functions
/// Asserts the initialization of a `DocCMiddleware` type.
/// Asserts the public initializer.
/// - Parameters:
/// - configuration: A type that contains the parameters to configure the middleware.
/// - logger: A type that interacts with the logging system.
/// - fileProvider: A type that conforms to the protocol that defines file system interactions, if any.
func assertInit(
configuration: DocCMiddleware.Configuration,
logger: Logger = .test(),
fileProvider: (any FileProvider)? = nil
configuration: DocCMiddleware<LocalFileSystem>.Configuration,
logger: Logger = .test()
) {
// GIVEN
// WHEN
let middleware = DocCMiddleware(
configuration: configuration,
logger: logger,
fileProvider: fileProvider
logger: logger
)
// THEN
#expect(middleware.configuration.folderRoot == configuration.folderRoot)
#expect(middleware.configuration.uriRoot == configuration.uriRoot)
#expect(middleware.configuration.threadPool === configuration.threadPool)
#expect(middleware.logger.label == logger.label)
#expect(middleware.logger.logLevel == logger.logLevel)
#expect(type(of:middleware.fileProvider) == LocalFileSystem.self)
}
/// Asserts the internal initializer with a concrete file provider type.
/// - Parameters:
/// - configuration: A type that contains the parameters to configure the middleware.
/// - logger: A type that interacts with the logging system.
/// - fileProvider: A type that conforms to the protocol that defines file system interactions, if any.
func assertInit<FileSystemProvider: FileProvider>(
configuration: DocCMiddleware<FileSystemProvider>.Configuration,
logger: Logger = .test(),
fileProvider: FileSystemProvider
) {
// GIVEN
// WHEN
let middleware = DocCMiddleware(
configuration: configuration,
fileProvider: fileProvider,
logger: logger
)
// THEN
@@ -98,11 +124,7 @@ private extension DocCMiddlewareTests {
#expect(middleware.logger.label == logger.label)
#expect(middleware.logger.logLevel == logger.logLevel)
if let fileProvider {
#expect(type(of:middleware.fileProvider) == type(of: fileProvider))
} else {
#expect(middleware.fileProvider is LocalFileSystem)
}
#expect(type(of:middleware.fileProvider) == FileSystemProvider.self)
}
}