Skip to content

Commit

Permalink
#54 Add healthcheck endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
vityaman committed Nov 12, 2024
1 parent 6e823b0 commit 042f155
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ru.ifmo.se.dating.authik.api

import kotlinx.coroutines.reactor.awaitSingle
import org.springframework.http.ResponseEntity
import org.springframework.r2dbc.core.DatabaseClient
import org.springframework.stereotype.Controller
import ru.ifmo.se.dating.authik.api.generated.MonitoringApiDelegate

@Controller
internal class HttpMonitoringApi(
private val data: DatabaseClient,
) : MonitoringApiDelegate {
override suspend fun monitoringHealthcheckGet(): ResponseEntity<String> =
data
.sql("SELECT current_schema")
.map { row, _ -> row.get(0, String::class.java) }
.one()
.map { pong -> ResponseEntity.ok(pong) }
.awaitSingle()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ru.ifmo.se.dating.authik.api

import org.junit.Assert
import org.junit.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.web.client.TestRestTemplate
import ru.ifmo.se.dating.authik.AuthikTestSuite

class HttpMonitoringApiTest : AuthikTestSuite() {
@Autowired
private lateinit var rest: TestRestTemplate

@Test
fun healthcheck() {
Assert.assertEquals(getHealthcheck(), "public")
}

private fun getHealthcheck(): String {
val url = "http://localhost:8080/api/monitoring/healthcheck"
val response = rest.getForEntity(url, String::class.java)
return response.body!!
}
}

0 comments on commit 042f155

Please sign in to comment.