mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
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:
@@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user