Tests dont include empty tables (#13619)

* Do not include empty tables in test data

* empty data is simpler to check now

* Update test data

* revert comment options that block update all test data

* clean existing data

* fixes

* another fix

* remov extra sensors???

* why is that using that ip...

* missed an empty table

* missed one

* restore ftos

* revert another ftos

* revert ird

* restore timos

* restore timos_7705

* oops

* double oops

* timos mpls

* timos_hc

* another timos_hc fix
This commit is contained in:
Tony Murray
2021-12-15 19:48:44 -06:00
committed by GitHub
parent 478f3d80d9
commit d5656d826e
163 changed files with 4818 additions and 2956 deletions

View File

@@ -649,7 +649,7 @@ class ModuleTestHelper
// insert new data, don't store duplicate data
foreach ($data as $module => $module_data) {
// skip saving modules with no data
if ($this->dataIsEmpty($module_data['discovery']) && $this->dataIsEmpty($module_data['poller'])) {
if (empty($module_data['discovery']) && empty($module_data['poller'])) {
continue;
}
if ($module_data['discovery'] == $module_data['poller']) {
@@ -704,10 +704,10 @@ class ModuleTestHelper
*
* @param int $device_id The test device id
* @param array $modules to capture data for (should be a list of modules that were actually run)
* @param string $key a key to store the data under the module key (usually discovery or poller)
* @param string $type a key to store the data under the module key (usually discovery or poller)
* @return array The dumped data keyed by module -> table
*/
public function dumpDb($device_id, $modules, $key = null)
public function dumpDb($device_id, $modules, $type)
{
$data = [];
$module_dump_info = $this->getTableData();
@@ -719,12 +719,11 @@ class ModuleTestHelper
// only dump data for the given modules
foreach ($modules as $module) {
foreach ($module_dump_info[$module] ?: [] as $table => $info) {
foreach ($module_dump_info[$module] ?? [] as $table => $info) {
if ($table == 'component') {
if (isset($key)) {
$data[$module][$key][$table] = $this->collectComponents($device_id);
} else {
$data[$module][$table] = $this->collectComponents($device_id);
$components = $this->collectComponents($device_id);
if (! empty($components)) {
$data[$module][$type][$table] = $components;
}
continue;
}
@@ -762,6 +761,11 @@ class ModuleTestHelper
$fields = implode(', ', $select);
$rows = dbFetchRows("SELECT $fields FROM `$table` $join $where $order_by", $params);
// don't include empty tables
if (empty($rows)) {
continue;
}
// remove unwanted fields
if (isset($info['included_fields'])) {
$keys = array_flip($info['included_fields']);
@@ -775,11 +779,7 @@ class ModuleTestHelper
}, $rows);
}
if (isset($key)) {
$data[$module][$key][$table] = $rows;
} else {
$data[$module][$table] = $rows;
}
$data[$module][$type][$table] = $rows;
}
}
@@ -872,7 +872,7 @@ class ModuleTestHelper
return $this->json_file;
}
private function collectComponents($device_id)
private function collectComponents(int $device_id): array
{
$components = (new Component())->getComponents($device_id)[$device_id] ?? [];
$components = Arr::sort($components, function ($item) {
@@ -881,15 +881,4 @@ class ModuleTestHelper
return array_values($components);
}
private function dataIsEmpty($data)
{
foreach ($data as $table_data) {
if (! empty($table_data)) {
return false;
}
}
return true;
}
}