Skip to content

Commit

Permalink
Fix invalid test data (#9099)
Browse files Browse the repository at this point in the history
* Fix invalid test data
and add test for it

* fix bgp

* add missing comma back
  • Loading branch information
murrant committed Aug 28, 2018
1 parent 31a21ba commit f73f7ec
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 118 deletions.
15 changes: 10 additions & 5 deletions LibreNMS/Util/ModuleTestHelper.php
Expand Up @@ -226,6 +226,7 @@ private function collectOids($device_id)
*
* @param array $modules
* @return array
* @throws InvalidModuleException
*/
public static function findOsWithData($modules = [])
{
Expand Down Expand Up @@ -253,11 +254,15 @@ public static function findOsWithData($modules = [])
continue; // no test data for selected modules
}

$os_list[$base_name] = [
$os,
$variant,
self::resolveModuleDependencies($valid_modules),
];
try {
$os_list[$base_name] = [
$os,
$variant,
self::resolveModuleDependencies($valid_modules),
];
} catch (InvalidModuleException $e) {
throw new InvalidModuleException("Invalid module " . $e->getMessage() . " in $os $variant");
}
}

return $os_list;
Expand Down
23 changes: 22 additions & 1 deletion tests/OSModulesTest.php
Expand Up @@ -31,6 +31,22 @@

class OSModulesTest extends DBTestCase
{
/**
* Test all modules for a particular OS
*
* @group os
* @dataProvider dumpedDataProvider
*/
public function testDataIsValid($os, $variant, $modules)
{
// special case if data provider throws exception
if ($os === false) {
$this->fail($modules);
}

$this->assertNotEmpty($modules, "No modules to test for $os $variant");
}

/**
* Test all modules for a particular OS
*
Expand Down Expand Up @@ -105,6 +121,11 @@ public function dumpedDataProvider()
$modules = explode(',', getenv('TEST_MODULES'));
}

return ModuleTestHelper::findOsWithData($modules);
try {
return ModuleTestHelper::findOsWithData($modules);
} catch (InvalidModuleException $e) {
// special case for exception
return [[false, false, $e->getMessage()]];
}
}
}
12 changes: 0 additions & 12 deletions tests/data/arris-d5.json
Expand Up @@ -10986,18 +10986,6 @@
},
"poller": "matches discovery"
},
"bgp-peers": {
"discovery": {
"devices": [
{
"bgpLocalAs": null
}
],
"bgpPeers": [],
"bgpPeers_cbgp": []
},
"poller": "matches discovery"
},
"vlans": {
"discovery": {
"vlans": [
Expand Down
102 changes: 52 additions & 50 deletions tests/data/linux_ntp-client-legacy.json
@@ -1,55 +1,57 @@
{
"discovery": {
"applications": {
"app_type": "ntp-client",
"app_state": "UNKNOWN",
"discovered": "1",
"app_state_prev": null,
"app_status": "",
"app_instance": ""
},
"application_metrics": []
},
"poller": {
"applications": {
"app_type": "ntp-client",
"app_state": "OK",
"discovered": "1",
"app_state_prev": "UNKNOWN",
"app_status": "",
"app_instance": ""
},
"application_metrics": [
{
"metric": "clk_jitter",
"value": "0.853",
"value_prev": null,
"app_type": "ntp-client"
},
{
"metric": "clk_wander",
"value": "0.025",
"value_prev": null,
"app_type": "ntp-client"
"applications": {
"discovery": {
"applications": {
"app_type": "ntp-client",
"app_state": "UNKNOWN",
"discovered": "1",
"app_state_prev": null,
"app_status": "",
"app_instance": ""
},
{
"metric": "frequency",
"value": "91.141",
"value_prev": null,
"app_type": "ntp-client"
},
{
"metric": "offset",
"value": "0.702900",
"value_prev": null,
"app_type": "ntp-client"
"application_metrics": []
},
"poller": {
"applications": {
"app_type": "ntp-client",
"app_state": "OK",
"discovered": "1",
"app_state_prev": "UNKNOWN",
"app_status": "",
"app_instance": ""
},
{
"metric": "sys_jitter",
"value": "2.581995",
"value_prev": null,
"app_type": "ntp-client"
}
]
"application_metrics": [
{
"metric": "clk_jitter",
"value": "0.853",
"value_prev": null,
"app_type": "ntp-client"
},
{
"metric": "clk_wander",
"value": "0.025",
"value_prev": null,
"app_type": "ntp-client"
},
{
"metric": "frequency",
"value": "91.141",
"value_prev": null,
"app_type": "ntp-client"
},
{
"metric": "offset",
"value": "0.702900",
"value_prev": null,
"app_type": "ntp-client"
},
{
"metric": "sys_jitter",
"value": "2.581995",
"value_prev": null,
"app_type": "ntp-client"
}
]
}
}
}
102 changes: 52 additions & 50 deletions tests/data/linux_ntp-client-v1.json
@@ -1,55 +1,57 @@
{
"discovery": {
"applications": {
"app_type": "ntp-client",
"app_state": "UNKNOWN",
"discovered": "1",
"app_state_prev": null,
"app_status": "",
"app_instance": ""
},
"application_metrics": []
},
"poller": {
"applications": {
"app_type": "ntp-client",
"app_state": "OK",
"discovered": "1",
"app_state_prev": "UNKNOWN",
"app_status": "",
"app_instance": ""
},
"application_metrics": [
{
"metric": "clk_jitter",
"value": "0.853",
"value_prev": null,
"app_type": "ntp-client"
},
{
"metric": "clk_wander",
"value": "0.025",
"value_prev": null,
"app_type": "ntp-client"
"applications": {
"discovery": {
"applications": {
"app_type": "ntp-client",
"app_state": "UNKNOWN",
"discovered": "1",
"app_state_prev": null,
"app_status": "",
"app_instance": ""
},
{
"metric": "frequency",
"value": "91.141",
"value_prev": null,
"app_type": "ntp-client"
},
{
"metric": "offset",
"value": "0.702900",
"value_prev": null,
"app_type": "ntp-client"
"application_metrics": []
},
"poller": {
"applications": {
"app_type": "ntp-client",
"app_state": "OK",
"discovered": "1",
"app_state_prev": "UNKNOWN",
"app_status": "",
"app_instance": ""
},
{
"metric": "sys_jitter",
"value": "2.581995",
"value_prev": null,
"app_type": "ntp-client"
}
]
"application_metrics": [
{
"metric": "clk_jitter",
"value": "0.853",
"value_prev": null,
"app_type": "ntp-client"
},
{
"metric": "clk_wander",
"value": "0.025",
"value_prev": null,
"app_type": "ntp-client"
},
{
"metric": "frequency",
"value": "91.141",
"value_prev": null,
"app_type": "ntp-client"
},
{
"metric": "offset",
"value": "0.702900",
"value_prev": null,
"app_type": "ntp-client"
},
{
"metric": "sys_jitter",
"value": "2.581995",
"value_prev": null,
"app_type": "ntp-client"
}
]
}
}
}

0 comments on commit f73f7ec

Please sign in to comment.