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:
Tony Murray
2020-04-11 19:53:25 -05:00
committed by GitHub
parent 4a6a0af489
commit 790ef61b0d
2 changed files with 10 additions and 11 deletions

View File

@@ -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)

View File

@@ -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);