Speed up tests by skipping pings (#11642)

* Mock fping for module tests, there is no need.
Removes some wait time.

* fixup some rrd disabling code

* oops
This commit is contained in:
Tony Murray
2020-05-19 22:08:41 -05:00
committed by GitHub
parent b41d262537
commit f1320b6510
7 changed files with 134 additions and 84 deletions

View File

@@ -29,6 +29,7 @@ use DeviceCache;
use LibreNMS\Config;
use LibreNMS\Exceptions\FileNotFoundException;
use LibreNMS\Exceptions\InvalidModuleException;
use LibreNMS\Fping;
use LibreNMS\Util\ModuleTestHelper;
class OSModulesTest extends DBTestCase
@@ -82,12 +83,8 @@ class OSModulesTest extends DBTestCase
public function testOS($os, $variant, $modules)
{
$this->requireSnmpsim(); // require snmpsim for tests
// stub out Log::event, we don't need to store them for these tests
$this->app->bind('log', function ($app) {
return \Mockery::mock('\App\Facades\LogManager[event]', [$app])
->shouldReceive('event');
});
// stub out Log::event and Fping->ping, we don't need to store them for these tests
$this->stubClasses();
try {
set_debug(false); // avoid all undefined index errors in the legacy code
@@ -158,4 +155,28 @@ class OSModulesTest extends DBTestCase
return [[false, false, $e->getMessage()]];
}
}
private function stubClasses(): void
{
$this->app->bind('log', function ($app) {
return \Mockery::mock('\App\Facades\LogManager[event]', [$app])
->shouldReceive('event');
});
$this->app->bind(Fping::class, function ($app) {
$mock = \Mockery::mock('\LibreNMS\Fping');
$mock->shouldReceive('ping')->andReturn([
"xmt" => 3,
"rcv" => 3,
"loss" => 0,
"min" => 0.62,
"max" => 0.93,
"avg" => 0.71,
"dup" => 0,
"exitcode" => 0,
]);
return $mock;
});
}
}