mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
OS Testing update (#7971)
* OS Testing update Option on pre-commit.php to run tests for just one OS. Reorganize tests a bit to support this. Improved bgp-peers capture and os module capture (initial) Better output when phpunit tests fail * fix a couple issues. Better output for another * Use the correct setup function
This commit is contained in:
@@ -7,11 +7,12 @@ chdir($install_dir);
|
||||
|
||||
require $install_dir . '/vendor/autoload.php';
|
||||
|
||||
$short_opts = 'lsufpch';
|
||||
$short_opts = 'lsufpcho:';
|
||||
$long_opts = array(
|
||||
'lint',
|
||||
'style',
|
||||
'unit',
|
||||
'os:',
|
||||
'fail-fast',
|
||||
'passthru',
|
||||
'snmpsim',
|
||||
@@ -27,6 +28,7 @@ Running $filename without options runs all checks.
|
||||
-l, --lint Run php lint checks to test for valid syntax
|
||||
-s, --style Run phpcs check to check for PSR-2 compliance
|
||||
-u, --unit Run phpunit tests
|
||||
-o, --os Specific OS to run tests on. Implies --unit
|
||||
-f, --fail-fast Quit when any failure is encountered
|
||||
-p, --passthru Display output from checks as it comes
|
||||
--db Run unit tests that require a database
|
||||
@@ -47,6 +49,13 @@ $completed_tests = array(
|
||||
'unit' => false,
|
||||
);
|
||||
|
||||
if ($os = check_opt($options, 'os', 'o')) {
|
||||
// enable unit tests, snmpsim, and db
|
||||
$options['u'] = false;
|
||||
$options['snmpsim'] = false;
|
||||
$options['db'] = false;
|
||||
}
|
||||
|
||||
$all = !check_opt($options, 'l', 'lint', 's', 'style', 'u', 'unit');
|
||||
if ($all) {
|
||||
// no test specified, run all tests in this order
|
||||
@@ -69,7 +78,7 @@ foreach (array_keys($options) as $opt) {
|
||||
} elseif ($opt == 's' || $opt == 'style') {
|
||||
$ret = run_check('style', $passthru, $command_only);
|
||||
} elseif ($opt == 'u' || $opt == 'unit') {
|
||||
$ret = run_check('unit', $passthru, $command_only, $fail_fast);
|
||||
$ret = run_check('unit', $passthru, $command_only, $fail_fast, $os);
|
||||
}
|
||||
|
||||
if ($fail_fast && $ret !== 0 && $ret !== 250) {
|
||||
@@ -94,10 +103,10 @@ exit($return); //return the combined/single return value of tests
|
||||
* @param bool $passthru display the output as comes in
|
||||
* @param bool $command_only only display the intended command, no checks
|
||||
* @param bool $fail_fast Quit as soon as possible if error or failure
|
||||
* @param bool $snmpsim Use snmpsim
|
||||
* @param string $os Only check a specific OS
|
||||
* @return int the return value from the check (0 = success)
|
||||
*/
|
||||
function run_check($type, $passthru, $command_only, $fail_fast = false, $snmpsim = false)
|
||||
function run_check($type, $passthru, $command_only, $fail_fast = false, $os = null)
|
||||
{
|
||||
global $completed_tests;
|
||||
if (getenv('SKIP_' . strtoupper($type) . '_CHECK') || $completed_tests[$type]) {
|
||||
@@ -108,7 +117,7 @@ function run_check($type, $passthru, $command_only, $fail_fast = false, $snmpsim
|
||||
$function = 'check_' . $type;
|
||||
if (function_exists($function)) {
|
||||
$completed_tests[$type] = true;
|
||||
return $function($passthru, $command_only, $fail_fast, $snmpsim);
|
||||
return $function($passthru, $command_only, $fail_fast, $os);
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -209,9 +218,10 @@ function check_style($passthru = false, $command_only = false)
|
||||
* @param bool $passthru display the output as comes in
|
||||
* @param bool $command_only only display the intended command, no checks
|
||||
* @param bool $fail_fast Stop when any error or failure is encountered
|
||||
* @param string $os only check a specific OS
|
||||
* @return int the return value from phpunit (0 = success)
|
||||
*/
|
||||
function check_unit($passthru = false, $command_only = false, $fail_fast = false)
|
||||
function check_unit($passthru = false, $command_only = false, $fail_fast = false, $os = null)
|
||||
{
|
||||
$phpunit_bin = check_exec('phpunit');
|
||||
|
||||
@@ -221,6 +231,10 @@ function check_unit($passthru = false, $command_only = false, $fail_fast = false
|
||||
$phpunit_cmd .= ' --stop-on-error --stop-on-failure';
|
||||
}
|
||||
|
||||
if (!is_null($os)) {
|
||||
$phpunit_cmd .= " --group os --filter \"@$os.*\"";
|
||||
}
|
||||
|
||||
if ($command_only) {
|
||||
echo $phpunit_cmd . PHP_EOL;
|
||||
return 250;
|
||||
@@ -257,8 +271,17 @@ function check_opt($options)
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
|
||||
$intersect = array_intersect(array_keys($options), $args);
|
||||
return !empty($intersect);
|
||||
foreach ($args as $option) {
|
||||
if (isset($options[$option])) {
|
||||
if ($options[$option] === false) {
|
||||
// no data, return that option is enabled
|
||||
return true;
|
||||
}
|
||||
return $options[$option];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user