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 summaray for detailed check #236

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/ResultStores/StoredCheckResults/StoredCheckResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,19 @@ public function containsCheckWithStatus(array|Status $statuses): bool
);
}

public function getFailing()
{
return $this->storedCheckResults->filter(
fn (StoredCheckResult $line) => $line->status !== Status::ok()->value
);
}

public function toJson(): string
{
return (string) json_encode([
'finishedAt' => $this->finishedAt->getTimestamp(),
'status' => $this->allChecksOk() ? 'ok' : 'failing',
'failingChecks' => $this->getFailing()->map->name ?: [],
'checkResults' => $this->storedCheckResults->map(fn (StoredCheckResult $line) => $line->toArray()),
]);
}
Expand Down
11 changes: 11 additions & 0 deletions tests/ResultStores/StoredCheckResultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
expect($storedCheckResults->containsFailingCheck())->toBeTrue();
});

it('returns a list of failed checks', function () {
$storedCheckResults = new StoredCheckResults(new DateTime(), collect([
makeStoredCheckResultWithStatus(Status::warning()),
makeStoredCheckResultWithStatus(Status::ok()),
]));
$failing = $storedCheckResults->getFailing();
expect($failing->first()->status)->toBe('warning');
expect($failing->first()->name)->toBe('test');
expect($failing->count())->toBe(1);
});

it('has a method to check if all checks are good', function () {
$storedCheckResults = new StoredCheckResults(new DateTime, collect([
makeStoredCheckResultWithStatus(Status::ok()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"finishedAt": 1609459200,
"status": "ok",
"failingChecks": [],
"checkResults": [
{
"name": "FakeUsedDiskSpace",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"finishedAt": 1609459200,
"status": "ok",
"failingChecks": [],
"checkResults": [
{
"name": "FakeUsedDiskSpace",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"finishedAt": 1609459200,
"status": "ok",
"failingChecks": [],
"checkResults": [
{
"name": "FakeUsedDiskSpace",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
finishedAt: 1609459200
status: failing
failingChecks:
- FakeUsedDiskSpace
checkResults:
- { name: FakeUsedDiskSpace, label: 'Fake Used Disk Space', notificationMessage: 'The disk is almost full (100% used).', shortSummary: 100%, status: failed, meta: { disk_space_used_percentage: 100 } }
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
finishedAt: 1609459200
status: failing
failingChecks:
- FakeUsedDiskSpace
checkResults:
- { name: FakeUsedDiskSpace, label: 'Fake Used Disk Space', notificationMessage: 'The disk is almost full (100% used).', shortSummary: 100%, status: failed, meta: { disk_space_used_percentage: 100 } }
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"finishedAt": 1609459200,
"status": "ok",
"failingChecks": [],
"checkResults": [
{
"name": "FakeUsedDiskSpace",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"finishedAt": 1609459200,
"status": "ok",
"failingChecks": [],
"checkResults": [
{
"name": "FakeUsedDiskSpace",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
finishedAt: 1609459200
status: failing
failingChecks:
- FakeUsedDiskSpace
checkResults:
- { name: FakeUsedDiskSpace, label: 'Fake Used Disk Space', notificationMessage: 'The disk is almost full (100% used).', shortSummary: 100%, status: failed, meta: { disk_space_used_percentage: 100 } }
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
finishedAt: 1609459200
status: failing
failingChecks:
- FakeUsedDiskSpace
checkResults:
- { name: FakeUsedDiskSpace, label: 'Fake Used Disk Space', notificationMessage: 'The disk is almost full (100% used).', shortSummary: 100%, status: failed, meta: { disk_space_used_percentage: 100 } }
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"finishedAt":978307200,"checkResults":[{"name":"name","label":"label","notificationMessage":"message","shortSummary":"summary","status":"ok","meta":{"name":"value"}}]}
{"finishedAt":978307200,"status":"ok","failingChecks":[],"checkResults":[{"name":"name","label":"label","notificationMessage":"message","shortSummary":"summary","status":"ok","meta":{"name":"value"}}]}
Loading