2016-02-25 18:24:17 +01:00
|
|
|
<?php
|
|
|
|
|
2016-02-26 12:01:00 +01:00
|
|
|
namespace Tests\Icinga\Module\Director\IcingaConfig;
|
2016-02-25 18:24:17 +01:00
|
|
|
|
|
|
|
use Icinga\Data\Filter\Filter;
|
|
|
|
use Icinga\Module\Director\IcingaConfig\AssignRenderer;
|
|
|
|
use Icinga\Module\Director\Test\BaseTestCase;
|
|
|
|
|
|
|
|
class AssignRendererTest extends BaseTestCase
|
|
|
|
{
|
2016-02-25 20:11:39 +01:00
|
|
|
public function testWhetherEqualMatchIsCorrectlyRendered()
|
|
|
|
{
|
|
|
|
$string = 'host.name="localhost"';
|
|
|
|
$expected = 'assign where host.name == "localhost"';
|
|
|
|
$this->assertEquals(
|
|
|
|
$expected,
|
|
|
|
$this->renderer($string)->renderAssign()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWhetherWildcardsRenderAMatchMethod()
|
|
|
|
{
|
|
|
|
$string = 'host.address="127.0.0.*"';
|
|
|
|
$expected = 'assign where match("127.0.0.*", host.address)';
|
|
|
|
$this->assertEquals(
|
|
|
|
$expected,
|
|
|
|
$this->renderer($string)->renderAssign()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-02-25 18:24:17 +01:00
|
|
|
public function testWhetherACombinedFilterRendersCorrectly()
|
|
|
|
{
|
|
|
|
$string = 'host.name="*internal"|(service.vars.priority<2'
|
|
|
|
. '&host.vars.is_clustered=true)';
|
|
|
|
|
|
|
|
$expected = 'assign where match("*internal", host.name) ||'
|
|
|
|
. ' (service.vars.priority < 2 && host.vars.is_clustered == true)';
|
|
|
|
|
2016-02-25 20:11:39 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
$expected,
|
|
|
|
$this->renderer($string)->renderAssign()
|
|
|
|
);
|
|
|
|
}
|
2016-02-25 18:24:17 +01:00
|
|
|
|
2016-02-25 20:11:39 +01:00
|
|
|
protected function renderer($string)
|
|
|
|
{
|
|
|
|
return AssignRenderer::forFilter(Filter::fromQueryString($string));
|
2016-02-25 18:24:17 +01:00
|
|
|
}
|
|
|
|
}
|