Integrated the DocCMiddleware.Configuration type to the DocCMiddleware type in the library target.
This commit is contained in:
@@ -14,35 +14,53 @@ import Testing
|
||||
|
||||
import struct Hummingbird.LocalFileSystem
|
||||
import struct Logging.Logger
|
||||
|
||||
import protocol Hummingbird.FileProvider
|
||||
|
||||
@testable import DocCMiddleware
|
||||
@testable import struct DocCMiddleware.DocCMiddleware
|
||||
|
||||
@Suite("DocC Middleware")
|
||||
@Suite("DocC Middleware", .tags(.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
|
||||
func `initialize with URI and folder paths`() {
|
||||
assertInit(configuration: .init(
|
||||
uriRoot: "/path/to/documentation",
|
||||
folderRoot: "/location/docc/documentation"
|
||||
))
|
||||
}
|
||||
|
||||
@Test(.tags(.initializer))
|
||||
func `initialize with type that conforms to the FileProvider protocol`() {
|
||||
// GIVEN
|
||||
assertInit(fileProvider: FileProviderStub())
|
||||
@Test
|
||||
func `initialize with URI path and type that conforms to the FileProvider protocol`() {
|
||||
assertInit(
|
||||
configuration: .init(
|
||||
uriRoot: "/path/to/documentation",
|
||||
folderRoot: .empty
|
||||
),
|
||||
fileProvider: FileProviderStub()
|
||||
)
|
||||
}
|
||||
#else
|
||||
@Test("initialize with path to root", .tags(.initializer))
|
||||
func initWithRootPath() {
|
||||
assertInit(pathToRoot: "/path/to/root/docc/documentation")
|
||||
@Test("initialize with URI and folder paths")
|
||||
func initWithURIAndFolderPaths() {
|
||||
assertInit(configuration: .init(
|
||||
uriRoot: "/path/to/documentation",
|
||||
folderRoot: "/location/docc/documentation"
|
||||
))
|
||||
}
|
||||
|
||||
@Test("initialize with type that conforms to the FileProvider protocol", .tags(.initializer))
|
||||
func initWithFileProviderType() {
|
||||
assertInit(fileProvider: FileProviderStub())
|
||||
@Test("initialize with type that conforms to the FileProvider protocol")
|
||||
func initWithURIPathAndFileProviderType() {
|
||||
assertInit(
|
||||
configuration: .init(
|
||||
uriRoot: "/path/to/documentation",
|
||||
folderRoot: .empty
|
||||
),
|
||||
fileProvider: FileProviderStub()
|
||||
)
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -54,46 +72,37 @@ private extension DocCMiddlewareTests {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
/// Asserts the initialization of a `DocCMiddleware` type with a root path in the file system.
|
||||
/// Asserts the initialization of a `DocCMiddleware` type.
|
||||
/// - Parameters:
|
||||
/// - pathToRoot: A path to the root `DocC` documentation containers.
|
||||
/// - 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(
|
||||
pathToRoot: String,
|
||||
logger: Logger = .test
|
||||
configuration: DocCMiddleware.Configuration,
|
||||
logger: Logger = .test,
|
||||
fileProvider: (any FileProvider)? = nil
|
||||
) {
|
||||
// GIVEN
|
||||
// WHEN
|
||||
let middleware = DocCMiddleware(
|
||||
pathToRoot: pathToRoot,
|
||||
logger: logger
|
||||
configuration: configuration,
|
||||
logger: logger,
|
||||
fileProvider: fileProvider
|
||||
)
|
||||
|
||||
// THEN
|
||||
#expect(middleware.fileProvider is LocalFileSystem)
|
||||
#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)
|
||||
}
|
||||
|
||||
/// 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)
|
||||
if let fileProvider {
|
||||
#expect(type(of:middleware.fileProvider) == type(of: fileProvider))
|
||||
} else {
|
||||
#expect(middleware.fileProvider is LocalFileSystem)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ extension Tag {
|
||||
|
||||
/// Tag that indicate a test case for an enumeration type.
|
||||
@Tag static var enumeration: Self
|
||||
/// Tag that indicate a test case for a type initialization.
|
||||
@Tag static var initializer: Self
|
||||
/// Tag that indicate a test case for a middleware type.
|
||||
@Tag static var middleware: Self
|
||||
/// Tag that indicate a test case for a use case type.
|
||||
@Tag static var useCase: Self
|
||||
|
||||
|
||||
Reference in New Issue
Block a user