Issue#13 Use any available port for mockwebserver in core tests

This commit is contained in:
Gergely Hegedus 2022-01-26 22:35:27 +02:00
parent 8d33f77cec
commit 9bdcaddb0c
2 changed files with 4 additions and 7 deletions

View file

@ -20,13 +20,13 @@ class MockServerScenarioSetup internal constructor(
var clientCertificates: HandshakeCertificates? = null
private set
fun start(useHttps: Boolean) {
fun start(useHttps: Boolean): String {
val mockWebServer = MockWebServer().also { this.mockWebServer = it }
if (useHttps) {
clientCertificates = mockWebServer.useHttps()
}
mockWebServer.dispatcher = networkDispatcher
mockWebServer.start(InetAddress.getLocalHost(), PORT)
return mockWebServer.url("/").toString()
}
/**
@ -69,9 +69,6 @@ class MockServerScenarioSetup internal constructor(
}
companion object {
const val PORT: Int = 7335
val HTTP_BASE_URL get() = "http://${InetAddress.getLocalHost().canonicalHostName}"
val HTTPS_BASE_URL get() = "https://localhost"
private fun MockWebServer.useHttps(): HandshakeCertificates {
val localhost = InetAddress.getByName("localhost").canonicalHostName