diff --git a/ktor-server/ktor-server-test-host/jvmAndNix/src/io/ktor/server/testing/TestApplicationEngine.kt b/ktor-server/ktor-server-test-host/jvmAndNix/src/io/ktor/server/testing/TestApplicationEngine.kt index f4c43994d1..45153549c4 100644 --- a/ktor-server/ktor-server-test-host/jvmAndNix/src/io/ktor/server/testing/TestApplicationEngine.kt +++ b/ktor-server/ktor-server-test-host/jvmAndNix/src/io/ktor/server/testing/TestApplicationEngine.kt @@ -119,16 +119,19 @@ class TestApplicationEngine( } override suspend fun resolvedConnectors(): List { + if (environment.connectors.isNotEmpty()) { + return environment.connectors + } return listOf( object : EngineConnectorConfig { override val type: ConnectorType = ConnectorType.HTTP - override val host: String = environment.connectors.firstOrNull()?.host ?: "localhost" - override val port: Int = environment.connectors.firstOrNull()?.port ?: 80 + override val host: String = "localhost" + override val port: Int = 80 }, object : EngineConnectorConfig { override val type: ConnectorType = ConnectorType.HTTPS - override val host: String = environment.connectors.firstOrNull()?.host ?: "localhost" - override val port: Int = environment.connectors.firstOrNull()?.port ?: 443 + override val host: String = "localhost" + override val port: Int = 443 } ) } diff --git a/ktor-server/ktor-server-test-host/jvmAndNix/src/io/ktor/server/testing/client/TestHttpClientEngine.kt b/ktor-server/ktor-server-test-host/jvmAndNix/src/io/ktor/server/testing/client/TestHttpClientEngine.kt index 3d046abace..5d6f6ec569 100644 --- a/ktor-server/ktor-server-test-host/jvmAndNix/src/io/ktor/server/testing/client/TestHttpClientEngine.kt +++ b/ktor-server/ktor-server-test-host/jvmAndNix/src/io/ktor/server/testing/client/TestHttpClientEngine.kt @@ -55,7 +55,7 @@ public class TestHttpClientEngine(override val config: TestHttpClientConfig) : H } val testServerCall = with(data) { - runRequest(method, url.fullPath, headers, body, url.protocol) + runRequest(method, url, headers, body, url.protocol) } return with(testServerCall.response) { @@ -65,13 +65,14 @@ public class TestHttpClientEngine(override val config: TestHttpClientConfig) : H private suspend fun runRequest( method: HttpMethod, - url: String, + url: Url, headers: Headers, content: OutgoingContent, protocol: URLProtocol ): TestApplicationCall { return app.handleRequestNonBlocking { - this.uri = url + this.uri = url.fullPath + this.port = url.port this.method = method appendRequestHeaders(headers, content) this.protocol = protocol.name diff --git a/ktor-server/ktor-server-test-host/jvmAndNix/test/TestApplicationTest.kt b/ktor-server/ktor-server-test-host/jvmAndNix/test/TestApplicationTest.kt index e2809f19ad..24fdb3a6e6 100644 --- a/ktor-server/ktor-server-test-host/jvmAndNix/test/TestApplicationTest.kt +++ b/ktor-server/ktor-server-test-host/jvmAndNix/test/TestApplicationTest.kt @@ -12,6 +12,7 @@ import io.ktor.http.* import io.ktor.http.content.* import io.ktor.server.application.* import io.ktor.server.config.* +import io.ktor.server.engine.* import io.ktor.server.plugins.* import io.ktor.server.request.* import io.ktor.server.response.* @@ -279,4 +280,43 @@ class TestApplicationTest { val response = client.get("/boom") assertEquals(HttpStatusCode.InternalServerError, response.status) } + + @Test + fun testConnectors(): Unit = testApplication { + environment { + connector { + port = 8080 + } + connector { + port = 8081 + } + + module { + routing { + port(8080) { + get { + call.respond("8080") + } + } + port(8081) { + get { + call.respond("8081") + } + } + } + } + } + + val response8080 = client.get { + host = "0.0.0.0" + port = 8080 + } + assertEquals("8080", response8080.bodyAsText()) + + val response8081 = client.get { + host = "0.0.0.0" + port = 8081 + } + assertEquals("8081", response8081.bodyAsText()) + } }