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

Extend TLVTree tests #89

Merged
merged 1 commit into from
Oct 1, 2024
Merged
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
3 changes: 3 additions & 0 deletions library/Toplevelview/Tree/TLVIcingaNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

use Icinga\Exception\NotImplementedError;

/**
* @codeCoverageIgnore
*/
class TLVIcingaNode extends TLVTreeNode
{
protected static $canHaveChildren = false;
Expand Down
1 change: 1 addition & 0 deletions library/Toplevelview/Web/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Controller wraps around the Icinga\Web\Controller to
* check for the PHP YAML extension
*
* @codeCoverageIgnore
* @throws ConfigurationError if the PHP yaml extension is not loaded
*/
class Controller extends CompatController
Expand Down
44 changes: 44 additions & 0 deletions test/php/library/Toplevelview/Tree/TLVHostGroupNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,48 @@ public function getFetched($type, $key) {

$this->assertSame('unit', $n->getTitle());
}

public function testGetStatus()
{
$n = new TLVHostGroupNode();
$n->setProperties(['hostgroup'=>'unit']);

$mockRoot = new class {
public function get($thing) {
return false;
}
public function getFetched($type, $key) {
$h = new stdClass;
$s = new stdClass;
$s->hard_state = 1;
$s->is_handled = true;
$s->in_downtime = true;
$h->display_name = 'hostgroup';

$h->hosts_total = 1;
$h->hosts_up = 1;
$h->hosts_total = 1;
$h->services_total = 1;
$h->hosts_up = 1;
$h->services_ok = 1;
$h->hosts_down_handled = 1;
$h->hosts_down_unhandled = 1;
$h->services_warning_handled = 1;
$h->services_warning_unhandled = 1;
$h->services_critical_handled = 1;
$h->services_critical_unhandled = 1;
$h->services_unknown_handled = 1;
$h->services_unknown_unhandled = 1;

return $h;
}
};

$reflection = new ReflectionClass($n);
$reflection_root = $reflection->getProperty('root');
$reflection_root->setAccessible(true);
$reflection_root->setValue($n, $mockRoot);

$this->assertSame('critical unhandled', $n->getStatus()->getOverall());
}
}
12 changes: 11 additions & 1 deletion test/php/library/Toplevelview/Tree/TLVHostNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,19 @@ public function testGetStatus()
$n->setProperties(['host'=>'unit']);

$mockRoot = new class {
public function get($thing) {
return false;
}
public function getFetched($type, $key) {
$h = new stdClass;
$h->display_name = 'host';
$s = new stdClass;
$s->hard_state = 2;
$s->is_handled = false;
$s->in_downtime = false;
$h->notifications_enabled = false;
$h->state = $s;
return $h;
}
};

Expand All @@ -48,6 +58,6 @@ public function getFetched($type, $key) {
$reflection_root->setAccessible(true);
$reflection_root->setValue($n, $mockRoot);

$this->assertSame('missing', $n->getStatus()->getOverall());
$this->assertSame('critical unhandled', $n->getStatus()->getOverall());
}
}
38 changes: 38 additions & 0 deletions test/php/library/Toplevelview/Tree/TLVServiceGroupNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,42 @@ public function getFetched($type, $key) {

$this->assertSame('unit', $n->getTitle());
}

public function testGetStatus()
{
$n = new TLVServiceGroupNode();
$n->setProperties(['servicegroup'=>'unit']);

$mockRoot = new class {
public function get($thing) {
return false;
}
public function getFetched($type, $key) {
$h = new stdClass;
$s = new stdClass;
$s->hard_state = 1;
$s->is_handled = true;
$s->in_downtime = true;
$h->display_name = 'servicegroup';

$h->services_total = 1;
$h->services_ok = 1;
$h->services_warning_handled = 1;
$h->services_warning_unhandled = 1;
$h->services_critical_handled = 1;
$h->services_critical_unhandled = 1;
$h->services_unknown_handled = 1;
$h->services_unknown_unhandled = 1;

return $h;
}
};

$reflection = new ReflectionClass($n);
$reflection_root = $reflection->getProperty('root');
$reflection_root->setAccessible(true);
$reflection_root->setValue($n, $mockRoot);

$this->assertSame('critical unhandled', $n->getStatus()->getOverall());
}
}
12 changes: 11 additions & 1 deletion test/php/library/Toplevelview/Tree/TLVServiceNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,19 @@ public function testGetStatus()
$n->setProperties(['service'=>'unit', 'host'=>'test']);

$mockRoot = new class {
public function get($thing) {
return false;
}
public function getFetched($type, $key) {
$h = new stdClass;
$s = new stdClass;
$s->hard_state = 1;
$s->is_handled = true;
$s->in_downtime = true;
$h->display_name = 'service';
$h->notifications_enabled = false;
$h->state = $s;
return $h;
}
};

Expand All @@ -48,6 +58,6 @@ public function getFetched($type, $key) {
$reflection_root->setAccessible(true);
$reflection_root->setValue($n, $mockRoot);

$this->assertSame('missing', $n->getStatus()->getOverall());
$this->assertSame('downtime handled', $n->getStatus()->getOverall());
}
}
29 changes: 29 additions & 0 deletions test/php/library/Toplevelview/Tree/TLVTreeNodeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Tests\Icinga\Module\Toplevelview;

use Icinga\Module\Toplevelview\Tree\TLVTreeNode;

use PHPUnit\Framework\TestCase;

final class TLVTreeNodeTest extends TestCase
{
public function testGetTitle()
{
$n = new TLVTreeNode();

$n->setProperties(['name' => 'bar']);
$this->assertSame('bar', $n->getTitle());

$this->assertSame(['name' => 'bar'], $n->getProperties());

$n->set('name', 'foo');
$this->assertSame('foo', $n->getTitle());
}

public function testGetBreadCrumb()
{
$n = new TLVTreeNode();
$this->assertSame([$n], $n->getBreadCrumb());
}
}
12 changes: 12 additions & 0 deletions test/php/library/Toplevelview/ViewConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,16 @@ public function testViewConfigWithSession()
$this->assertFalse($view->hasBeenLoadedFromSession());
$this->assertTrue($view2->hasBeenLoadedFromSession());
}

public function testViewConfigTree()
{
$c = new ViewConfig('test/testdata');
$view = $c->loadByName('example');

$t = $view->getTree();
$this->assertSame('5fc0ad55066b871d376eee60c84300d32ac7cb1d', $t->getViewChecksum());
$this->assertSame('example', $t->getViewName());
$t->setCacheLifetime(120);
$this->assertSame(120, $t->getCacheLifetime());
}
}