mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
96 lines
2.8 KiB
PHP
96 lines
2.8 KiB
PHP
<?php
|
|
namespace InfluxDB;
|
|
|
|
use InfluxDB\Adapter\GuzzleAdapter as InfluxHttpAdapter;
|
|
use InfluxDB\Options;
|
|
use GuzzleHttp\Client as GuzzleHttpClient;
|
|
use crodas\InfluxPHP\Client as Crodas;
|
|
|
|
class ClientTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
private $object;
|
|
private $options;
|
|
|
|
private $anotherClient;
|
|
|
|
public function setUp()
|
|
{
|
|
$options = include __DIR__ . '/../bootstrap.php';
|
|
|
|
$client = new Crodas(
|
|
$options["tcp"]["host"],
|
|
$options["tcp"]["port"],
|
|
$options["tcp"]["username"],
|
|
$options["tcp"]["password"]
|
|
);
|
|
try {
|
|
$client->deleteDatabase($options["tcp"]["database"]);
|
|
} catch (\Exception $e) {
|
|
// nothing...
|
|
}
|
|
$client->createDatabase($options["tcp"]["database"]);
|
|
|
|
$this->anotherClient = $client;
|
|
|
|
$tcpOptions = $options["tcp"];
|
|
|
|
$options = new Options();
|
|
$options->setHost($tcpOptions["host"]);
|
|
$options->setPort($tcpOptions["port"]);
|
|
$options->setUsername($tcpOptions["username"]);
|
|
$options->setPassword($tcpOptions["password"]);
|
|
$options->setDatabase($tcpOptions["database"]);
|
|
|
|
$this->options = $options;
|
|
|
|
$guzzleHttp = new GuzzleHttpClient();
|
|
$adapter = new InfluxHttpAdapter($guzzleHttp, $options);
|
|
|
|
$influx = new Client();
|
|
$influx->setAdapter($adapter);
|
|
$this->object = $influx;
|
|
}
|
|
|
|
public function testGuzzleHttpApiWorksCorrectly()
|
|
{
|
|
$this->object->mark("tcp.test", ["mark" => "element"]);
|
|
|
|
$body = $this->object->query("select * from tcp.test");
|
|
$this->assertCount(1, $body[0]["points"]);
|
|
$this->assertEquals("element", $body[0]["points"][0][2]);
|
|
}
|
|
|
|
public function testGuzzleHttpQueryApiWorksCorrectly()
|
|
{
|
|
$this->object->mark("tcp.test", ["mark" => "element"]);
|
|
|
|
$body = $this->object->query("select * from tcp.test");
|
|
|
|
$this->assertCount(1, $body);
|
|
$this->assertEquals("tcp.test", $body[0]["name"]);
|
|
$this->assertEquals("element", $body[0]["points"][0][2]);
|
|
}
|
|
|
|
public function testGuzzleHttpQueryApiWithMultipleData()
|
|
{
|
|
$this->object->mark("tcp.test", ["mark" => "element"]);
|
|
$this->object->mark("tcp.test", ["mark" => "element2"]);
|
|
$this->object->mark("tcp.test", ["mark" => "element3"]);
|
|
|
|
$body = $this->object->query("select mark from tcp.test", "s");
|
|
|
|
$this->assertCount(3, $body[0]["points"]);
|
|
$this->assertEquals("tcp.test", $body[0]["name"]);
|
|
}
|
|
|
|
public function testGuzzleHttpQueryApiWithTimePrecision()
|
|
{
|
|
$this->object->mark("tcp.test", ["mark" => "element"]);
|
|
|
|
$body = $this->object->query("select mark from tcp.test", "s");
|
|
|
|
$this->assertCount(1, $body[0]["points"]);
|
|
$this->assertEquals("tcp.test", $body[0]["name"]);
|
|
}
|
|
}
|