Written some test cases for the AppBuilder builder in the test target.

This commit is contained in:
Javier Cicchelli 2025-03-09 21:54:52 +01:00
parent 5656639e5d
commit e866d1da71
4 changed files with 87 additions and 40 deletions

View File

@ -1,10 +1,3 @@
//
// Test.swift
// DocCRepo
//
// Created by Javier Cicchelli on 08/03/2025.
//
import Hummingbird
import HummingbirdTesting
import Testing

View File

@ -1,33 +0,0 @@
import AppLibrary
import Hummingbird
import HummingbirdTesting
import Testing
struct AppTests {
// MARK: Properties
private let arguments = TestArguments()
private let builder = AppBuilder(name: "DocCRepo")
// MARK: Route tests
@Test(arguments: ["/"])
func routes(_ uri: String) async throws {
let app = try await builder(arguments)
try await app.test(.router) { client in
try await client.execute(uri: uri, method: .get) { response in
#expect(response.status == .ok)
#expect(response.body == .empty)
}
}
}
}
// MARK: ByteBuffer+Constants
private extension ByteBuffer {
static let empty = ByteBuffer(string: "")
}

View File

@ -0,0 +1,86 @@
import AppLibrary
import Hummingbird
import HummingbirdTesting
import Testing
@Suite("AppBuilder", .tags(.builder))
struct AppBuilderTests {
// MARK: Properties
private let appBuilder = AppBuilder(
appName: "DoxyTest",
archivesFolder: "Resources/Archives/Test"
)
private let arguments = TestArguments()
// MARK: Route tests
@Test(arguments: zip([String].uris, [HTTPResponse.Status].statuses))
func routes(
uri: String,
expects status: HTTPResponse.Status
) async throws {
let app = try await appBuilder(arguments)
try await app.test(.router) { client in
try await client.execute(
uri: uri,
method: .get
) { response in
#expect(response.status == status)
}
}
}
}
// MARK: - Collection+HTTPResponseStatus
private extension Collection where Element == HTTPResponse.Status {
// MARK: Computed
static var statuses: [Element] {[
.notFound,
.notFound,
.notFound,
.notFound,
.seeOther,
.seeOther,
.notImplemented,
.seeOther,
.seeOther,
.seeOther,
.seeOther,
.notImplemented,
.seeOther,
.seeOther,
]}
}
// MARK: - Collection+String
private extension Collection where Element == String {
// MARK: Computed
static var uris: [Element] {[
"/",
"/index.html",
"/xxx",
"/archives",
"/archives/SomeArchive",
"/archives/SomeArchive/",
"/archives/SomeArchive/index.html",
"/archives/SomeArchive/documentation",
"/archives/SomeArchive/tutorials",
"/archives/SlothCreator",
"/archives/SlothCreator/",
"/archives/SlothCreator/index.html",
"/archives/SlothCreator/documentation",
"/archives/SlothCreator/tutorials",
]}
}

View File

@ -4,6 +4,7 @@ extension Tag {
// MARK: Constants
@Tag static var builder: Tag
@Tag static var enumeration: Tag
@Tag static var middleware: Tag
@Tag static var provider: Tag