ktorio / ktor

Framework for quickly creating connected applications in Kotlin with minimal effort
https://ktor.io
Apache License 2.0
12.53k stars 1.02k forks source link

Question about testing status pages #1090

Closed master-bytes-krafter closed 3 years ago

master-bytes-krafter commented 5 years ago

Ktor Version

1.1.4

Ktor Engine Used(client or server and name)

Test engine / Netty

JVM Version, Operating System and Relevant Context

openjdk 11

Feedback

Hello, First of all nice work with your framework. I have one question though: i use status pages to handle some custom content for some specific statuses. It works when i run an actual Netty engine. Now i do some testing with the test application engine, and i notice that status entries in status pages behave weirdly and my tests fail.

Example:

status(HttpStatusCode.NotFound, HttpStatusCode.UnsupportedMediaType) {
            call.respond(it, someJsonError)
}

The test is simple

// TODO why do we need this ?
//      application.intercept(ApplicationCallPipeline.Call) {
//          call.respond(HttpStatusCode.NotFound)
//      }

        describe("making an unknown route request") {
            with(handleRequest(HttpMethod.Get, "/unknown-route")) {
                it("responds with expected default error message") {
                    response.status() `should equal` HttpStatusCode.NotFound
// response status is null ??
                }
}

Now this test passes when i uncomment those lines, but why do i need to do it this way ? shouldn'it be handled by my actual application logic ? I can uncomment those lines for 404 testing stuff but it annoys me to do so for 415 testing code that fails in similar way. Can you please advise ?

Stexxe commented 3 years ago

That was a buggy behavior of the test application engine and the StatusPages feature interaction. You can observe the expected (without those lines) behavior with Ktor 1.5.3.