Smoke-test /health for the reachable (200) and unreachable (503) cases
This commit is contained in:
1 parent
c67c71ea28
commit
666614a3b2
4 files changed
+110
-28
No files matched your search
@@ -1,5 +1,4 @@
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
|
||||
namespace Elternbeirat.Web.Tests;
|
||||
@@ -140,4 +139,34 @@ public sealed class RouteSmokeTests : IDisposable
|
||||
|
||||
html.ShouldContain("Förderverein"); // the page body, rendered from Markdown
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Health_returns_200_when_PocketBase_is_reachable()
|
||||
{
|
||||
// The monitor's happy path: the app answers and PocketBase (the seeded
|
||||
// fixture) is up, so /health is 200. This mostly guards the wiring -- that the
|
||||
// endpoint exists and reaches the client -- since the fixture keeps PocketBase
|
||||
// alive; the unreachable case is covered separately below.
|
||||
var client = _factory.CreateClient();
|
||||
|
||||
var response = await client.GetAsync(new Uri("/health", UriKind.Relative));
|
||||
|
||||
response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Health_returns_503_when_PocketBase_is_unreachable()
|
||||
{
|
||||
// The case the monitor exists for: the app is up but PocketBase is not. Point a
|
||||
// throwaway app at a dead address (nothing listens on port 1, so the probe is
|
||||
// refused at once, no timeout wait) and assert /health reports 503 rather than
|
||||
// claiming healthy.
|
||||
await using var factory = _baseFactory.WithWebHostBuilder(builder =>
|
||||
builder.UseSetting("PocketBase:BaseUrl", "http://localhost:1"));
|
||||
var client = factory.CreateClient();
|
||||
|
||||
var response = await client.GetAsync(new Uri("/health", UriKind.Relative));
|
||||
|
||||
response.StatusCode.ShouldBe(HttpStatusCode.ServiceUnavailable);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user