mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Small test speedup (#11411)
Use Log::event() inside log_event() Mock Log::event() in module tests to prevent writing to the database.
This commit is contained in:
@@ -884,19 +884,12 @@ function get_astext($asn)
|
||||
*/
|
||||
function log_event($text, $device = null, $type = null, $severity = 2, $reference = null)
|
||||
{
|
||||
if (!is_array($device)) {
|
||||
$device = device_by_id_cache($device);
|
||||
// handle legacy device array
|
||||
if (is_array($device) && isset($device['device_id'])) {
|
||||
$device = $device['device_id'];
|
||||
}
|
||||
|
||||
dbInsert([
|
||||
'device_id' => ($device['device_id'] ?: 0),
|
||||
'reference' => $reference,
|
||||
'type' => $type,
|
||||
'datetime' => \Carbon\Carbon::now(),
|
||||
'severity' => $severity,
|
||||
'message' => $text,
|
||||
'username' => Auth::user()->username ?? '',
|
||||
], 'eventlog');
|
||||
Log::event($text, $device, $type, $severity, $reference);
|
||||
}
|
||||
|
||||
// Parse string with emails. Return array with email (as key) and name (as value)
|
||||
|
@@ -83,6 +83,12 @@ class OSModulesTest extends DBTestCase
|
||||
{
|
||||
$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');
|
||||
});
|
||||
|
||||
try {
|
||||
set_debug(false); // avoid all undefined index errors in the legacy code
|
||||
$helper = new ModuleTestHelper($modules, $os, $variant);
|
||||
|
Reference in New Issue
Block a user