Files
librenms-librenms/tests/Unit/Data/InfluxDBStoreTest.php
Tony Murray 61316ce2cc PHP 8 fixes (#12528)
* port related errors

* more fixes

* fix storage count

* add tests for php8

* style

* only need not empty

* aix fixes....

* storage WIP

* fix aix discovering hrstorage
fix db test adding .gitkeep
fix os modules when discovery only

* fix aos processors wrong oid

* fix mempool number casting

* fix aos7 cpu

* use + 0 cast instead of floatval()

* more verbose error on invalid json

* remove invalid data in json

* actually fix the json

* correct json error fix

* cast_number() function
fix aruba-instant and aos6 bugs exposed by new function, probably more...

* fix a-f
fix inadequate sort for component data

* fix global port poll time

* fix mempools precent 0, route count, ntp const

* fix schleifenbauer liberal current usage

* further number casting refinement

* vrp

* fix tests

* fix arbos

* warn cleanups adjust to :: change

* fix ciena-sds

* fix drac

* fix dell-rpdu anddlink

* fix and improve arubaos
better error when getting an array in Processor

* fix atenpdu, add missing arubaos files

* aruba-instant to yaml
apparently I didn't need to do this, the diff just looks really odd
It did add ranged sub-index replacements

* docker app, was completely wrong... fixed

* fix sentry4 divide by 0...

* fixed root issue, remove check

* nicer cidr in ipv6 code

* remove bogus enuxus battery bank skip_values

* Fix InfluxDB tests

* remove extra import

* fix other style issues.

* influx "style" fixes
2021-03-12 18:10:14 -06:00

66 lines
2.2 KiB
PHP

<?php
/**
* InfluxStoreTest.php *
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @link https://www.librenms.org
* @copyright 2018 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
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()
{
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()
{
// 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);
}
}