Matthew
05/20/2025, 7:37 AMhandleRequest function is replaced with the client.get ". As I understand it the new pattern is pretty much like booting up the app which exposes the endpoint then you call it with a HTTP client as a test. The old pattern allowed you to "peek" into the Ktor application server. The tests I've inherited used this "peeking" ability to check that the cookie + session management is working as expected. This is because our application has used the Ktor Session/Cookie plugins to wire in Pac4j library. The Pac4j code seems to implement a bunch of interfaces. So the tests are proving that everything is wired up correctly. The test assertions all relied on having access to the ApplicationCall object (returned via handleRequest) but now we don't have access to it. Is there any "backdoor" that I can peek into the spun up Ktor application and intercept the request to get the ApplicationCall so that I can avoid having to refactor these tests? Long term I plan to refactor them to test the behaviour of the API but it's a huge task and something I can't tackle now.RJ Garcia
05/20/2025, 4:10 PMMatthew
05/20/2025, 8:00 PMMatthew
05/20/2025, 8:00 PMAleksei Tirman [JB]
05/21/2025, 8:48 AMApplicationCall object from the HttpResponse . For example:
val response = client.get("/")
val call = response.callMatthew
05/21/2025, 9:00 AMHttpClientCallMatthew
05/21/2025, 9:01 AMvar callSpy: ApplicationCall? = null
testApplication {
application {
install(createApplicationPlugin(name="requestSpy") {
onCall { callSpy = it }
})
}
runBlocking {
client.get(uri, requestModifier)
callSpy!!.responseTest()
}
}Aleksei Tirman [JB]
05/21/2025, 9:05 AM