Skip to content

Commit

Permalink
refactor(ktor-internal): add uts
Browse files Browse the repository at this point in the history
  • Loading branch information
hanrw committed Aug 24, 2024
1 parent beb8509 commit b68a96d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package com.tddworks.common.network.api.ktor.internal

data class HostPortConnectionConfig(
val protocol: () -> String? = { null },
val host: () -> String = { "" },
val port: () -> Int? = { null },
val host: () -> String,
) : ConnectionConfig
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class HttpClientTest {
val apiClient = createHttpClient(
connectionConfig = HostPortConnectionConfig(
protocol = { "https" },
host = { "some-host" },
port = { 443 }
port = { 443 },
host = { "some-host" }
),
httpClientEngine = mockEngine,
authConfig = AuthConfig(authToken = { "token" }),
Expand All @@ -50,8 +50,8 @@ class HttpClientTest {
val apiClient = createHttpClient(
connectionConfig = HostPortConnectionConfig(
protocol = { "https" },
host = { "some-host" },
port = { 443 }
port = { 443 },
host = { "some-host" }
),
httpClientEngine = mockEngine
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.tddworks.common.network.api.ktor.internal

import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test

class HostPortConnectionConfigTest {

@Test
fun `should return default protocol and port`() {
val config = HostPortConnectionConfig { "example.com" }

assertNull(config.protocol(), "Protocol should default to null")

assertNull(config.port(), "Port should default to null")
}

@Test
fun `should able to specified protocol and port`() {
val protocol: () -> String? = { "http" }
val port: () -> Int? = { 8080 }
val config = HostPortConnectionConfig(
protocol = protocol,
port = port,
host = { "example.com" }
)

assertEquals("http", config.protocol(), "Protocol should be 'http'")
assertEquals(8080, config.port(), "Port should be 8080")
}
}

0 comments on commit b68a96d

Please sign in to comment.