-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 56 additions & 44 deletions
100
src/test/kotlin/no/nav/syfo/application/api/SelftestSpek.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,79 @@ | ||
package no.nav.syfo.application.api | ||
package no.nav.syfo | ||
|
||
import io.kotest.core.spec.style.FunSpec | ||
import io.ktor.http.HttpMethod | ||
import io.ktor.client.request.* | ||
import io.ktor.client.statement.* | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.server.routing.routing | ||
import io.ktor.server.testing.TestApplicationEngine | ||
import io.ktor.server.testing.handleRequest | ||
import no.nav.syfo.ApplicationState | ||
import io.ktor.server.testing.* | ||
import no.nav.syfo.nais.isalive.naisIsAliveRoute | ||
import no.nav.syfo.nais.isready.naisIsReadyRoute | ||
import org.amshove.kluent.shouldBeEqualTo | ||
|
||
object SelftestSpek : | ||
FunSpec({ | ||
context("Successfull liveness and readyness tests") { | ||
with(TestApplicationEngine()) { | ||
start() | ||
val applicationState = ApplicationState() | ||
applicationState.ready = true | ||
applicationState.alive = true | ||
application.routing { | ||
naisIsAliveRoute(applicationState) | ||
naisIsReadyRoute(applicationState) | ||
} | ||
|
||
class SelftestSpek : | ||
FunSpec( | ||
{ | ||
context("Successfull liveness and readyness tests") { | ||
test("Returns ok on is_alive") { | ||
with(handleRequest(HttpMethod.Get, "/internal/is_alive")) { | ||
response.status() shouldBeEqualTo HttpStatusCode.OK | ||
response.content shouldBeEqualTo "I'm alive! :)" | ||
testApplication { | ||
application { | ||
val applicationState = ApplicationState() | ||
applicationState.ready = true | ||
applicationState.alive = true | ||
routing { naisIsAliveRoute(applicationState) } | ||
} | ||
|
||
val response = client.get("/internal/is_alive") | ||
|
||
response.status shouldBeEqualTo HttpStatusCode.OK | ||
response.bodyAsText() shouldBeEqualTo "I'm alive! :)" | ||
} | ||
} | ||
test("Returns ok in is_ready") { | ||
with(handleRequest(HttpMethod.Get, "/internal/is_ready")) { | ||
response.status() shouldBeEqualTo HttpStatusCode.OK | ||
response.content shouldBeEqualTo "I'm ready! :)" | ||
testApplication { | ||
application { | ||
val applicationState = ApplicationState() | ||
applicationState.ready = true | ||
applicationState.alive = true | ||
routing { naisIsReadyRoute(applicationState) } | ||
} | ||
|
||
val response = client.get("/internal/is_ready") | ||
response.status shouldBeEqualTo HttpStatusCode.OK | ||
response.bodyAsText() shouldBeEqualTo "I'm ready! :)" | ||
} | ||
} | ||
} | ||
} | ||
context("Unsuccessful liveness and readyness") { | ||
with(TestApplicationEngine()) { | ||
start() | ||
val applicationState = ApplicationState() | ||
applicationState.ready = false | ||
applicationState.alive = false | ||
application.routing { | ||
naisIsAliveRoute(applicationState) | ||
naisIsReadyRoute(applicationState) | ||
} | ||
|
||
context("Unsuccessful liveness and readyness") { | ||
test("Returns internal server error when liveness check fails") { | ||
with(handleRequest(HttpMethod.Get, "/internal/is_alive")) { | ||
response.status() shouldBeEqualTo HttpStatusCode.InternalServerError | ||
response.content shouldBeEqualTo "I'm dead x_x" | ||
testApplication { | ||
application { | ||
val applicationState = ApplicationState() | ||
applicationState.ready = false | ||
applicationState.alive = false | ||
routing { naisIsAliveRoute(applicationState) } | ||
} | ||
val response = client.get("/internal/is_alive") | ||
|
||
response.status shouldBeEqualTo HttpStatusCode.InternalServerError | ||
response.bodyAsText() shouldBeEqualTo "I'm dead x_x" | ||
} | ||
} | ||
|
||
test("Returns internal server error when readyness check fails") { | ||
with(handleRequest(HttpMethod.Get, "/internal/is_ready")) { | ||
response.status() shouldBeEqualTo HttpStatusCode.InternalServerError | ||
response.content shouldBeEqualTo "Please wait! I'm not ready :(" | ||
testApplication { | ||
application { | ||
val applicationState = ApplicationState() | ||
applicationState.ready = false | ||
applicationState.alive = false | ||
routing { naisIsReadyRoute(applicationState) } | ||
} | ||
val response = client.get("/internal/is_ready") | ||
|
||
response.status shouldBeEqualTo HttpStatusCode.InternalServerError | ||
response.bodyAsText() shouldBeEqualTo "Please wait! I'm not ready :(" | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
}, | ||
) |