Skip to content

Commit 67e27d9

Browse files
committed
feat(tests): configure test environment and streamline health checks
- Sets the web host environment to "tests" for accurate testing context. - Removes redundant resilience pipeline for health checks. - Simplifies health check assertions to improve test clarity and maintainability.
1 parent e4050fb commit 67e27d9

File tree

2 files changed

+5
-30
lines changed

2 files changed

+5
-30
lines changed

tests/ES.Kubernetes.Reflector.Tests/Fixtures/ReflectorFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ protected override IHost CreateHost(IHostBuilder builder)
2727

2828
protected override void ConfigureWebHost(IWebHostBuilder builder)
2929
{
30+
builder.UseEnvironment("tests");
3031
builder.ConfigureServices(services =>
3132
{
32-
// remove the existing KubernetesClientConfiguration and IKubernetes registrations
3333
var kubernetesClientConfiguration = services.SingleOrDefault(
3434
d => d.ServiceType == typeof(KubernetesClientConfiguration));
3535
if (kubernetesClientConfiguration is not null) services.Remove(kubernetesClientConfiguration);

tests/ES.Kubernetes.Reflector.Tests/Integration/HealthCheckIntegrationTests.cs

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,15 @@ public class HealthCheckIntegrationTests(ReflectorIntegrationFixture integration
2121
{
2222
private readonly ReflectorIntegrationFixture _integrationFixture = integrationFixture;
2323

24-
25-
private static readonly ResiliencePipeline<bool> HealthCheckResiliencePipeline =
26-
new ResiliencePipelineBuilder<bool>()
27-
.AddRetry(new RetryStrategyOptions<bool>
28-
{
29-
ShouldHandle = new PredicateBuilder<bool>()
30-
.Handle<HttpOperationException>(ex =>
31-
ex.Response.StatusCode == HttpStatusCode.ServiceUnavailable)
32-
.HandleResult(false),
33-
MaxRetryAttempts = 10,
34-
Delay = TimeSpan.FromSeconds(1)
35-
})
36-
.AddTimeout(TimeSpan.FromSeconds(30))
37-
.Build();
38-
39-
4024
[Fact]
4125
public async Task LivenessHealthCheck_Should_Return_Healthy()
4226
{
4327
var httpClient = _integrationFixture.Reflector.CreateClient();
4428
var settings = _integrationFixture.Reflector.Services.GetRequiredService<IgniteSettings>();
29+
4530
var response = await httpClient.GetAsync(settings.AspNetCore.HealthChecks.LivenessEndpointPath,
4631
TestContext.Current.CancellationToken);
47-
4832
Assert.Equal(HttpStatusCode.OK,response.StatusCode);
49-
Assert.Equal("text/plain", response.Content.Headers.ContentType?.MediaType);
50-
var content = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
51-
Assert.Equal("Healthy", content);
5233
}
5334

5435
[Fact]
@@ -57,14 +38,8 @@ public async Task ReadinessHealthCheck_Should_Return_Healthy()
5738
var settings = _integrationFixture.Reflector.Services.GetRequiredService<IgniteSettings>();
5839
var httpClient = _integrationFixture.Reflector.CreateClient();
5940

60-
await HealthCheckResiliencePipeline.ExecuteAsync(async token =>
61-
{
62-
var response = await httpClient.GetAsync(settings.AspNetCore.HealthChecks.ReadinessEndpointPath,
63-
TestContext.Current.CancellationToken);
64-
response.EnsureSuccessStatusCode();
65-
return response.StatusCode == HttpStatusCode.OK;
66-
}, TestContext.Current.CancellationToken);
67-
68-
41+
var response = await httpClient.GetAsync(settings.AspNetCore.HealthChecks.ReadinessEndpointPath,
42+
TestContext.Current.CancellationToken);
43+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
6944
}
7045
}

0 commit comments

Comments
 (0)