Skip to content

Commit 047ff27

Browse files
committed
test: add tests for watcher check filter
Signed-off-by: Robin Appelman <[email protected]>
1 parent 4720c39 commit 047ff27

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
@@ -192,4 +196,43 @@ private function getTestStorage($scan = true) {
192196
$this->storages[] = $storage;
193197
return $storage;
194198
}
199+
200+
public static function checkFilterProvider(): array {
201+
return [
202+
[null, [
203+
'' => true,
204+
'foo' => true,
205+
'foo.txt' => true,
206+
]],
207+
['/^.+$/', [
208+
'' => false,
209+
'foo' => true,
210+
'foo.txt' => true,
211+
]],
212+
['/^.+\..+$/', [
213+
'' => false,
214+
'foo' => false,
215+
'foo.txt' => true,
216+
]]
217+
];
218+
}
219+
220+
#[DataProvider('checkFilterProvider')]
221+
public function testCheckFilter($filter, $paths) {
222+
$storage = $this->createMock(IStorage::class);
223+
$storage->method('hasUpdated')
224+
->willReturn(true);
225+
$watcher = new Watcher($storage);
226+
$watcher->setPolicy(IWatcher::CHECK_ALWAYS);
227+
228+
$watcher->setCheckFilter($filter);
229+
230+
$entry = new CacheEntry([
231+
'storage_mtime' => 0,
232+
]);
233+
234+
foreach ($paths as $patch => $shouldUpdate) {
235+
$this->assertEquals($shouldUpdate, $watcher->needsUpdate($patch, $entry));
236+
}
237+
}
195238
}

0 commit comments

Comments
 (0)