diff options
Diffstat (limited to 'tests/test-health.R')
| -rw-r--r-- | tests/test-health.R | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/test-health.R b/tests/test-health.R new file mode 100644 index 0000000..21007af --- /dev/null +++ b/tests/test-health.R @@ -0,0 +1,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) + } +) |