mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
More specific test filtering (#9226)
DO NOT DELETE THIS TEXT #### Please note > Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting. - [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/) #### Testers If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926` After you are done testing, you can remove the changes with `./scripts/github-remove`. If there are schema changes, you can ask on discord how to revert.
This commit is contained in:
committed by
Neil Lathwood
parent
22f07914e8
commit
87ed73ec5c
@ -180,7 +180,6 @@ class OS implements ProcessorDiscovery
|
||||
|
||||
$rf = new \ReflectionClass($this);
|
||||
$name = $rf->getShortName();
|
||||
var_dump($name);
|
||||
preg_match_all("/[A-Z][a-z]*/", $name, $segments);
|
||||
|
||||
return implode('-', array_map('strtolower', $segments[0]));
|
||||
|
@ -33,13 +33,13 @@ foreach ($changed_files as $file) {
|
||||
if (ends_with($file, '.sh')) {
|
||||
$map['bash']++;
|
||||
}
|
||||
if (ends_with($file, '.php') && !starts_with($file, ['includes/polling/os/', 'scripts/'])) {
|
||||
|
||||
// check if os owned file or generic php file
|
||||
if (!empty($os_name = os_from_file($file))) {
|
||||
$map['os'][] = $os_name;
|
||||
} elseif (ends_with($file, '.php')) {
|
||||
$map['php']++;
|
||||
}
|
||||
if (starts_with($file, ['includes/definitions/', 'includes/polling/os/']) && ends_with($file, ['.yaml', '.inc.php'])) {
|
||||
$split_path = explode('/', $file);
|
||||
$map['os'][] = str_replace(['.yaml', '.inc.php'], '', array_pop($split_path));
|
||||
}
|
||||
}
|
||||
|
||||
$map['os'] = array_unique($map['os']);
|
||||
@ -146,6 +146,11 @@ foreach (array_keys($options) as $opt) {
|
||||
if (!empty($map['os']) && $map['php'] === 0) {
|
||||
$os = $map['os'];
|
||||
}
|
||||
|
||||
if (!empty($os)) {
|
||||
echo 'Only checking os: ' . implode(', ', (array)$os) . PHP_EOL;
|
||||
}
|
||||
|
||||
$ret = run_check('unit', $passthru, $command_only, compact('fail_fast', 'os', 'module'));
|
||||
}
|
||||
|
||||
@ -162,6 +167,45 @@ if ($all && $return === 0) {
|
||||
}
|
||||
exit($return); //return the combined/single return value of tests
|
||||
|
||||
function os_from_file($file)
|
||||
{
|
||||
if (starts_with($file, 'includes/definitions/')) {
|
||||
return basename($file, '.yaml');
|
||||
} elseif (starts_with($file, ['includes/polling', 'includes/discovery'])) {
|
||||
return os_from_php($file);
|
||||
} elseif (starts_with($file, 'LibreNMS/OS/')) {
|
||||
if (preg_match('#LibreNMS/OS/[^/]+.php#', $file)) {
|
||||
// convert class name to os name
|
||||
preg_match_all("/[A-Z][a-z]*/", basename($file, '.php'), $segments);
|
||||
$osname = implode('-', array_map('strtolower', $segments[0]));
|
||||
$os = os_from_php($osname);
|
||||
if ($os) {
|
||||
return $os;
|
||||
}
|
||||
return os_from_php(str_replace('-', '_', $osname));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract os name from path and validate it exists.
|
||||
*
|
||||
* @param $php_file
|
||||
* @return null|string
|
||||
*/
|
||||
function os_from_php($php_file)
|
||||
{
|
||||
$os = basename($php_file, '.inc.php');
|
||||
|
||||
if (file_exists("includes/definitions/$os.yaml")) {
|
||||
return $os;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the specified check and return the return value.
|
||||
|
Reference in New Issue
Block a user