Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to check if a HealthCheck.Result is healthy using a boolean #494

Closed
sleberknight opened this issue Jun 13, 2024 · 0 comments · Fixed by #498
Closed

Add ability to check if a HealthCheck.Result is healthy using a boolean #494

sleberknight opened this issue Jun 13, 2024 · 0 comments · Fixed by #498
Assignees
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Milestone

Comments

@sleberknight
Copy link
Member

HealthCheckResultAssertions contains fluent isHealthy() and isUnhealthy() methods, which works in most cases.

But if you have a JUnit @ParameterizedTest to check various health check results, and all you care about is healthy or not, you can't. Instead, you must break these into separate tests.

For situations like this, it would be nice to be able to provide a boolean. For example, I want to be able to do this:

@ParameterizedTest
@CsvSource(textBlock = """
        200, OK, true
        201, OK, true
        202, OK, true
        400, WARN, false
        404, WARN, false
        500, CRITICAL, false
        """)
void shouldHaveExpectedResult(int statusCode, HealthStatus severity, boolean expectedHealthyValue) {
    var healthCheck = new new UrlHealthCheck(client, description, url, () -> true, kiwiEnvironment);
    server.enqueue(new MockResponse().setResponseCode(statusCode));
    assertThatHealthCheck(healthCheck)
            .hasHealthyValue(expectedHealthyValue)
            .hasDetail(HealthCheckResults.SEVERITY_DETAIL, severity.name());
}

In the above example code, hasHealthyValue accepts a boolean where true means healthy and false means unhealthy.

@sleberknight sleberknight added the new feature A new feature such as a new class, method, package, group of classes, etc. label Jun 13, 2024
@sleberknight sleberknight added this to the 3.5.0 milestone Jun 19, 2024
@sleberknight sleberknight self-assigned this Jun 19, 2024
sleberknight added a commit that referenced this issue Jun 19, 2024
* Add hasHealthyValue(boolean) to HealthCheckResultAssertions

Closes #494
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant