-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/allow-random-port' of github.com:marschwar/klite
- Loading branch information
Showing
5 changed files
with
44 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package klite | ||
|
||
import ch.tutteli.atrium.api.fluent.en_GB.toBeGreaterThan | ||
import ch.tutteli.atrium.api.fluent.en_GB.toEqual | ||
import ch.tutteli.atrium.api.verbs.expect | ||
import org.junit.jupiter.api.Test | ||
import java.net.InetSocketAddress | ||
import kotlin.random.Random | ||
|
||
class ServerTest { | ||
@Test fun `bind server to any available port`() { | ||
val server = Server(listen = InetSocketAddress( 0)) | ||
try { | ||
server.start(gracefulStopDelaySec = -1) | ||
expect(server.listen.port).toBeGreaterThan(0) | ||
} finally { | ||
server.stop(0) | ||
} | ||
} | ||
|
||
@Test fun `bind server to custom port`() { | ||
val port = Random.nextInt(1024, 65535) + 1 | ||
val server = Server(listen = InetSocketAddress(port)) | ||
try { | ||
server.start(gracefulStopDelaySec = -1) | ||
expect(server.listen.port).toEqual(port) | ||
} finally { | ||
server.stop(0) | ||
} | ||
} | ||
|
||
@Test fun `expose bound address if server is not started`() { | ||
expect(Server().listen.port).toEqual(8080) | ||
} | ||
} | ||
|