Files
librenms-librenms/spec/InfluxDB/ClientSpec.php
T

99 lines
2.8 KiB
PHP
Raw Normal View History

2014-09-10 12:00:46 +02:00
<?php
namespace spec\InfluxDB;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
2014-09-12 20:20:23 +02:00
use InfluxDB\Adapter\GuzzleAdapter;
use InfluxDB\Adapter\UdpAdapter;
2014-09-12 23:22:37 +02:00
use InfluxDB\Adapter\AdapterInterface;
2014-09-14 17:36:29 +02:00
use InfluxDB\Filter\FilterInterface;
use InfluxDb\Adapter\QueryableInterface;
2014-09-10 12:00:46 +02:00
class ClientSpec extends ObjectBehavior
{
function let(\InfluxDB\Adapter\AdapterInterface $adapter)
{
2014-09-11 09:59:33 +02:00
$this->setAdapter($adapter);
2014-09-10 12:00:46 +02:00
}
2014-09-12 23:22:37 +02:00
2014-09-10 12:00:46 +02:00
function it_is_initializable()
{
$this->shouldHaveType('InfluxDB\Client');
}
2014-09-12 23:22:37 +02:00
function it_should_send_data(AdapterInterface $adapter)
2014-09-10 12:00:46 +02:00
{
2014-09-10 12:47:26 +02:00
$adapter->send([[
2014-09-10 12:00:46 +02:00
"name" => "video.search",
"columns" => ["author", "title"],
"points" => [
["Guccini", "Autogrill"]
2014-09-11 09:59:33 +02:00
]
2014-09-13 09:17:34 +02:00
]], false)->shouldBeCalledTimes(1);
2014-09-10 12:00:46 +02:00
$this->mark("video.search", [
"author" => "Guccini",
"title" => "Autogrill"
2014-09-11 09:59:33 +02:00
]);
2014-09-10 12:00:46 +02:00
}
2014-09-12 20:20:23 +02:00
2014-09-13 09:17:34 +02:00
function it_should_send_data_with_time_precision(AdapterInterface $adapter)
{
$adapter->send([[
"name" => "video.search",
"columns" => ["time", "author", "title"],
"points" => [
["1410591552", "Guccini", "Autogrill"]
]
]], "s")->shouldBeCalledTimes(1);
$this->mark("video.search", [
"time" => "1410591552",
"author" => "Guccini",
"title" => "Autogrill"
], "s");
}
2014-09-12 20:20:23 +02:00
function it_should_query_on_querable_adapter(GuzzleAdapter $adapter)
{
$this->setAdapter($adapter);
$adapter->query("select * from tcp.test", false)->willReturn([]);
$this->query("select * from tcp.test")->shouldReturn([]);
}
function it_should_query_with_time_precision(GuzzleAdapter $adapter)
{
$this->setAdapter($adapter);
$adapter->query("select * from tcp.test", "s")->willReturn([]);
$this->query("select * from tcp.test", "s")->shouldReturn([]);
}
function it_should_query_but_skip_invalid_time_precision(GuzzleAdapter $adapter)
{
$this->setAdapter($adapter);
$adapter->query("select * from tcp.test", false)->willReturn([]);
$this->query("select * from tcp.test", "r")->shouldReturn([]);
}
function it_should_thrown_an_exception_on_unquerable_adapter(UdpAdapter $adapter)
{
$this->setAdapter($adapter);
$this->shouldThrow("\\BadMethodCallException")->duringQuery("select * from tcp.test");
}
2014-09-14 17:36:29 +02:00
function it_should_filter_returned_data(FilterInterface $filter, QueryableInterface $adapter)
{
2014-09-14 18:01:04 +02:00
$adapter->query(Argument::Any(), Argument::Any())->willReturn(null);
2014-09-14 17:36:29 +02:00
$filter->filter(Argument::Any())->shouldBeCalledTimes(1)->willReturn([]);
$this->setFilter($filter);
$this->setAdapter($adapter);
$this->query("select * from tcp.test")->shouldReturn([]);
}
2014-09-10 12:00:46 +02:00
}