Server: Implement get version
This commit is contained in:
parent
8fa3ba1b18
commit
2848c4e77b
@ -50,5 +50,14 @@ fun Routing.storage(app: SyncApplication) {
|
||||
call.respond(HttpStatusCode.Conflict, currData)
|
||||
}
|
||||
}
|
||||
get("version") {
|
||||
val key = call.parameters["key"]!!
|
||||
try {
|
||||
val data = app.server.get(key)
|
||||
call.respond(HttpStatusCode.OK, data.version)
|
||||
} catch(e: KeyNotFoundException) {
|
||||
call.respond(HttpStatusCode.NotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -41,6 +41,17 @@ class StorageModuleTest : BaseApplicationTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when get version succeeds should return version`() {
|
||||
`when`(server.get("k1")).thenReturn(data1)
|
||||
withTestApplication(app()) {
|
||||
handleGet("/db/k1/version").apply {
|
||||
assertEquals(HttpStatusCode.OK, response.status())
|
||||
assertEquals("1", response.content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when get with invalid key should return 404`() {
|
||||
`when`(server.get("k1")).thenThrow(KeyNotFoundException())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user