Files
hummingbird-docc/Tests/DocCMiddleware/Tests/Public/Middlewares/DocCMiddlewareTests.swift
T

100 lines
3.0 KiB
Swift

// ===----------------------------------------------------------------------===
//
// 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 Testing
import struct Hummingbird.LocalFileSystem
import struct Logging.Logger
import protocol Hummingbird.FileProvider
@testable import DocCMiddleware
@Suite("DocC Middleware")
struct DocCMiddlewareTests {
// MARK: Initializers tests
#if swift(>=6.2)
@Test(.tags(.initializer))
func `initialize with path to root`() {
assertInit(pathToRoot: "/path/to/root/docc/documentation")
}
@Test(.tags(.initializer))
func `initialize with type that conforms to the FileProvider protocol`() {
// GIVEN
assertInit(fileProvider: FileProviderStub())
}
#else
@Test("initialize with path to root", .tags(.initializer))
func initWithRootPath() {
assertInit(pathToRoot: "/path/to/root/docc/documentation")
}
@Test("initialize with type that conforms to the FileProvider protocol", .tags(.initializer))
func initWithFileProviderType() {
assertInit(fileProvider: FileProviderStub())
}
#endif
}
// MARK: - Assertions
private extension DocCMiddlewareTests {
// MARK: Functions
/// Asserts the initialization of a `DocCMiddleware` type with a root path in the file system.
/// - Parameters:
/// - pathToRoot: A path to the root `DocC` documentation containers.
/// - logger: A type that interacts with the logging system.
func assertInit(
pathToRoot: String,
logger: Logger = .test
) {
// GIVEN
// WHEN
let middleware = DocCMiddleware(
pathToRoot: pathToRoot,
logger: logger
)
// THEN
#expect(middleware.fileProvider is LocalFileSystem)
#expect(middleware.logger.label == logger.label)
#expect(middleware.logger.logLevel == logger.logLevel)
}
/// Asserts the initialization of a `DocCMiddleware` type with a type that conforms to the `FileProvider` protocol.
/// - Parameters:
/// - fileProvider: A type that conforms to the protocol that defines file system interactions.
/// - logger: A type that interacts with the logging system.
func assertInit(
fileProvider: any FileProvider,
logger: Logger = .test
) {
// GIVEN
// WHEN
let middleware = DocCMiddleware(
fileProvider: fileProvider,
logger: logger
)
// THEN
#expect(type(of:middleware.fileProvider) == type(of: fileProvider))
#expect(middleware.logger.label == logger.label)
#expect(middleware.logger.logLevel == logger.logLevel)
}
}