Skip to content

Commit 050c9da

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

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/lib/Files/Cache/WatcherTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
namespace Test\Files\Cache;
99

10+
use OC\Files\Cache\CacheEntry;
11+
use OC\Files\Cache\Watcher;
12+
use OCP\Files\Cache\IWatcher;
13+
use OCP\Files\Storage\IStorage;
14+
use PHPUnit\Framework\Attributes\DataProvider;
15+
1016
/**
1117
* Class WatcherTest
1218
*
@@ -191,4 +197,45 @@ private function getTestStorage($scan = true) {
191197
$this->storages[] = $storage;
192198
return $storage;
193199
}
200+
201+
public static function checkFilterProvider(): array {
202+
return [
203+
[null, [
204+
'' => true,
205+
'foo' => true,
206+
'foo.txt' => true,
207+
]],
208+
['/^.+$/', [
209+
'' => false,
210+
'foo' => true,
211+
'foo.txt' => true,
212+
]],
213+
['/^.+\..+$/', [
214+
'' => false,
215+
'foo' => false,
216+
'foo.txt' => true,
217+
]]
218+
];
219+
}
220+
221+
/**
222+
* @dataProvider checkFilterProvider
223+
*/
224+
public function testCheckFilter($filter, $paths) {
225+
$storage = $this->createMock(IStorage::class);
226+
$storage->method('hasUpdated')
227+
->willReturn(true);
228+
$watcher = new Watcher($storage);
229+
$watcher->setPolicy(IWatcher::CHECK_ALWAYS);
230+
231+
$watcher->setCheckFilter($filter);
232+
233+
$entry = new CacheEntry([
234+
'storage_mtime' => 0,
235+
]);
236+
237+
foreach ($paths as $patch => $shouldUpdate) {
238+
$this->assertEquals($shouldUpdate, $watcher->needsUpdate($patch, $entry));
239+
}
240+
}
194241
}

0 commit comments

Comments
 (0)