diff options
Diffstat (limited to 't/06-health.t')
| -rw-r--r-- | t/06-health.t | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/t/06-health.t b/t/06-health.t new file mode 100644 index 0000000..fca2820 --- /dev/null +++ b/t/06-health.t @@ -0,0 +1,58 @@ +use strict; +use warnings; + +use FindBin (); +use lib "$FindBin::Bin/lib"; + +use Test::More; +use TestServer qw(json new_client); + +use Cepis; + +{ + my $body = json( + { status => 'ok', + dne => '26071', + ceps => 1596168, + geo => 894489, + base_gerada_em => '2026-07-24T03:48:28Z', + } + ); + my $server = TestServer->new( routes => { '/health' => [ 200, $body, {} ] } ); + my $client = new_client($server); + + my $health = $client->health; + isa_ok( $health, 'Cepis::Health' ); + ok( $health->ok, 'the API reports itself healthy' ); + is( $health->dne, '26071', 'dne identifies the database' ); + is( $health->ceps, 1596168, 'ceps' ); + is( $health->geo, 894489, 'geo is a count here, not an object' ); + is( $health->base_gerada_em, '2026-07-24T03:48:28Z', 'base_gerada_em' ); + $server->stop; +} + +{ + my $body = json( + { status => 'degradado', dne => '', ceps => 0, geo => 0, base_gerada_em => '' } ); + my $server = TestServer->new( routes => { '/health' => [ 503, $body, {} ] } ); + my $client = new_client($server); + + my $health = $client->health; + ok( !$health->ok, 'a degraded API does not throw' ); + is( $health->status, 'degradado', 'the diagnosis arrives in status' ); + is( $server->count('/health'), 1, 'and a 503 on /health is not retried' ); + $server->stop; +} + +{ + my $server = TestServer->new( routes => { '/health' => [ 500, '{}', {} ] } ); + my $client = new_client($server); + + my $ok = eval { $client->health; 1 }; + ok( !$ok, 'a 500 on /health still throws' ); + isa_ok( $@, 'Cepis::Error::ServerError' ); + is( $server->count('/health'), 3, 'after retrying' ); + $server->stop; +} + +done_testing(); |