Remove statusdat protocol tests

refs #4639
This commit is contained in:
Johannes Meyer 2014-04-14 15:35:27 +02:00
parent 1555f55857
commit 301e29b5e8
12 changed files with 0 additions and 1085 deletions

View File

@ -1,66 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Tests\Icinga\Protocol\Statusdat\Component;
use \Zend_Config;
use Icinga\Test\BaseTestCase;
use Icinga\Protocol\Statusdat\Reader;
/**
* This is a high level test for the whole statusdat component, i.e. all parts put together
* and called like they would be in a real situation. This should work when all isolated tests have passed.
*/
class StatusdatComponentTest extends BaseTestCase
{
public function getReader() {
$reader = new Reader(new Zend_Config(array(
"status_file" => dirname(__FILE__)."/status.dat",
"object_file" => dirname(__FILE__)."/objects.cache"
)),null,true);
return $reader;
}
public function testServicegroupFilterFromService() {
$r = $this->getReader();
$group = array('a1','b2');
$result = $r->select()->from("services")->where("group IN ?",$group)->getResult();
$this->assertCount(9, $result, 'Assert items to be returned in a servicegroup filter');
foreach($result as $obj) {
$this->assertTrue(is_object($obj));
}
}
public function testServicegroupFilterFromHost() {
$r = $this->getReader();
$group = array('a1','b2');
$result = $r->select()->from("hosts")->where("services.group IN ?",$group)->getResult();
$this->assertCount(3, $result);
foreach($result as $obj) {
$this->assertTrue(is_object($obj));
}
}
public function testHostgroupFilterFromHost() {
$r = $this->getReader();
$group = array('exc-hostb');
$result = $r->select()->from("hosts")->where("group IN ?",$group)->getResult();
$this->assertCount(3, $result);
foreach($result as $obj) {
$this->assertTrue(is_object($obj));
}
}
public function testHostgroupFilterFromService() {
$r = $this->getReader();
$group = array('exc-hostb');
$result = $r->select()->from("services")->where("host.group IN ?", $group)->getResult();
$this->assertCount(9, $result);
foreach($result as $obj) {
$this->assertTrue(is_object($obj));
}
}
}

View File

@ -1,124 +0,0 @@
define servicegroup {
servicegroup_name sv1
alias testsv1
members hosta,servicea1,hostb,serviceb1,hostc,servicec1
}
define servicegroup {
servicegroup_name a1
alias testsa1
members hosta,servicea1
}
define servicegroup {
servicegroup_name b2
alias testsb2
members hostb,serviceb2
}
define servicegroup {
servicegroup_name sv2
alias testsv2
members hosta,servicea2,hostb,serviceb2,hostc,servicec2
}
define hostgroup {
hostgroup_name all-hosts
alias All hosts
members hosta,hostb,hostc
}
define hostgroup {
hostgroup_name exc-hostb
alias Excluded host b
members hosta,hostc
}
define host {
host_name hosta
alias hosta
address 127.0.0.5
parents hosta
check_period 24x7
check_command check-host-alive
contact_groups admins
notification_period workhours
}
define host {
host_name hostb
alias hostb
address 127.0.0.5
parents hostb
check_period 24x7
check_command check-host-alive
contact_groups admins
notification_period workhours
}
define host {
host_name hostc
alias hostc
address 127.0.0.5
parents hostc
check_period 24x7
check_command check-host-alive
contact_groups admins
notification_period workhours
}
define service {
host_name hosta
service_description servicea1
check_period 24x7
check_command check_icinga_startup_delay
}
define service {
host_name hosta
service_description servicea2
check_period 24x7
check_command check_icinga_startup_delay
}
define service {
host_name hosta
service_description servicea3
check_period 24x7
check_command check_icinga_startup_delay
}
define service {
host_name hostb
service_description serviceb1
check_period 24x7
check_command check_icinga_startup_delay
}
define service {
host_name hostb
service_description serviceb2
check_period 24x7
check_command check_icinga_startup_delay
}
define service {
host_name hostb
service_description serviceb3
check_period 24x7
check_command check_icinga_startup_delay
}
define service {
host_name hostc
service_description servicec1
check_period 24x7
check_command check_icinga_startup_delay
}
define service {
host_name hostc
service_description servicec2
check_period 24x7
check_command check_icinga_startup_delay
}
define service {
host_name hostc
service_description servicec3
check_period 24x7
check_command check_icinga_startup_delay
}

View File

@ -1,211 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Tests\Icinga\Protocol\Statusdat;
use Icinga\Test\BaseTestCase;
use Icinga\Protocol\Statusdat\Parser;
class ParserTest extends BaseTestCase
{
private function getStringAsFileHandle($string)
{
$fhandle = fopen("php://memory", 'r+');
fputs($fhandle, $string);
rewind($fhandle);
return $fhandle;
}
public function testSimpleObjectCacheParsing()
{
$fd = $this->getStringAsFileHandle("
define hostescalation {
host_name\ttest
key\tvalue
}
define host {
host_name\ttest
alias\ttest123
}
define host {
host_name\ttest2
alias\ttest123
}
define service {
host_name\ttest
service_description\tCurrent Users
}
define servicegroup {
servicegroup_name\tgroup
members\ttest,Current Users
}
");
$testParser = new Parser($fd);
$testParser->parseObjectsFile();
$state = $testParser->getRuntimeState();
$this->assertTrue(is_array($state));
$this->assertTrue(isset($state["host"]));
$this->assertTrue(isset($state["service"]));
$this->assertEquals("test",$state["host"]["test"]->host_name);
$this->assertTrue(is_array($state["host"]["test"]->escalation));
$this->assertTrue(isset($state["service"]["test;Current Users"]->group));
$this->assertTrue(is_array($state["service"]["test;Current Users"]->group));
$this->assertCount(1,$state["service"]["test;Current Users"]->group);
$this->assertEquals("group",$state["service"]["test;Current Users"]->group[0]);
$this->assertEquals("value",$state["host"]["test"]->escalation[0]->key);
$this->assertEquals("test2",$state["host"]["test2"]->host_name);
}
public function testRuntimeParsing()
{
$baseState = array(
"host" => array(
"test" => (object) array(
"host_name" => "test"
),
"test2" => (object) array(
"host_name" => "test2"
)
),
"service" => array(
"test;Current Users" => (object) array(
"host_name" => "test",
"service_description" => "Current Users"
)
)
);
$fd = $this->getStringAsFileHandle(self::RUNTIME_STATE1);
$testParser = new Parser($fd, $baseState);
$testParser->parseRuntimeState();
$state = $testParser->getRuntimeState();
$this->assertTrue(isset($state["host"]["test"]->status));
$this->assertEquals(3,$state["host"]["test"]->status->current_state);
$this->assertTrue(is_array($state["host"]["test"]->comment));
$this->assertEquals(2,count($state["host"]["test"]->comment));
}
public function testOverwriteRuntime()
{
$baseState = array(
"host" => array(
"test" => (object) array(
"host_name" => "test"
),
"test2" => (object) array(
"host_name" => "test2"
)
),
"service" => array(
"test;Current Users" => (object) array(
"host_name" => "test",
"service_description" => "Current Users"
)
)
);
$fd = $this->getStringAsFileHandle(self::RUNTIME_STATE1);
$testParser = new Parser($fd, $baseState);
$testParser->parseRuntimeState();
$state = $testParser->getRuntimeState();
$this->assertTrue(isset($state["host"]["test"]->status));
$this->assertEquals(3,$state["host"]["test"]->status->current_state);
$this->assertTrue(is_array($state["host"]["test"]->comment));
$this->assertEquals(2,count($state["host"]["test"]->comment));
$fd = $this->getStringAsFileHandle(self::RUNTIME_STATE2);
$testParser->parseRuntimeState($fd);
$state = $testParser->getRuntimeState();
$this->assertTrue(isset($state["host"]["test"]->status));
$this->assertEquals(2,$state["host"]["test"]->status->current_state);
$this->assertTrue(is_array($state["host"]["test"]->comment));
$this->assertEquals(3,count($state["host"]["test"]->comment));
}
/**
* Assert no errors occuring
*/
public function testRuntimeParsingForBigFile()
{
$objects = fopen("./res/status/icinga.objects.cache","r");
$status = fopen("./res/status/icinga.status.dat","r");
$testParser = new Parser($objects);
$testParser->parseObjectsFile();
$testParser->parseRuntimeState($status);
}
const RUNTIME_STATE1 = "
hoststatus {
host_name=test
current_state=3
test=test123
}
hoststatus {
host_name=test2
current_state=3
test=test123
}
servicestatus {
host_name=test
service_description=Current Users
current_state=3
}
hostcomment {
host_name=test
key=value1
}
hostcomment {
host_name=test
key=value2
}";
const RUNTIME_STATE2 = "
hoststatus {
host_name=test
current_state=2
test=test123
}
hoststatus {
host_name=test2
current_state=2
test=test123
}
servicestatus {
host_name=test
service_description=Current Users
current_state=2
}
hostcomment {
host_name=test
key=value14
}
hostcomment {
host_name=test
key=value15
}
hostcomment {
host_name=test
key=value24
}";
}

View File

@ -1,139 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Tests\Icinga\Protocol\Statusdat\Query;
use Icinga\Test\BaseTestCase;
use Icinga\Protocol\Statusdat\Query\Expression;
class ExpressionTest extends BaseTestCase
{
public function testFromStringParsing()
{
$assertions = array(
"expression > ?" => "isGreater",
"expression >= ?" => "isGreaterEq",
"expression <= ?" => "isLessEq",
"expression < ?" => "isLess",
"expression = ?" => "isEqual",
"expression != ?" => "isNotEqual",
"expression like ?" => "isLike",
"expression IN ? " => "isIn"
);
foreach ($assertions as $query => $callback) {
$expression = new Expression();
$value = array(10);
$expression->fromString($query, $value);
$this->assertCount(0, $value);
$this->assertEquals("expression", $expression->getField());
$this->assertEquals($callback, $expression->CB);
}
}
public function testNumericComparisons()
{
$assertions = array( // subarrays are (TEST,MATCHES)
"expression < ?" => array(5, array(1, 2, 3, 4)),
"expression <= ?" => array(5, array(1, 2, 3, 4, 5)),
"expression >= ?" => array(5, array(5, 6, 7)),
"expression > ?" => array(5, array(6, 7)),
"expression = ?" => array(5, array(5)),
"expression != ?" => array(5, array(1, 2, 3, 4, 6, 7)),
"expression IN ?" => array(array(1, 5, 7), array(1, 5, 7))
);
foreach ($assertions as $query => $test) {
$expression = new Expression();
$value = array($test[0]);
$testArray = array(
(object)array("expression" => 1),
(object)array("expression" => 2),
(object)array("expression" => 3),
(object)array("expression" => 4),
(object)array("expression" => 5),
(object)array("expression" => 6),
(object)array("expression" => 7)
);
$expression->fromString($query, $value);
$this->assertCount(0, $value);
$result = $expression->filter($testArray);
foreach ($result as $index) {
$this->assertContains($index + 1, $test[1]);
}
}
}
public function testNestedComparison()
{
$testArray = array(
(object)array(
"expression" => "atest",
"state" => (object)array("value" => 1)
),
(object)array(
"expression" => "testa",
"state" => (object)array("value" => 2)
)
);
$expression = new Expression();
$value = array(1);
$expression->fromString("state.value > ?", $value);
$this->assertCount(0, $value);
$result = $expression->filter($testArray);
$this->assertEquals(1, count($result));
$this->assertEquals(2, $testArray[$result[1]]->state->value);
}
public function testNestedComparisonInArray()
{
$testArray = array(
(object)array(
"expression" => "atest",
"state" => array((object) array("test"=>"1","test2"=>1))
),
(object)array(
"expression" => "testa",
"state" => array((object) array("test"=>"2","test2"=>2))
)
);
$expression = new Expression();
$value = array(1);
$expression->fromString("state.test > ?", $value);
$this->assertCount(0, $value);
$result = $expression->filter($testArray);
$this->assertEquals(1, count($result));
}
public function testCountQuery()
{
$testArray = array(
(object)array(
"expression" => "atest",
"multiple" => array("test"=>"1","test2"=>1)
),
(object)array(
"expression" => "testa",
"multiple" => array("test"=>"2","test2"=>2,"test5"=>2,"test1"=>2,"test3"=>2,"test4"=>2)
)
);
$expression = new Expression();
$value = array(2);
$expression->fromString("COUNT{multiple} > ?", $value);
$this->assertCount(0, $value);
$result = $expression->filter($testArray);
$this->assertEquals(1, count($result));
}
public function testFilter()
{
$this->markTestIncomplete('testFilter is not implemented yet');
}
}

View File

@ -1,227 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Tests\Icinga\Protocol\Statusdat\Query;
use Icinga\Test\BaseTestCase;
use Icinga\Protocol\Statusdat\Query\Group;
use Icinga\Protocol\Statusdat\Query\IQueryPart;
class QueryExpressionMock implements IQueryPart
{
public $rawExpression;
public $value;
public $filter = array();
public function __construct($expression = null, &$value = array())
{
$this->value = array_shift($value);
$this->rawExpression = $expression;
}
public function filter(array &$base, &$idx = null)
{
return array_intersect(array_values($idx), array_values($this->filter));
}
/**
* Add additional information about the query this filter belongs to
*
* @param $query
* @return mixed
*/
public function setQuery($query)
{
// TODO: Implement setQuery() method.
}
}
class GroupTest extends BaseTestCase
{
public function testParsingSingleCondition()
{
$testQuery = new Group();
$value = array(4);
$testQuery->fromString(
"numeric_val >= ?",
$value,
"Tests\Icinga\Protocol\Statusdat\Query\QueryExpressionMock"
);
$this->assertCount(1, $testQuery->getItems());
$this->assertCount(0, $value);
$expression = $testQuery->getItems();
$expression = $expression[0];
$this->assertEquals("numeric_val >= ?", $expression->rawExpression);
$this->assertEquals(4, $expression->value);
}
public function testParsingSimpleAndCondition()
{
$testQuery = new Group();
$value = array(4, 'hosta');
$testQuery->fromString(
"numeric_val >= ? AND host_name = ?",
$value,
"Tests\Icinga\Protocol\Statusdat\Query\QueryExpressionMock"
);
$this->assertCount(2, $testQuery->getItems());
$this->assertCount(0, $value);
$this->assertEquals("AND", $testQuery->getType());
$items = $testQuery->getItems();
$expression0 = $items[0];
$this->assertEquals("numeric_val >= ?", $expression0->rawExpression);
$this->assertEquals(4, $expression0->value);
$expression1 = $items[1];
$this->assertEquals("host_name = ?", $expression1->rawExpression);
$this->assertEquals("hosta", $expression1->value);
}
public function testParsingSimpleORCondition()
{
$testQuery = new Group();
$value = array(4, 'hosta');
$testQuery->fromString(
"numeric_val >= ? OR host_name = ?",
$value,
"Tests\Icinga\Protocol\Statusdat\Query\QueryExpressionMock"
);
$this->assertCount(2, $testQuery->getItems());
$this->assertCount(0, $value);
$this->assertEquals("OR", $testQuery->getType());
$items = $testQuery->getItems();
$expression0 = $items[0];
$this->assertEquals("numeric_val >= ?", $expression0->rawExpression);
$this->assertEquals(4, $expression0->value);
$expression1 = $items[1];
$this->assertEquals("host_name = ?", $expression1->rawExpression);
$this->assertEquals("hosta", $expression1->value);
}
public function testParsingExplicitSubgroup()
{
$testQuery = new Group();
$value = array(4, 'service1', 'hosta');
$testQuery->fromString(
"numeric_val >= ? AND (service_description = ? OR host_name = ?)",
$value,
"Tests\Icinga\Protocol\Statusdat\Query\QueryExpressionMock"
);
$this->assertCount(2, $testQuery->getItems());
$this->assertCount(0, $value);
$this->assertEquals("AND", $testQuery->getType());
$items = $testQuery->getItems();
$expression0 = $items[0];
$this->assertEquals("numeric_val >= ?", $expression0->rawExpression);
$this->assertEquals(4, $expression0->value);
$subgroup = $items[1];
$this->assertInstanceOf("Icinga\Protocol\Statusdat\Query\Group", $subgroup);
$this->assertEquals("OR", $subgroup->getType());
$orItems = $subgroup->getItems();
$expression1 = $orItems[0];
$this->assertEquals("service_description = ?", $expression1->rawExpression);
$this->assertEquals("service1", $expression1->value);
$expression2 = $orItems[1];
$this->assertEquals("host_name = ?", $expression2->rawExpression);
$this->assertEquals("hosta", $expression2->value);
}
public function testParsingImplicitSubgroup()
{
$testQuery = new Group();
$value = array(4, 'service1', 'hosta');
$testQuery->fromString(
"numeric_val >= ? AND service_description = ? OR host_name = ?",
$value,
"Tests\Icinga\Protocol\Statusdat\Query\QueryExpressionMock"
);
$this->assertCount(2, $testQuery->getItems());
$this->assertCount(0, $value);
$this->assertEquals("AND", $testQuery->getType());
$items = $testQuery->getItems();
$expression0 = $items[0];
$this->assertEquals("numeric_val >= ?", $expression0->rawExpression);
$this->assertEquals(4, $expression0->value);
$subgroup = $items[1];
$this->assertInstanceOf("Icinga\Protocol\Statusdat\Query\Group", $subgroup);
$this->assertEquals("OR", $subgroup->getType());
$orItems = $subgroup->getItems();
$expression1 = $orItems[0];
$this->assertEquals("service_description = ?", $expression1->rawExpression);
$this->assertEquals("service1", $expression1->value);
$expression2 = $orItems[1];
$this->assertEquals("host_name = ?", $expression2->rawExpression);
$this->assertEquals("hosta", $expression2->value);
}
public function testAndFilter()
{
$testQuery = new Group();
$testQuery->setType(Group::TYPE_AND);
$exp1 = new QueryExpressionMock();
$exp1->filter = array(1, 2, 3, 4, 5, 6, 8);
$exp2 = new QueryExpressionMock();
$exp2->filter = array(3, 4, 8);
$base = array(0, 1, 2, 3, 4, 5, 6, 7, 8);
$this->assertEquals(
array(3, 4, 8),
array_values($testQuery->addItem($exp1)->addItem($exp2)->filter($base))
);
}
public function testOrFilter()
{
$testQuery = new Group();
$testQuery->setType(Group::TYPE_OR);
$exp1 = new QueryExpressionMock();
$exp1->filter = array(1, 2, 3);
$exp2 = new QueryExpressionMock();
$exp2->filter = array(3, 4, 6, 8);
$base = array(0, 1, 2, 3, 4, 5, 6, 7, 8);
$this->assertEquals(
array(1, 2, 3, 4, 6, 8),
array_values($testQuery->addItem($exp1)->addItem($exp2)->filter($base))
);
}
public function testCombinedFilter()
{
$testQuery_and = new Group();
$testQuery_and->setType(Group::TYPE_AND);
$testQuery_or = new Group();
$testQuery_or->setType(Group::TYPE_OR);
$base = array(0, 1, 2, 3, 4, 5, 6, 7, 8);
$and_exp1 = new QueryExpressionMock();
$and_exp1->filter = array(1, 2, 3, 4, 5, 6, 8);
$and_exp2 = new QueryExpressionMock();
$and_exp2->filter = array(3, 4, 8);
$or_exp1 = new QueryExpressionMock();
$or_exp1->filter = array(1, 2, 3);
$or_exp2 = new QueryExpressionMock();
$or_exp2->filter = array(3, 4, 6, 8);
$this->assertEquals(array(3, 4, 8), array_values(
$testQuery_and
->addItem($and_exp1)
->addItem($and_exp2)
->addItem($testQuery_or->addItem($or_exp1)->addItem($or_exp2))
->filter($base))
);
}
}

View File

@ -1,131 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Tests\Icinga\Protocol\Statusdat;
use Icinga\Test\BaseTestCase;
use Icinga\Protocol\Statusdat\Query;
class QueryTest extends BaseTestCase
{
public function testSimpleServiceSelect()
{
$readerMock = $this->getServiceTestReader();
$query = new Query($readerMock);
$objects = $readerMock->getObjects();
$result = $query->select()->from("services")->getResult();
$this->assertCount(count($objects["service"]), $result);
}
public function testSimpleHostSelect()
{
$readerMock = $this->getServiceTestReader();
$query = new Query($readerMock);
$objects = $readerMock->getObjects();
$result = $query->from("hosts")->getResult();
$this->assertCount(count($objects["host"]), $result);
}
public function testLimit()
{
$readerMock = $this->getServiceTestReader();
$objects = $readerMock->getObjects();
$query = new Query($readerMock);
$result = $query->from("services")->limit(2)->getResult();
$this->assertCount(2, $result);
}
public function testOffset()
{
$readerMock = $this->getServiceTestReader();
$objects = $readerMock->getObjects();
$query = new Query($readerMock);
$result = $query->from("services")->limit(2, 4)->getResult();
$this->assertCount(2, $result);
}
public function testGroupByColumn()
{
$readerMock = $this->getServiceTestReader();
$objects = $readerMock->getObjects();
$query = new Query($readerMock);
$result = $query->from("services")->groupByColumns("numeric_val")->getResult();
$this->assertCount(3,$result);
foreach($result as $value) {
$this->assertTrue(isset($value->count));
$this->assertTrue(isset($value->columns));
$this->assertEquals(2,$value->count);
}
}
public function testOrderedGroupByColumn()
{
$readerMock = $this->getServiceTestReader();
$objects = $readerMock->getObjects();
$query = new Query($readerMock);
$result = $query->from("services")->order('numeric_val ASC')->groupByColumns("numeric_val")->getResult();
$this->assertCount(3,$result);
foreach($result as $sstatus) {
$this->assertTrue(isset($sstatus->count));
$this->assertTrue(isset($sstatus->columns));
$this->assertEquals(2, $sstatus->count);
}
}
private function getServiceTestReader()
{
$readerMock = new ReaderMock(array(
"host" => array(
"hosta" => (object) array(
"host_name" => "hosta",
"numeric_val" => 0,
"services" => array(0, 1, 2)
),
"hostb" => (object) array(
"host_name" => "hostb",
"numeric_val" => 0,
"services" => array(3, 4, 5)
)
),
"service" => array(
"hosta;service1" => (object) array(
"host_name" => "hosta",
"service_description" => "service1",
"numeric_val" => 1
),
"hosta;service2" => (object) array(
"host_name" => "hosta",
"service_description" => "service2",
"numeric_val" => 3
),
"hosta;service3" => (object) array(
"host_name" => "hosta",
"service_description" => "service3",
"numeric_val" => 2
),
"hostb;service1" => (object) array(
"host_name" => "hostb",
"service_description" => "service1",
"numeric_val" => 1
),
"hostb;service2" => (object) array(
"host_name" => "hostb",
"service_description" => "service2",
"numeric_val" => 3
),
"hostb;service3" => (object) array(
"host_name" => "hostb",
"service_description" => "service3",
"numeric_val" => 2
)
)
));
return $readerMock;
}
}

View File

@ -1,54 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Tests\Icinga\Protocol\Statusdat;
use Icinga\Data\DatasourceInterface;
use Icinga\Protocol\Statusdat\IReader;
class ReaderMock implements IReader, DatasourceInterface
{
private $objects;
private $indices;
public function __construct(array $objects = array())
{
$this->objects = $objects;
}
public function getState()
{
return $this->objects;
}
public function getInternalState()
{
return array(
"objects" => $this->objects,
"indices" => $this->indices
);
}
public function getObjects()
{
return $this->objects;
}
public function __call($arg1, $arg2) {
return $this;
}
public function select()
{
return $this;
}
public function getObjectByName($type, $idx)
{
if (isset($this->objects[$type]) && isset($this->objects[$type][$idx])) {
return $this->objects[$type][$idx];
}
}
}

View File

@ -1,94 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Tests\Icinga\Protocol\Statusdat;
use Icinga\Test\BaseTestCase;
use Icinga\Protocol\Statusdat\Reader;
class ConfigMock
{
function __construct($data)
{
foreach ($data as $key => $val) {
$this->$key = $val;
}
}
function get($attr)
{
return $this->$attr;
}
}
class ParserMock
{
public $runtime = array();
public $objects = array();
public function parseObjectsFile()
{
return $this->objects;
}
public function parseRuntimeState()
{
return $this->runtime;
}
public function getRuntimeState()
{
return $this->runtime;
}
}
class ReaderTest extends BaseTestCase
{
public function tearDown()
{
parent::tearDown();
if (file_exists('./tmp')) {
@system("rm -rf ./tmp");
}
}
public function testFileCaching()
{
if (!file_exists('./tmp')) {
mkdir('./tmp');
}
$parser = new ParserMock();
$parser->runtime = array(
"host" => array(
"test" => (object)array(
"host_name" => "test"
)
)
);
$cacheDir = realpath(dirname(__FILE__) . '/.cache');
$object_file = tempnam("./dir", "object");
$status_file = tempnam("./dir", "status");
$reader = new Reader(new ConfigMock(array(
"cache_path" => $cacheDir,
"object_file" => $object_file,
"status_file" => $status_file
)), $parser);
unlink($object_file);
unlink($status_file);
$this->assertTrue(file_exists($cacheDir . '/zend_cache---object' . md5($object_file)));
$this->assertTrue(file_exists($cacheDir . '/zend_cache---state' . md5($object_file)));
system('rm ' . $cacheDir . '/zend_cache*');
}
public function testEmptyFileException()
{
$this->setExpectedException("Icinga\Exception\ConfigurationError");
$parser = new ParserMock();
$reader = new Reader(new ConfigMock(array(
"cache_path" => "/tmp",
"object_file" => "",
"status_file" => "",
)), $parser);
}
}

View File

@ -1,25 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Tests\Icinga\Protocol\Statusdat;
use Icinga\Test\BaseTestCase;
use Icinga\Protocol\Statusdat\RuntimeStateContainer;
class RuntimestatecontainerTest extends BaseTestCase
{
public function testPropertyResolving()
{
$container = new RuntimeStateContainer("
host_name=test host
current_state=0
plugin_output=test 1234 test test
test=dont read
");
$container->test = "test123";
$this->assertEquals("test host",$container->host_name);
$this->assertEquals($container->test,"test123");
$this->assertEquals(0,$container->current_state);
}
}

View File

@ -1,14 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Tests\Icinga\Web;
use \Zend_View_Abstract;
class ViewMock extends Zend_View_Abstract
{
protected function _run()
{
}
}