From a99252ee5e0c6545d8af8cc0ddb37c221d233e61 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 3 Mar 2017 09:07:43 +0100 Subject: [PATCH] HostApplyMatchesTest: new tests --- .../Director/Objects/HostApplyMatchesTest.php | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 test/php/library/Director/Objects/HostApplyMatchesTest.php diff --git a/test/php/library/Director/Objects/HostApplyMatchesTest.php b/test/php/library/Director/Objects/HostApplyMatchesTest.php new file mode 100644 index 00000000..4811044b --- /dev/null +++ b/test/php/library/Director/Objects/HostApplyMatchesTest.php @@ -0,0 +1,78 @@ +sampleHost()); + $this->assertTrue( + $matcher->matchesFilter( + Filter::fromQueryString('host.name=%22aha%22') + ) + ); + $this->assertFalse( + $matcher->matchesFilter( + Filter::fromQueryString('host.name=%22ahaa%22') + ) + ); + } + + public function testWildcardMatches() + { + $matcher = HostApplyMatches::prepare($this->sampleHost()); + $this->assertTrue( + $matcher->matchesFilter( + Filter::fromQueryString('host.name=%22ah*%22') + ) + ); + $this->assertTrue( + $matcher->matchesFilter( + Filter::fromQueryString('host.name=%22*h*%22') + ) + ); + $this->assertFalse( + $matcher->matchesFilter( + Filter::fromQueryString('host.name=%22*g*%22') + ) + ); + } + + public function testStringVariableMatches() + { + $matcher = HostApplyMatches::prepare($this->sampleHost()); + $this->assertTrue( + $matcher->matchesFilter( + Filter::fromQueryString('host.vars.location=%22*urem*%22') + ) + ); + $this->assertTrue( + $matcher->matchesFilter( + Filter::fromQueryString('host.vars.location=%22Nuremberg%22') + ) + ); + $this->assertFalse( + $matcher->matchesFilter( + Filter::fromQueryString('host.vars.location=%22Nurembergg%22') + ) + ); + } + + protected function sampleHost() + { + return IcingaHost::create(array( + 'object_type' => 'object', + 'object_name' => 'aha', + 'vars' => array( + 'location' => 'Nuremberg', + 'tags' => array('Special', 'Amazing'), + ) + )); + } +}