mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Module tests update: per module output, only store modules data that are run (#8355)
* Test data: don't save data for modules that were not run * Sometimes mibs are prefixed with + * Save output for each module and only output the errored module. Also makes it easier to identify modules that were ran. * Clean up json files. Message when no module data exists. * verbose output when phpunit --debug is used order by for ports avoid graphite output in tests only load module_tables.yaml once * use explode and strpos instead of regex since it is failing... * Fix some warnings * Fix whitespace
This commit is contained in:
committed by
Neil Lathwood
parent
66a3f82269
commit
2bcc76625c
@@ -25,7 +25,6 @@
|
||||
|
||||
namespace LibreNMS\Tests;
|
||||
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Exceptions\FileNotFoundException;
|
||||
use LibreNMS\Exceptions\InvalidModuleException;
|
||||
use LibreNMS\Util\ModuleTestHelper;
|
||||
@@ -37,8 +36,8 @@ class OSModulesTest extends DBTestCase
|
||||
*
|
||||
* @group os
|
||||
* @dataProvider dumpedDataProvider
|
||||
* @param string $target_os name of the (and variant) to test
|
||||
* @param string $filename file name of the json data
|
||||
* @param string $os base os
|
||||
* @param string $variant optional variant
|
||||
* @param array $modules modules to test for this os
|
||||
*/
|
||||
public function testOS($os, $variant, $modules)
|
||||
@@ -49,20 +48,25 @@ class OSModulesTest extends DBTestCase
|
||||
try {
|
||||
$helper = new ModuleTestHelper($modules, $os, $variant);
|
||||
$helper->setQuiet();
|
||||
$filename = $helper->getJsonFilepath(true);
|
||||
|
||||
$filename = $helper->getJsonFilepath(true);
|
||||
$expected_data = $helper->getTestData();
|
||||
$results = $helper->generateTestData($snmpsim, true);
|
||||
} catch (FileNotFoundException $e) {
|
||||
$this->fail($e->getMessage());
|
||||
return;
|
||||
} catch (InvalidModuleException $e) {
|
||||
$this->fail($e->getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_null($results)) {
|
||||
$this->fail("$os: Failed to collect data.");
|
||||
}
|
||||
|
||||
// output all discovery and poller output if debug mode is enabled for phpunit
|
||||
$debug = in_array('--debug', $_SERVER['argv'], true);
|
||||
|
||||
foreach ($modules as $module) {
|
||||
$expected = $expected_data[$module]['discovery'];
|
||||
$actual = $results[$module]['discovery'];
|
||||
@@ -71,18 +75,22 @@ class OSModulesTest extends DBTestCase
|
||||
$actual,
|
||||
"OS $os: Discovered $module data does not match that found in $filename\n"
|
||||
. print_r(array_diff($expected, $actual), true)
|
||||
. $helper->getLastDiscoveryOutput()
|
||||
. $helper->getDiscoveryOutput($debug ? null : $module)
|
||||
. "\nOS $os: Polled $module data does not match that found in $filename"
|
||||
);
|
||||
|
||||
$expected = $expected_data[$module]['poller'] == 'matches discovery' ? $expected_data[$module]['discovery'] : $expected_data[$module]['poller'];
|
||||
if ($expected_data[$module]['poller'] == 'matches discovery') {
|
||||
$expected = $expected_data[$module]['discovery'];
|
||||
} else {
|
||||
$expected = $expected_data[$module]['poller'];
|
||||
}
|
||||
$actual = $results[$module]['poller'];
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$actual,
|
||||
"OS $os: Polled $module data does not match that found in $filename\n"
|
||||
. print_r(array_diff($expected, $actual), true)
|
||||
. $helper->getLastPollerOutput()
|
||||
. $helper->getPollerOutput($debug ? null : $module)
|
||||
. "\nOS $os: Polled $module data does not match that found in $filename"
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user