Skip to content

Commit eedeae4

Browse files
committed
test: add tests for watcher check filter
Signed-off-by: Robin Appelman <[email protected]>
1 parent 56cc62d commit eedeae4

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/lib/Files/Cache/WatcherTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88

99
namespace Test\Files\Cache;
1010

11+
use OC\Files\Cache\CacheEntry;
1112
use OC\Files\Cache\Watcher;
1213
use OC\Files\Storage\Storage;
1314
use OC\Files\Storage\Temporary;
15+
use OCP\Files\Cache\IWatcher;
16+
use OCP\Files\Storage\IStorage;
17+
use PHPUnit\Framework\Attributes\DataProvider;
1418

1519
/**
1620
* Class WatcherTest
@@ -196,4 +200,43 @@ private function getTestStorage($scan = true) {
196200
$this->storages[] = $storage;
197201
return $storage;
198202
}
203+
204+
public static function checkFilterProvider(): array {
205+
return [
206+
[null, [
207+
'' => true,
208+
'foo' => true,
209+
'foo.txt' => true,
210+
]],
211+
['/^.+$/', [
212+
'' => false,
213+
'foo' => true,
214+
'foo.txt' => true,
215+
]],
216+
['/^.+\..+$/', [
217+
'' => false,
218+
'foo' => false,
219+
'foo.txt' => true,
220+
]]
221+
];
222+
}
223+
224+
#[DataProvider('checkFilterProvider')]
225+
public function testCheckFilter($filter, $paths) {
226+
$storage = $this->createMock(IStorage::class);
227+
$storage->method('hasUpdated')
228+
->willReturn(true);
229+
$watcher = new Watcher($storage);
230+
$watcher->setPolicy(IWatcher::CHECK_ALWAYS);
231+
232+
$watcher->setCheckFilter($filter);
233+
234+
$entry = new CacheEntry([
235+
'storage_mtime' => 0,
236+
]);
237+
238+
foreach ($paths as $patch => $shouldUpdate) {
239+
$this->assertEquals($shouldUpdate, $watcher->needsUpdate($patch, $entry));
240+
}
241+
}
199242
}

0 commit comments

Comments
 (0)