Открыть боковую панель
Aurora OS
Kotlin Multiplatform
Libraries
ktor
Коммиты
82eaa1e8
Не подтверждена
Коммит
82eaa1e8
создал
Сен 27, 2022
по автору
Rustam
Зафиксировано автором
GitHub
Сен 27, 2022
Просмотр файлов
KTOR-4875 Fixed respecting connectors port in testApplication (#3169)
владелец
24d59f00
Изменения
3
Скрыть пробелы
Построчно
Рядом
ktor-server/ktor-server-test-host/jvmAndNix/src/io/ktor/server/testing/TestApplicationEngine.kt
Просмотр файла @
82eaa1e8
...
...
@@ -119,16 +119,19 @@ class TestApplicationEngine(
}
override
suspend
fun
resolvedConnectors
():
List
<
EngineConnectorConfig
>
{
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
}
)
}
...
...
ktor-server/ktor-server-test-host/jvmAndNix/src/io/ktor/server/testing/client/TestHttpClientEngine.kt
Просмотр файла @
82eaa1e8
...
...
@@ -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
...
...
ktor-server/ktor-server-test-host/jvmAndNix/test/TestApplicationTest.kt
Просмотр файла @
82eaa1e8
...
...
@@ -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
())
}
}
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать