summaryrefslogtreecommitdiffstats
path: root/tests/test-health.R
blob: 21007afd6d0173ae0026ad1e14c51a98fcf9b719 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
library(cepis)
source(file.path("helper", "utils.R"))

healthy <- list(
  status = "ok",
  dne = "26071",
  ceps = 1596168L,
  geo = 894489L,
  base_gerada_em = "2026-07-24T03:48:28Z"
)

with_server(
  list(route("/health", response(200L, json(healthy)))),
  function(client, server) {
    health <- cep_health(client)
    check("health reports itself ok", isTRUE(health$ok))
    check("it names the database version", identical(health$dne, "26071"))
    check("it counts the CEPs", identical(health$ceps, 1596168L))
    check("it counts the ones with a coordinate", identical(health$geo, 894489L))
  }
)

degraded <- list(status = "degradado", dne = "", ceps = 0L, geo = 0L)

with_server(
  list(route("/health", response(503L, json(degraded)))),
  function(client, server) {
    health <- cep_health(client)
    check("a degraded API is a diagnosis, not an error", isFALSE(health$ok))
    check("the status is readable", identical(health$status, "degradado"))
    check("a 503 at /health is not retried", calls(server, "/health") == 1L)
  }
)