. * * @link https://www.librenms.org * * @copyright 2018 Tony Murray * @author Tony Murray */ namespace LibreNMS\Tests\Unit\Data; use InfluxDB\Point; use LibreNMS\Config; use LibreNMS\Data\Store\InfluxDB; use LibreNMS\Tests\TestCase; /** * @group datastores */ class InfluxDBStoreTest extends TestCase { public function testBadSettings(): void { Config::set('influxdb.host', ''); Config::set('influxdb.port', 'abc'); $influx = new InfluxDB(InfluxDB::createFromConfig()); \Log::shouldReceive('debug'); \Log::shouldReceive('error')->once()->with('InfluxDB exception: Unable to parse URI: http://:0'); // the important one $influx->put(['hostname' => 'test'], 'fake', [], ['one' => 1]); } public function testSimpleWrite(): void { // Create a mock of the Random Interface $mock = \Mockery::mock(\InfluxDB\Database::class); $mock->shouldReceive('exists')->once()->andReturn(true); $influx = new InfluxDB($mock); $device = ['hostname' => 'testhost']; $measurement = 'testmeasure'; $tags = ['ifName' => 'testifname', 'type' => 'testtype']; $fields = ['ifIn' => 234234.0, 'ifOut' => 53453.0]; $expected = [new Point($measurement, null, ['hostname' => $device['hostname']] + $tags, $fields)]; $mock->shouldReceive('writePoints')->withArgs([$expected])->once(); $influx->put($device, $measurement, $tags, $fields); } }