diff options
Diffstat (limited to 'tests/Cepis.Tests/HealthTests.cs')
| -rw-r--r-- | tests/Cepis.Tests/HealthTests.cs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/Cepis.Tests/HealthTests.cs b/tests/Cepis.Tests/HealthTests.cs new file mode 100644 index 0000000..2855d72 --- /dev/null +++ b/tests/Cepis.Tests/HealthTests.cs @@ -0,0 +1,46 @@ +namespace Cepis.Tests; + +/// <summary>The health endpoint, which reports rather than throws.</summary> +public sealed class HealthTests : HttpTestBase +{ + [Fact] + public async Task ReadsAHealthyApi() + { + Server.Respond("/health", Reply.Of(200, Fixtures.Healthy)); + + var health = await Client.HealthAsync(); + + Assert.True(health.Ok); + Assert.Equal("ok", health.Status); + Assert.Equal("26071", health.Dne); + Assert.Equal(1596168, health.Ceps); + Assert.Equal(894489, health.Geo); + Assert.Equal("2026-07-24T03:48:28Z", health.BaseGeradaEm); + } + + [Fact] + public async Task ADegradedApiReportsRatherThanThrows() + { + Server.Respond("/health", Reply.Of(503, + """{"status":"degradado","dne":"26071","ceps":0,"geo":0,"base_gerada_em":""}""")); + + var health = await Client.HealthAsync(); + + Assert.False(health.Ok); + Assert.Equal("degradado", health.Status); + Assert.Equal(1, Server.Count("/health")); + } + + [Fact] + public async Task AnUnreachableApiStillThrows() + { + using var unreachable = new CepisClient(new CepisClientOptions + { + BaseUrl = "http://127.0.0.1:1", + MaxAttempts = 1, + Timeout = TimeSpan.FromSeconds(30), + }); + + await Assert.ThrowsAsync<NetworkException>(() => unreachable.HealthAsync()); + } +} |