Skip to content

Commit

Permalink
Merge pull request #122 from davidrushton/feature/diskspace-custom-fi…
Browse files Browse the repository at this point in the history
…lesystem

Added filesystemName to UsedDiskSpaceCheck
  • Loading branch information
freekmurze authored Sep 22, 2022
2 parents 2c0ff43 + d6403f5 commit 46d1953
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Checks/Checks/UsedDiskSpaceCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ class UsedDiskSpaceCheck extends Check

protected int $errorThreshold = 90;

protected ?string $filesystemName = null;

public function filesystemName(string $filesystemName): self
{
$this->filesystemName = $filesystemName;

return $this;
}

public function warnWhenUsedSpaceIsAbovePercentage(int $percentage): self
{
$this->warningThreshold = $percentage;
Expand Down Expand Up @@ -48,7 +57,7 @@ public function run(): Result

protected function getDiskUsagePercentage(): int
{
$process = Process::fromShellCommandline('df -P .');
$process = Process::fromShellCommandline('df -P ' . ( $this->filesystemName ?: '.' ));

$process->run();

Expand Down
10 changes: 10 additions & 0 deletions tests/Checks/UsedDiskSpaceCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
->getNotificationMessage()->toEqual('The disk is almost full (91% used).');
});

it('can set a custom filesystem name', function () {
$filesystem = '/mnt/temp';

$check = FakeUsedDiskSpaceCheck::new()
->filesystemName('/mnt/temp');

expect($check->getFilesystemName())
->toEqual($filesystem);
});

it('can report the real disk space used', function () {
$result = UsedDiskSpaceCheck::new()->run();

Expand Down
6 changes: 6 additions & 0 deletions tests/TestClasses/FakeUsedDiskSpaceCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ public function getDiskUsagePercentage(): int
{
return $this->fakeDiskUsagePercentage;
}

public function getFilesystemName(): string|null
{
return $this->filesystemName;
}

}

0 comments on commit 46d1953

Please sign in to comment.