Skip to content

Commit

Permalink
Add a health check test
Browse files Browse the repository at this point in the history
  • Loading branch information
lopcode committed Aug 3, 2024
1 parent 200e94c commit 75aa4e9
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 18 deletions.
7 changes: 6 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ updates:
directory: "/api"
schedule:
interval: "weekly"
groups:
ktor:
patterns: ["io.ktor*"]
database:
patterns: [ "org.jdbi*", "org.flyway*", "org.postgresql*" ]
- package-ecosystem: "docker"
directory: "/api"
schedule:
interval: "weekly"
interval: "weekly"
9 changes: 9 additions & 0 deletions api/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*.{kt,kts}]
ktlint_code_style = ktlint_official
ktlint_standard_multiline-expression-wrapping = disabled
ktlint_standard_chain-method-continuation = disabled
ktlint_standard_function-signature = disabled
ktlint_standard_function-expression-body = disabled
max_line_length = 120
5 changes: 0 additions & 5 deletions api/app/.editorconfig

This file was deleted.

12 changes: 8 additions & 4 deletions api/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ testing {
val test by getting(JvmTestSuite::class) {
useKotlinTest("2.0.0")
testType = TestSuiteType.UNIT_TEST

dependencies {
implementation("io.ktor:ktor-server-test-host")
}
}

register<JvmTestSuite>("integrationTest") {
Expand All @@ -40,6 +36,8 @@ testing {

dependencies {
implementation(project())
implementation(platform("io.ktor:ktor-bom:3.0.0-beta-2"))
implementation("io.ktor:ktor-server-test-host")
}

targets {
Expand Down Expand Up @@ -73,6 +71,7 @@ tasks.withType<ShadowJar> {
}

dependencies {
implementation(platform("io.ktor:ktor-bom:3.0.0-beta-2"))
implementation("io.ktor:ktor-server-core")
implementation("io.ktor:ktor-server-netty")
implementation("io.ktor:ktor-server-call-logging")
Expand All @@ -96,3 +95,8 @@ dependencies {
application {
mainClass = "com.photofox.MainKt"
}

configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
version.set("1.3.1")
verbose.set(true)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.photofox

import io.ktor.client.request.get
import io.ktor.http.HttpStatusCode
import io.ktor.server.testing.testApplication
import kotlin.test.Test
import kotlin.test.assertEquals

class HealthSenseCheck {
@Test
fun `health check returns 2xx`() = testApplication {
application {
module()
}

val response = client.get("/api/health")
assertEquals(HttpStatusCode.OK, response.status)
}
}
5 changes: 1 addition & 4 deletions api/app/src/main/kotlin/com/photofox/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ private fun Application.configureRouting() {
}
}

suspend fun <ViewModel : Any> RoutingCall.respondPage(
pageTemplateName: String,
viewModel: ViewModel,
) {
suspend fun <ViewModel : Any> RoutingCall.respondPage(pageTemplateName: String, viewModel: ViewModel) {
return this.respond(
PageResponse(
makePageTemplatePath(pageTemplateName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ class PageResponsePlugin {
companion object Plugin : BaseApplicationPlugin<ApplicationCallPipeline, Any, Plugin> {
override val key = AttributeKey<Plugin>("PageResponse")

override fun install(
pipeline: ApplicationCallPipeline,
configure: Any.() -> Unit,
): Plugin {
override fun install(pipeline: ApplicationCallPipeline, configure: Any.() -> Unit): Plugin {
pipeline.sendPipeline.intercept(ApplicationSendPipeline.Before) { value ->
if (value is PageResponse<*>) {
context.response.cacheControl(
Expand Down
1 change: 1 addition & 0 deletions api/app/static
1 change: 1 addition & 0 deletions api/app/templates

0 comments on commit 75aa4e9

Please sign in to comment.