-
Notifications
You must be signed in to change notification settings - Fork 0
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
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
backend/authik/src/main/kotlin/ru/ifmo/se/dating/authik/api/HttpMonitoringApi.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 |
---|---|---|
@@ -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() | ||
} |
23 changes: 23 additions & 0 deletions
23
backend/authik/src/test/kotlin/ru/ifmo/se/dating/authik/api/HttpMonitoringApiTest.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 |
---|---|---|
@@ -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!! | ||
} | ||
} |