File tree Expand file tree Collapse file tree 4 files changed +32
-3
lines changed Expand file tree Collapse file tree 4 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,10 @@ actual class HttpServer actual constructor() {
49
49
mockWebServer.start(port)
50
50
}
51
51
52
+ actual fun stop () {
53
+ mockWebServer.shutdown()
54
+ }
55
+
52
56
actual var router: Router ?
53
57
get() = dispatcher.router
54
58
set(newRouter) {
Original file line number Diff line number Diff line change @@ -20,4 +20,5 @@ interface Router {
20
20
expect class HttpServer () {
21
21
var router: Router ?
22
22
fun start (port : Int )
23
+ fun stop ()
23
24
}
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ class HttpServerTest: BaseTest() {
22
22
23
23
@AfterTest
24
24
fun teardown () = runTest {
25
- // todo: server close
25
+ server.stop()
26
26
client.close()
27
27
}
28
28
@@ -40,9 +40,29 @@ class HttpServerTest: BaseTest() {
40
40
server.start(8080 )
41
41
42
42
val response = client.get<String >(" http://localhost:8080/test" )
43
- assertEquals(response, " test" )
43
+ assertEquals(" test" , response )
44
44
45
45
val httpResponse = client.get<HttpResponse >(" http://localhost:8080/notTest" )
46
- assertEquals(httpResponse.status, HttpStatusCode .NotFound )
46
+ assertEquals(HttpStatusCode .NotFound , httpResponse.status)
47
+ }
48
+
49
+ @Test
50
+ fun returnsHeaders () = runTest {
51
+ server.router = object : Router {
52
+ override fun handleRequest (request : Request ): Response {
53
+ return Response (
54
+ 200 ,
55
+ mapOf (" customHeader" to " customHeaderValue" ),
56
+ Data (" test" ),
57
+ " text/plain"
58
+ )
59
+ }
60
+ }
61
+
62
+ server.start(8080 )
63
+
64
+ val httpResponse = client.get<HttpResponse >(" http://localhost:8080/anything" )
65
+ assertEquals( HttpStatusCode .OK , httpResponse.status)
66
+ assertEquals(" customHeaderValue" , httpResponse.headers[" customHeader" ])
47
67
}
48
68
}
Original file line number Diff line number Diff line change @@ -25,6 +25,10 @@ actual class HttpServer actual constructor() {
25
25
httpServer.startWithPort(port.toULong(), null )
26
26
}
27
27
28
+ actual fun stop () {
29
+ httpServer.stop()
30
+ }
31
+
28
32
actual var router: Router ? = null
29
33
set(newRouter) {
30
34
field = newRouter
You can’t perform that action at this time.
0 commit comments