mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Reduce OS module test noise (#15046)
* Reduce os module test noise JSON stores 1.0 as 1, so format the actual data in the same way. Add tests too to make sure this behavior doesn't break * Only change floats
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
namespace LibreNMS\Tests;
|
||||
|
||||
use LibreNMS\Device\YamlDiscovery;
|
||||
use LibreNMS\Util\Number;
|
||||
use LibreNMS\Util\Rewrite;
|
||||
use LibreNMS\Util\Time;
|
||||
|
||||
@@ -119,4 +120,16 @@ class FunctionsTest extends TestCase
|
||||
$this->assertEquals(606614400, Time::parseAt('March 23 1989 UTC'));
|
||||
$this->assertEquals(time() + 86400, Time::parseAt('+1 day'));
|
||||
}
|
||||
|
||||
public function testNumberCast()
|
||||
{
|
||||
$this->assertSame(-14.3, Number::cast(-14.3));
|
||||
$this->assertSame(0, Number::cast('b -35')); // cast must start with the number as old style php cast did
|
||||
$this->assertSame(0, Number::cast('0 43 51'));
|
||||
$this->assertSame(14.35, Number::cast('14.35 a'));
|
||||
$this->assertSame(-43.332, Number::cast('-43.332 a'));
|
||||
$this->assertSame(-12325234523.43, Number::cast('-12325234523.43asdf'));
|
||||
$this->assertSame(1, Number::cast(1.0));
|
||||
$this->assertSame(2, Number::cast('2.000'));
|
||||
}
|
||||
}
|
||||
|
@@ -35,6 +35,7 @@ use LibreNMS\Exceptions\FileNotFoundException;
|
||||
use LibreNMS\Exceptions\InvalidModuleException;
|
||||
use LibreNMS\Util\Debug;
|
||||
use LibreNMS\Util\ModuleTestHelper;
|
||||
use LibreNMS\Util\Number;
|
||||
use PHPUnit\Util\Color;
|
||||
|
||||
class OSModulesTest extends DBTestCase
|
||||
@@ -183,7 +184,18 @@ class OSModulesTest extends DBTestCase
|
||||
? $helper->getDiscoveryOutput($phpunit_debug ? null : $module)
|
||||
: $helper->getPollerOutput($phpunit_debug ? null : $module));
|
||||
|
||||
$this->assertSame(Arr::dot($expected), Arr::dot($actual), $message);
|
||||
// convert to dot notation so the array is flat and easier to compare visually
|
||||
$expected = Arr::dot($expected);
|
||||
$actual = Arr::dot($actual);
|
||||
|
||||
// json will store 43.0 as 43, Number::cast will change those to integers too
|
||||
foreach ($actual as $index => $value) {
|
||||
if (is_float($value)) {
|
||||
$actual[$index] = Number::cast($value);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertSame($expected, $actual, $message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user