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

TODO Hunting. Added ticks to listed selected protocol and features on banner #431

Merged
merged 3 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions port_http_server/src/main/kotlin/Server.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ data class Server(
log.info { "Server stopped" }
}

private fun createBanner(startUpTimestamp: Long): String {
internal fun createBanner(startUpTimestamp: Long): String {

// TODO Print passed options values
// TODO Use emojis (like rocket launch... just for fun)

val heap = getMemoryMXBean().heapMemoryUsage
val jvmMemory = "%,d".format(heap.init / 1024)
Expand All @@ -142,8 +145,14 @@ data class Server(
val binding = "$scheme://$hostName:$runtimePort"

val serverAdapterValue = "$BOLD$CYAN$portName$RESET"
val protocols = adapter.supportedProtocols().joinToString("$RESET, $CYAN", CYAN, RESET)
val features = adapter.supportedFeatures().joinToString("$RESET, $CYAN", CYAN, RESET)
val protocols = adapter.supportedProtocols()
.joinToString("$RESET, $CYAN", CYAN, RESET) { p ->
if (p == settings.protocol) "✅ $p" else "$p"
}
val features = adapter.supportedFeatures()
.joinToString("$RESET, $CYAN", CYAN, RESET) { f ->
if (settings.features.contains(f)) "✅ $f" else "$f"
}
val options = adapter.supportedOptions().joinToString("$RESET, $CYAN", CYAN, RESET)

val hostnameValue = "$BLUE$hostname$RESET"
Expand Down
23 changes: 23 additions & 0 deletions port_http_server/src/test/kotlin/ServerTest.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.hexagonkt.http.server

import com.hexagonkt.http.server.ServerFeature.SESSIONS
import com.hexagonkt.serialization.JacksonMapper
import com.hexagonkt.serialization.Json
import com.hexagonkt.serialization.SerializationManager
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS
import kotlin.test.assertContains
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertFalse
import java.net.InetAddress.getByName as address

@TestInstance(PER_CLASS)
Expand Down Expand Up @@ -44,4 +48,23 @@ internal class ServerTest {
assert(server.started())
assert(server.runtimePort == 12345)
}

@Test fun `Banner creation`() {
val bannerPrefix = "Test Banner"
val serverSettings = ServerSettings(
address("localhost"),
12345,
banner = bannerPrefix,
features = setOf(SESSIONS)
)
val server = serve(serverSettings, VoidAdapter) {}

val now = System.currentTimeMillis()
val createdBanner = server.createBanner(now)

assertEquals(bannerPrefix, createdBanner.lines()[0].trimIndent())
assertContains(createdBanner, "✅ HTTP" )
assertFalse(createdBanner.contains("✅ HTTPS"))
assertContains(createdBanner, "✅ SESSIONS" )
}
}