Skip to content

Commit 34baf1f

Browse files
committed
Example of struggling generic controller content.
1 parent a62f02b commit 34baf1f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Tests/HummingbirdRouterTests/ControllerTests.swift

+33
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,37 @@ final class ControllerTests: XCTestCase {
4242
}
4343
}
4444
}
45+
46+
func testRouterControllerWithGenericChild() async throws {
47+
struct ChildController: RouterController {
48+
typealias Context = BasicRouterRequestContext
49+
var body: some RouterMiddleware<Context> {
50+
Get("child") { _,_ in "child" }
51+
}
52+
}
53+
54+
struct ParentController<Child: RouterController>: RouterController where Child.Context: RouterRequestContext {
55+
typealias Context = Child.Context
56+
@MiddlewareFixedTypeBuilder<Request, Response, Context> var child: () -> Child
57+
58+
var body: some RouterMiddleware<Context> {
59+
RouteGroup("parent") {
60+
child()
61+
}
62+
}
63+
}
64+
65+
let router = RouterBuilder(context: BasicRouterRequestContext.self) {
66+
ParentController {
67+
ChildController()
68+
}
69+
}
70+
71+
let app = Application(responder: router)
72+
try await app.test(.router) { client in
73+
try await client.execute(uri: "/parent/child", method: .get) {
74+
XCTAssertEqual(String(buffer: $0.body), "child")
75+
}
76+
}
77+
}
4578
}

0 commit comments

Comments
 (0)