Closed mathiasbn closed 2 years ago
See testStatusMappingWithRoutes
: it is passing now
Is it fixed now?
I'm not working with that project anymore, but I will ping the guys
The test passes because it explicitly returns 404. Same with the internal server error. If I am not mistaken then StatusPage
installed on Application
will also handle the implicit ones also (ie. page not founds if not routed). Consider the following test:
@Test
fun testStatusMappingWithRoutes1() {
withTestApplication {
application.install(StatusPages) {
status(HttpStatusCode.NotFound) { call.respondText("Not Found Application", status = HttpStatusCode.NotFound) }
exception<Throwable> { call.respondText("Internal Server Error Application", status = HttpStatusCode.InternalServerError) }
}
application.routing {
route("/foo") {
route("/wee") {
handle {
throw Exception()
}
}
install(StatusPages) {
status(HttpStatusCode.NotFound) { call.respondText("Not Found Route", status = HttpStatusCode.NotFound) }
exception<Throwable> { call.respondText("Internal Server Error Route", status = HttpStatusCode.InternalServerError) }
}
}
}
listOf("/foo", "/foo/1").forEach { path ->
handleRequest(HttpMethod.Get, path).let { call ->
assertEquals(HttpStatusCode.NotFound, call.response.status())
assertEquals("Not Found Route", call.response.content)
}
}
handleRequest(HttpMethod.Get, "/foo/wee").let { call ->
assertEquals(HttpStatusCode.InternalServerError, call.response.status())
assertEquals("Internal Server Error Route", call.response.content)
}
}
}
It currently fails with a null
statuscode but in a real embedded server I would except it to fail with "Not Found Application" != "Not Found Route".
This issue has been automatically marked as stale because it has not had recent activity.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
Obsolete with new testing API in 2.0.0
Given that ktor now has
Introduce send and receive pipelines on all levels
(commit msg). Wouldn't this test make sense (it fails):It's a copy/paste of testStatusMapping test, but with statuspages installed under a route pipeline (edited)