Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApplicationTest compile errors if MockHttpEngine selected #12

Open
robstoll opened this issue May 16, 2019 · 1 comment
Open

ApplicationTest compile errors if MockHttpEngine selected #12

robstoll opened this issue May 16, 2019 · 1 comment

Comments

@robstoll
Copy link
Contributor

There are several compile errors in ApplicationTest when one chooses MockHttpEngine as feature. I am not sure, it seems to me the generated code is completely outdated.

@robstoll
Copy link
Contributor Author

Also the example here seems to be wrong:
https://ktor.io/clients/http-client/testing.html

robstoll added a commit to robstoll/ktor-init-tools that referenced this issue May 16, 2019
I have no idea in which version the change was introduced, maybe I also made a mistake in translating the code into the generation (only have not tested it, inserted it via web form). In the end the testClientMock function should look as follows (that one is tested)
```
@test
fun testClientMock() {
    runBlocking {
        val client = HttpClient(MockEngine) {
            engine {
                addHandler { request ->
                    @UseExperimental(InternalAPI::class)
                    when (request.url.encodedPath) {
                        "/" -> respond(
                            ByteReadChannel(byteArrayOf(1, 2, 3)),
                            headers = headersOf("X-MyHeader", "MyValue")
                        )
                        else -> respond("Not Found ${request.url.encodedPath}", HttpStatusCode.NotFound)
                    }
                }
            }
            expectSuccess = false
        }
        assertEquals(byteArrayOf(1, 2, 3).toList(), client.get<ByteArray>("/").toList())
        assertEquals("MyValue", client.call("/").response.headers["X-MyHeader"])
        assertEquals("Not Found other/path", client.get<String>("/other/path"))
    }
}
```
Notice the `@UseExperimental(InternalAPI::class)` is this really the only way?
cy6erGn0m pushed a commit that referenced this issue Jun 18, 2019
fix for #12, not tested tough (via web)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant