dodalovic
05/10/2022, 5:48 AMexternalServices
mocking with the 2.0.1
ktor version, but it doesn't kick in:
externalServices {
hosts("<https://api.sendinblue.com>") {
install(ContentNegotiation) {
json()
}
routing {
post("v3/smtp/email") {
call.response.status(HttpStatusCode.OK)
}
}
}
}
and then I call the API:
val response = <http://httpClient.post|httpClient.post>("<https://api.sendinblue.com/v3/smtp/email>") {
accept(ContentType.Application.Json)
contentType(ContentType.Application.Json)
header("api-key", apiKey)
But this mocking doesn't kick-in, rather the real thing.Aleksei Tirman [JB]
05/10/2022, 8:38 AM@Test
fun test() = testApplication {
externalServices {
hosts("<https://api.sendinblue.com>") {
install(ContentNegotiation) {
json()
}
routing {
post("v3/smtp/email") {
call.response.status(HttpStatusCode.OK)
}
}
}
}
val response = <http://client.post|client.post>("<https://api.sendinblue.com/v3/smtp/email>") {
header("api-key", "123")
}
assertEquals(HttpStatusCode.OK, response.status)
}
Could you please share a complete test to reproduce your problem?dodalovic
05/10/2022, 9:06 AMsetup
at the beginning of my @Test methodsAleksei Tirman [JB]
05/10/2022, 9:11 AMtestApplication
you have the client
property that you can use for testing. Also, you can create a new client with createClient
method. My test passes with your setup
method too.dodalovic
05/10/2022, 9:14 AMAleksei Tirman [JB]
05/10/2022, 9:17 AMdodalovic
05/10/2022, 9:30 AM