| 1 |
<?php |
| 2 |
|
| 3 |
namespace Tests\Icinga\Module\Toplevelview; |
| 4 |
|
| 5 |
use Icinga\Module\Toplevelview\Tree\TLVStatus; |
| 6 |
|
| 7 |
use PHPUnit\Framework\TestCase; |
| 8 |
|
| 9 |
final class TLVStatusTest extends TestCase |
| 10 |
{ |
| 11 |
public function testGetOverall() |
| 12 |
{ |
| 13 |
$t = new TLVStatus(); |
| 14 |
$t->add('ok', 1); |
| 15 |
$this->assertSame('ok', $t->getOverall()); |
| 16 |
|
| 17 |
$t->add('missing', 1); |
| 18 |
$this->assertSame('ok', $t->getOverall()); |
| 19 |
|
| 20 |
$t->add('critical_handled', 1); |
| 21 |
$this->assertSame('critical handled', $t->getOverall()); |
| 22 |
|
| 23 |
$t->zero(); |
| 24 |
$t->add('total'); |
| 25 |
|
| 26 |
$this->assertSame(1, $t->get('total')); |
| 27 |
$this->assertSame(0, $t->get('missing')); |
| 28 |
} |
| 29 |
|
| 30 |
public function testGetOverallWithMissing() |
| 31 |
{ |
| 32 |
$t = new TLVStatus(); |
| 33 |
$this->assertSame('missing', $t->getOverall()); |
| 34 |
} |
| 35 |
|
| 36 |
public function testGetterSetter() |
| 37 |
{ |
| 38 |
$t = new TLVStatus(); |
| 39 |
$t->set('missing', 123); |
| 40 |
$this->assertSame(123, $t->get('missing')); |
| 41 |
|
| 42 |
$t->setMeta('hosts_total', 321); |
| 43 |
$this->assertSame(321, $t->getMeta('hosts_total')); |
| 44 |
$this->assertSame(null, $t->getMeta('services_total')); |
| 45 |
} |
| 46 |
|
| 47 |
public function testMerge() |
| 48 |
{ |
| 49 |
$b = new TLVStatus(); |
| 50 |
$b->set('ok', 1); |
| 51 |
$b->set('missing', 2); |
| 52 |
$b->set('warning_handled', 3); |
| 53 |
$b->set('critical_unhandled', 4); |
| 54 |
|
| 55 |
$a = new TLVStatus(); |
| 56 |
$a->set('ok', 3); |
| 57 |
$a->set('unknown_unhandled', 2); |
| 58 |
$a->set('missing', 1); |
| 59 |
|
| 60 |
$a->merge($b); |
| 61 |
$this->assertSame(3, $a->get('missing')); |
| 62 |
$this->assertSame(4, $a->get('ok')); |
| 63 |
$this->assertSame(3, $a->get('warning_handled')); |
| 64 |
$this->assertSame(4, $a->get('critical_unhandled')); |
| 65 |
$this->assertSame(2, $a->get('unknown_unhandled')); |
| 66 |
$this->assertSame(null, $a->get('warning_unhandled')); |
| 67 |
} |
| 68 |
} |