Skip to content

Commit

Permalink
Add unit tests for invalid performance data evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Aug 30, 2023
1 parent d6e397d commit 4601873
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/php/library/Icingadb/Util/PerfdataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,17 @@ public function testWhetherGetMinimumValueReturnsCorrectValues()
Perfdata::fromString('test=1;;;1337.5')->getMinimumValue(),
'Perfdata::getMinimumValue does not return correct values'
);

$this->assertSame(
'10,00',
Perfdata::fromString('test=1;;;;10,00')->getMinimumValue(),
'Perfdata::getMinimumValue does not return correct values'
);
$this->assertSame(
'foo',
Perfdata::fromString('test=1;;;;foo')->getMinimumValue(),
'Perfdata::getMinimumValue does not return correct values'
);
}

/**
Expand All @@ -276,6 +287,16 @@ public function testWhetherGetMaximumValueReturnsCorrectValues()
Perfdata::fromString('test=1;;;;1337.5')->getMaximumValue(),
'Perfdata::getMaximumValue does not return correct values'
);
$this->assertSame(
'10,00',
Perfdata::fromString('test=1;;;;10,00')->getMaximumValue(),
'Perfdata::getMaximumValue does not return correct values'
);
$this->assertSame(
'foo',
Perfdata::fromString('test=1;;;;foo')->getMaximumValue(),
'Perfdata::getMaximumValue does not return correct values'
);
}

/**
Expand Down Expand Up @@ -399,4 +420,16 @@ public function testWhetherPercentagesAreHandledCorrectly()
'Perfdata objects do not ignore impossible min/max combinations when returning percentages'
);
}

/**
* @depends testWhetherFromStringParsesAGivenStringCorrectly
*/
public function testInvalidPerfDataHandling()
{
$this->assertFalse(Perfdata::fromString('test=1;;;2,00;10,00'));
$this->assertFalse(Perfdata::fromString('test=1;;;foo;1000'));
$this->assertFalse(Perfdata::fromString('test=1;10@:'));
$this->assertFalse(Perfdata::fromString('test=1;foo:'));
$this->assertFalse(Perfdata::fromString('test=1;2,2:4,4'));
}
}
20 changes: 20 additions & 0 deletions test/php/library/Icingadb/Util/ThresholdRangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,5 +319,25 @@ public function testInvalidThresholdNotationsAreRenderedAsIs()
'foo',
(string) ThresholdRange::fromString('foo')
);
$this->assertSame(
'4,4:2,2',
(string) ThresholdRange::fromString('4,4:2,2')
);
}

public function testInvalidThresholdNotationsConsideredInValid()
{
$this->assertFalse(
ThresholdRange::fromString('10@')->isValid(),
'Invalid threshold notation 10@ considered as valid'
);
$this->assertFalse(
ThresholdRange::fromString('foo')->isValid(),
'Invalid threshold notation foo considered as valid'
);
$this->assertFalse(
ThresholdRange::fromString('4,4:2,2')->isValid(),
'Invalid threshold notation 4,4:2,2 considered as valid'
);
}
}

0 comments on commit 4601873

Please sign in to comment.