feat: add live server status monitoring, automatic status polling, and modernized UI design
This commit is contained in:
@@ -12,7 +12,8 @@ class R2ConfigParserTest {
|
||||
{
|
||||
"poweron": "https://cosmos.linuxguy.space/poweron",
|
||||
"poweroff": "https://cosmos.linuxguy.space/poweroff",
|
||||
"reboot": "https://cosmos.linuxguy.space/reboot"
|
||||
"reboot": "https://cosmos.linuxguy.space/reboot",
|
||||
"status": "https://cosmos.linuxguy.space/status"
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
@@ -22,6 +23,7 @@ class R2ConfigParserTest {
|
||||
assertEquals("https://cosmos.linuxguy.space/poweron", endpoints.powerOn)
|
||||
assertEquals("https://cosmos.linuxguy.space/poweroff", endpoints.powerOff)
|
||||
assertEquals("https://cosmos.linuxguy.space/reboot", endpoints.reboot)
|
||||
assertEquals("https://cosmos.linuxguy.space/status", endpoints.status)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -133,4 +133,57 @@ class TriggerClientTest {
|
||||
val result = fetchResult!!
|
||||
assertTrue(result.isSuccess)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun checkStatus_withJsonResponse_parsesOnlineAndIp() {
|
||||
server.enqueue(
|
||||
MockResponse()
|
||||
.setResponseCode(200)
|
||||
.setBody("""{"node":"debian","online":true,"status":"online","ip":"100.85.63.44"}""")
|
||||
)
|
||||
|
||||
val localDevice = sampleDevice.copy(
|
||||
statusUrl = server.url("/status").toString()
|
||||
)
|
||||
|
||||
val latch = CountDownLatch(1)
|
||||
var statusResult: NodeStatus? = null
|
||||
|
||||
client.checkStatus(localDevice) { status ->
|
||||
statusResult = status
|
||||
latch.countDown()
|
||||
}
|
||||
|
||||
assertTrue(latch.await(3, TimeUnit.SECONDS))
|
||||
val status = statusResult!!
|
||||
assertTrue(status.isOnline)
|
||||
assertEquals("ONLINE", status.statusText)
|
||||
assertEquals("100.85.63.44", status.ip)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun checkStatus_withPlainText_parsesOnline() {
|
||||
server.enqueue(
|
||||
MockResponse()
|
||||
.setResponseCode(200)
|
||||
.setBody("ONLINE")
|
||||
)
|
||||
|
||||
val localDevice = sampleDevice.copy(
|
||||
statusUrl = server.url("/ping").toString()
|
||||
)
|
||||
|
||||
val latch = CountDownLatch(1)
|
||||
var statusResult: NodeStatus? = null
|
||||
|
||||
client.checkStatus(localDevice) { status ->
|
||||
statusResult = status
|
||||
latch.countDown()
|
||||
}
|
||||
|
||||
assertTrue(latch.await(3, TimeUnit.SECONDS))
|
||||
val status = statusResult!!
|
||||
assertTrue(status.isOnline)
|
||||
assertEquals("ONLINE", status.statusText)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user