Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.

Commit dafa01c

Browse files
committed
Support head and options methods
1 parent 7fa3846 commit dafa01c

File tree

2 files changed

+32
-0
lines changed
  • src
    • main/kotlin/io/kotest/extensions/httpstub
    • test/kotlin/io/kotest/extensions/httpstub

2 files changed

+32
-0
lines changed

src/main/kotlin/io/kotest/extensions/httpstub/dsl.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ class HttpStubber(private val server: WireMockServer) {
4646
stub(builder, fn)
4747
}
4848

49+
fun head(url: String, fn: RequestStubber.() -> HttpResponse) {
50+
val builder = WireMock.head(WireMock.urlEqualTo(url))
51+
stub(builder, fn)
52+
}
53+
54+
fun options(url: String, fn: RequestStubber.() -> HttpResponse) {
55+
val builder = WireMock.options(WireMock.urlEqualTo(url))
56+
stub(builder, fn)
57+
}
58+
4959
fun put(url: String, fn: RequestStubber.() -> HttpResponse) {
5060
val builder = WireMock.put(WireMock.urlEqualTo(url))
5161
stub(builder, fn)

src/test/kotlin/io/kotest/extensions/httpstub/MethodTest.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import io.ktor.client.HttpClient
77
import io.ktor.client.engine.apache.Apache
88
import io.ktor.client.request.delete
99
import io.ktor.client.request.get
10+
import io.ktor.client.request.head
11+
import io.ktor.client.request.options
1012
import io.ktor.client.request.patch
1113
import io.ktor.client.request.post
1214
import io.ktor.client.request.put
@@ -50,6 +52,26 @@ class MethodTest : FunSpec() {
5052
resp.status shouldBe HttpStatusCode.PartialContent
5153
}
5254

55+
test("options request") {
56+
server.mappings {
57+
options("/foo") {
58+
HttpResponse(HttpStatusCode.Conflict, "hello")
59+
}
60+
}
61+
val resp = client.options("http://localhost:${server.port}/foo")
62+
resp.status shouldBe HttpStatusCode.Conflict
63+
}
64+
65+
test("head request") {
66+
server.mappings {
67+
head("/foo") {
68+
HttpResponse(HttpStatusCode.MultiStatus, "hello")
69+
}
70+
}
71+
val resp = client.head("http://localhost:${server.port}/foo")
72+
resp.status shouldBe HttpStatusCode.MultiStatus
73+
}
74+
5375
test("put request") {
5476
server.mappings {
5577
put("/foo") {

0 commit comments

Comments
 (0)