I'm using ktor cli. Is there a way to create a fak...
# ktor
b
I'm using ktor cli. Is there a way to create a fake of
HttpResponse
? I would like to use it to test a function that receives an
HttpResponse
and returns a
Result
. I know that I could use
MockEngine
to create a
HttpResponse
but it feels too much. I'm assuming that
HttpResponse
is something similar as
Response
in
Retrofit
. And there I could use
Response.error()
or
Response.success()
to create fakes.
a
Unfortunately, there is no easy way to do it. Here you can find a way of doing it.
b
😢 yes I found that but I don't want to use mockk or mockito... I tried to create a fake myself but it's not possible to create a fake of
HttpClientCall
because its constructor is
internal
.
👌 1
j
I had a problem where one of the possible solutions was that
HttpClientCall
was not internal, @Aleksei Tirman [JB] is it possible to change it to public?
a
@e5l
e
Could you log an issue? It's possible to fix before 2.0.0
b
_< I make it work with mockk but now my first test needs 2 seconds to finish. I'll open an issue to find a better way,
Copy code
internal inline fun <reified T : Any> fakeHttpResponse(
    status: HttpStatusCode,
    value: T,
): HttpResponse {
    return mockk {
        every { this@mockk.status } returns status
        coEvery { receive<T>() } returns value
    }
}
j
Can you share the issue here @Brais Gabin ?
b
I'll
j
Please add the possibility to change the visibility to HttpClientCall too
b
Yes, I'll add a link to this converation too
j
thank you 🙏
e
Thanks
j
Additionally, there are internal functions to create those objects too, so maybe the constructor can still be private/internal but those functions should be public instead
your welcome!