Add checksum validation for archived media
This commit is contained in:
@@ -75,4 +75,62 @@ class MonitorStorageCommandTest extends TestCase
|
||||
$this->assertSame(2, $snapshot['targets'][0]['assets']['total']);
|
||||
$this->assertGreaterThanOrEqual(1, count($snapshot['alerts']));
|
||||
}
|
||||
|
||||
public function test_monitor_command_flags_checksum_mismatches(): void
|
||||
{
|
||||
config([
|
||||
'storage-monitor.checksum_validation.enabled' => true,
|
||||
'storage-monitor.checksum_validation.alert_window_minutes' => 60,
|
||||
'storage-monitor.checksum_validation.thresholds.warning' => 1,
|
||||
'storage-monitor.checksum_validation.thresholds.critical' => 5,
|
||||
]);
|
||||
|
||||
$target = MediaStorageTarget::create([
|
||||
'key' => 'local-ssd',
|
||||
'name' => 'Local SSD',
|
||||
'driver' => 'local',
|
||||
'config' => ['monitor_path' => storage_path('app')],
|
||||
'is_hot' => true,
|
||||
'is_default' => true,
|
||||
'is_active' => true,
|
||||
'priority' => 100,
|
||||
]);
|
||||
|
||||
$event = Event::factory()->create();
|
||||
|
||||
EventMediaAsset::create([
|
||||
'event_id' => $event->id,
|
||||
'media_storage_target_id' => $target->id,
|
||||
'photo_id' => null,
|
||||
'variant' => 'original',
|
||||
'disk' => 'local-ssd',
|
||||
'path' => 'events/'.$event->id.'/photo.jpg',
|
||||
'size_bytes' => 2048,
|
||||
'status' => 'failed',
|
||||
'meta' => [
|
||||
'checksum_status' => 'mismatch',
|
||||
'checksum_verified_at' => now()->toIso8601String(),
|
||||
],
|
||||
]);
|
||||
|
||||
$health = Mockery::mock(StorageHealthService::class);
|
||||
$health->shouldReceive('getCapacity')->andReturn([
|
||||
'status' => 'ok',
|
||||
'total' => 100,
|
||||
'free' => 90,
|
||||
'used' => 10,
|
||||
'percentage' => 10,
|
||||
'path' => storage_path('app'),
|
||||
]);
|
||||
$this->app->instance(StorageHealthService::class, $health);
|
||||
|
||||
$this->artisan('storage:monitor')
|
||||
->assertExitCode(0);
|
||||
|
||||
$snapshot = Cache::get('storage:monitor:last');
|
||||
|
||||
$this->assertNotNull($snapshot);
|
||||
$alerts = collect($snapshot['alerts'] ?? []);
|
||||
$this->assertTrue($alerts->contains(fn ($alert) => ($alert['type'] ?? null) === 'checksum_mismatch'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user