|
2 | 2 |
|
3 | 3 | use Illuminate\Support\Facades\File; |
4 | 4 | use Opcodes\LogViewer\Exceptions\CannotOpenFileException; |
| 5 | +use Opcodes\LogViewer\Facades\Cache as LogViewerCache; |
| 6 | +use Opcodes\LogViewer\LogFile; |
5 | 7 | use Opcodes\LogViewer\Readers\IndexedLogReader; |
| 8 | +use Opcodes\LogViewer\Utils\GenerateCacheKey; |
6 | 9 | use Spatie\TestTime\TestTime; |
7 | 10 |
|
8 | 11 | beforeEach(function () { |
|
43 | 46 | ->and($index->getFlatIndex())->toHaveCount(2); |
44 | 47 | }); |
45 | 48 |
|
| 49 | +it('rebuilds a search index when its cache is evicted but file metadata survives', function () { |
| 50 | + $path = $this->file->path; |
| 51 | + |
| 52 | + $read = function () use ($path) { |
| 53 | + IndexedLogReader::clearInstances(); |
| 54 | + |
| 55 | + $logReader = (new LogFile($path))->logs()->search('Testing'); |
| 56 | + $logReader->scan(); |
| 57 | + |
| 58 | + return [ |
| 59 | + 'requires_scan' => $logReader->requiresScan(), |
| 60 | + 'new_bytes' => $logReader->numberOfNewBytes(), |
| 61 | + 'total' => $logReader->total(), |
| 62 | + 'count' => count($logReader->reset()->get()), |
| 63 | + ]; |
| 64 | + }; |
| 65 | + |
| 66 | + expect($read())->toMatchArray([ |
| 67 | + 'requires_scan' => false, |
| 68 | + 'new_bytes' => 0, |
| 69 | + 'total' => 1, |
| 70 | + 'count' => 1, |
| 71 | + ]); |
| 72 | + |
| 73 | + $index = (new LogFile($path))->index('~Testing~iu'); |
| 74 | + |
| 75 | + LogViewerCache::forget(GenerateCacheKey::for($index, 'metadata')); |
| 76 | + LogViewerCache::forget(GenerateCacheKey::for($index, 'chunk:0')); |
| 77 | + |
| 78 | + expect($read())->toMatchArray([ |
| 79 | + 'requires_scan' => false, |
| 80 | + 'new_bytes' => 0, |
| 81 | + 'total' => 1, |
| 82 | + 'count' => 1, |
| 83 | + ]); |
| 84 | +}); |
| 85 | + |
46 | 86 | it('throws an exception when file cannot be opened for reading', function () { |
47 | 87 | if (PHP_OS_FAMILY === 'Windows') { |
48 | 88 | $this->markTestSkipped('File permissions work differently on Windows. The feature tested might still work.'); |
|
0 commit comments