Skip to content

Commit

Permalink
test multiple invocations of rawBody
Browse files Browse the repository at this point in the history
  • Loading branch information
angryziber committed Jan 15, 2025
1 parent 0886386 commit 01721b0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion server/test/klite/HttpExchangeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import klite.Cookie.SameSite.Strict
import klite.RequestMethod.POST
import klite.StatusCode.Companion.Created
import klite.StatusCode.Companion.OK
import org.junit.jupiter.api.Test
Expand All @@ -16,10 +17,12 @@ import kotlin.reflect.typeOf

class HttpExchangeTest {
abstract class MockableHttpExchange: OriginalHttpExchange()
val requestStream = "Input".byteInputStream()
val original = mockk<MockableHttpExchange>(relaxed = true) {
every { requestMethod } returns "POST"
every { requestURI } returns URI("/hello?hello=world")
every { responseCode } returns -1
every { requestBody } returns requestStream
}
val bodyRenderer = mockk<BodyRenderer>()
val customParser = mockk<BodyParser> {
Expand All @@ -32,7 +35,7 @@ class HttpExchangeTest {
val exchange = HttpExchange(original, routerConfig, null, "req-id")

@Test fun path() {
expect(exchange.method).toEqual(RequestMethod.POST)
expect(exchange.method).toEqual(POST)
expect(exchange.path).toEqual("/hello")
}

Expand All @@ -41,6 +44,11 @@ class HttpExchangeTest {
expect(exchange.queryParams).toEqual(mapOf("hello" to "world"))
}

@Test fun rawBody() {
expect(exchange.rawBody).toEqual("Input")
expect(exchange.rawBody).toEqual(exchange.rawBody)
}

@Test fun fullUrl() {
every { exchange.host } returns "localhost:8080"
expect(exchange.fullUrl).toEqual(URI("http://localhost:8080/hello?hello=world"))
Expand Down

0 comments on commit 01721b0

Please sign in to comment.