|
1 | 1 | package no.nav.syfo
|
2 | 2 |
|
3 |
| -import io.ktor.http.HttpMethod |
| 3 | +import io.ktor.client.request.* |
| 4 | +import io.ktor.client.statement.* |
4 | 5 | import io.ktor.http.HttpStatusCode
|
5 | 6 | import io.ktor.server.routing.routing
|
6 |
| -import io.ktor.server.testing.TestApplicationEngine |
7 |
| -import io.ktor.server.testing.handleRequest |
8 |
| -import io.ktor.util.InternalAPI |
| 7 | +import io.ktor.server.testing.* |
9 | 8 | import no.nav.syfo.application.ApplicationState
|
10 | 9 | import no.nav.syfo.application.api.registerNaisApi
|
11 | 10 | import org.junit.jupiter.api.Assertions.assertEquals
|
12 | 11 | import org.junit.jupiter.api.Test
|
13 | 12 |
|
14 | 13 | internal class SelfTest {
|
15 | 14 |
|
16 |
| - @InternalAPI |
17 | 15 | @Test
|
18 | 16 | internal fun `Successfull liveness and readyness tests Returns ok on is_alive`() {
|
19 |
| - with(TestApplicationEngine()) { |
20 |
| - start() |
21 |
| - val applicationState = ApplicationState() |
22 |
| - applicationState.ready = true |
23 |
| - applicationState.alive = true |
24 |
| - application.routing { registerNaisApi(applicationState) } |
25 |
| - |
26 |
| - with(handleRequest(HttpMethod.Get, "/internal/is_alive")) { |
27 |
| - assertEquals(HttpStatusCode.OK, response.status()) |
28 |
| - assertEquals("I'm alive! :)", response.content) |
| 17 | + testApplication { |
| 18 | + application { |
| 19 | + val applicationState = ApplicationState() |
| 20 | + applicationState.ready = true |
| 21 | + applicationState.alive = true |
| 22 | + routing { registerNaisApi(applicationState) } |
29 | 23 | }
|
| 24 | + |
| 25 | + val response = client.get("/internal/is_alive") |
| 26 | + |
| 27 | + assertEquals(HttpStatusCode.OK, response.status) |
| 28 | + assertEquals("I'm alive! :)", response.bodyAsText()) |
30 | 29 | }
|
31 | 30 | }
|
32 | 31 |
|
33 |
| - @InternalAPI |
34 | 32 | @Test
|
35 | 33 | internal fun `Successfull liveness and readyness tests returns ok in is_ready`() {
|
36 |
| - with(TestApplicationEngine()) { |
37 |
| - start() |
38 |
| - val applicationState = ApplicationState() |
39 |
| - applicationState.ready = true |
40 |
| - applicationState.alive = true |
41 |
| - application.routing { registerNaisApi(applicationState) } |
42 |
| - |
43 |
| - with(handleRequest(HttpMethod.Get, "/internal/is_ready")) { |
44 |
| - assertEquals(HttpStatusCode.OK, response.status()) |
45 |
| - assertEquals("I'm ready! :)", response.content) |
| 34 | + testApplication { |
| 35 | + application { |
| 36 | + val applicationState = ApplicationState() |
| 37 | + applicationState.ready = true |
| 38 | + applicationState.alive = true |
| 39 | + routing { registerNaisApi(applicationState) } |
46 | 40 | }
|
| 41 | + |
| 42 | + val response = client.get("/internal/is_ready") |
| 43 | + |
| 44 | + assertEquals(HttpStatusCode.OK, response.status) |
| 45 | + assertEquals("I'm ready! :)", response.bodyAsText()) |
47 | 46 | }
|
48 | 47 | }
|
49 | 48 |
|
50 |
| - @InternalAPI |
51 | 49 | @Test
|
52 | 50 | internal fun `Unsuccessful liveness and readyness returns internal server error when liveness check fails`() {
|
53 |
| - with(TestApplicationEngine()) { |
54 |
| - start() |
55 |
| - val applicationState = ApplicationState() |
56 |
| - applicationState.ready = false |
57 |
| - applicationState.alive = false |
58 |
| - application.routing { registerNaisApi(applicationState) } |
59 |
| - |
60 |
| - with(handleRequest(HttpMethod.Get, "/internal/is_alive")) { |
61 |
| - assertEquals(HttpStatusCode.InternalServerError, response.status()) |
62 |
| - assertEquals("I'm dead x_x", response.content) |
| 51 | + testApplication { |
| 52 | + application { |
| 53 | + val applicationState = ApplicationState() |
| 54 | + applicationState.ready = false |
| 55 | + applicationState.alive = false |
| 56 | + routing { registerNaisApi(applicationState) } |
63 | 57 | }
|
| 58 | + val response = client.get("/internal/is_alive") |
| 59 | + |
| 60 | + assertEquals(HttpStatusCode.InternalServerError, response.status) |
| 61 | + assertEquals("I'm dead x_x", response.bodyAsText()) |
64 | 62 | }
|
65 | 63 | }
|
66 | 64 |
|
67 |
| - @InternalAPI |
68 | 65 | @Test
|
69 | 66 | internal fun `Unsuccessful liveness and readyness returns internal server error when readyness check fails`() {
|
70 |
| - with(TestApplicationEngine()) { |
71 |
| - start() |
72 |
| - val applicationState = ApplicationState() |
73 |
| - applicationState.ready = false |
74 |
| - applicationState.alive = false |
75 |
| - application.routing { registerNaisApi(applicationState) } |
76 |
| - with(handleRequest(HttpMethod.Get, "/internal/is_ready")) { |
77 |
| - assertEquals(HttpStatusCode.InternalServerError, response.status()) |
78 |
| - assertEquals("Please wait! I'm not ready :(", response.content) |
| 67 | + testApplication { |
| 68 | + application { |
| 69 | + val applicationState = ApplicationState() |
| 70 | + applicationState.ready = false |
| 71 | + applicationState.alive = false |
| 72 | + routing { registerNaisApi(applicationState) } |
79 | 73 | }
|
| 74 | + val response = client.get("/internal/is_ready") |
| 75 | + |
| 76 | + assertEquals(HttpStatusCode.InternalServerError, response.status) |
| 77 | + assertEquals("Please wait! I'm not ready :(", response.bodyAsText()) |
80 | 78 | }
|
81 | 79 | }
|
82 | 80 | }
|
0 commit comments