Skip to content

Commit

Permalink
Test ALL log level
Browse files Browse the repository at this point in the history
  • Loading branch information
Stexxe committed Dec 20, 2024
1 parent 1b8416f commit 65bc390
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public val Logging: ClientPlugin<LoggingConfig> = createClientPlugin("Logging",
fun isNone(): Boolean = level == LogLevel.NONE
fun isInfo(): Boolean = level == LogLevel.INFO
fun isHeaders(): Boolean = level == LogLevel.HEADERS
fun isBody(): Boolean = level == LogLevel.BODY
fun isBody(): Boolean = level == LogLevel.BODY || level == LogLevel.ALL

suspend fun logOutgoingContent(content: OutgoingContent, process: (ByteReadChannel) -> ByteReadChannel = { it }): Pair<OutgoingContent?, Long> {
return when(content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,18 @@ class NewFormatTest {
}
}

@Test
fun basicChunkedResponseBody() = testWithLevel(LogLevel.INFO, handle = {
respond(ByteReadChannel("test"), headers = Headers.build {
append(HttpHeaders.TransferEncoding, "chunked")
})
}) { client ->
client.get("/")
log.assertLogEqual("--> GET /")
.assertLogMatch(Regex("""<-- 200 OK / \(\d+ms, unknown-byte body\)"""))
.assertNoMoreLogs()
}

@Test
fun headersGet() = testWithLevel(LogLevel.HEADERS, handle = { respondWithLength() }) { client ->
client.get("/")
Expand Down Expand Up @@ -715,14 +727,18 @@ class NewFormatTest {
}

@Test
fun basicChunkedResponseBody() = testWithLevel(LogLevel.INFO, handle = {
respond(ByteReadChannel("test"), headers = Headers.build {
append(HttpHeaders.TransferEncoding, "chunked")
})
}) { client ->
fun allResponseBody() = testWithLevel(LogLevel.ALL, handle = { respondWithLength("hello!") }) { client ->
client.get("/")
log.assertLogEqual("--> GET /")
.assertLogMatch(Regex("""<-- 200 OK / \(\d+ms, unknown-byte body\)"""))
.assertLogEqual("Accept-Charset: UTF-8")
.assertLogEqual("Accept: */*")
.assertLogEqual("--> END GET")
.assertLogMatch(Regex("""<-- 200 OK / \(\d+ms\)"""))
.assertLogEqual("Content-Length: 6")
.assertLogEqual("Content-Type: text/plain")
.assertLogEqual("")
.assertLogEqual("hello!")
.assertLogMatch(Regex("""<-- END HTTP \(\d+ms, 6-byte body\)"""))
.assertNoMoreLogs()
}

Expand Down

0 comments on commit 65bc390

Please sign in to comment.