From 047ff27e466a9a9a6fee19ccc9b3f3c777f74beb Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 20 Nov 2025 18:55:14 +0100 Subject: [PATCH] test: add tests for watcher check filter Signed-off-by: Robin Appelman --- tests/lib/Files/Cache/WatcherTest.php | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/lib/Files/Cache/WatcherTest.php b/tests/lib/Files/Cache/WatcherTest.php index a7fa5086b7b..95ba5787ef3 100644 --- a/tests/lib/Files/Cache/WatcherTest.php +++ b/tests/lib/Files/Cache/WatcherTest.php @@ -8,9 +8,13 @@ namespace Test\Files\Cache; +use OC\Files\Cache\CacheEntry; use OC\Files\Cache\Watcher; use OC\Files\Storage\Storage; use OC\Files\Storage\Temporary; +use OCP\Files\Cache\IWatcher; +use OCP\Files\Storage\IStorage; +use PHPUnit\Framework\Attributes\DataProvider; /** * Class WatcherTest @@ -192,4 +196,43 @@ class WatcherTest extends \Test\TestCase { $this->storages[] = $storage; return $storage; } + + public static function checkFilterProvider(): array { + return [ + [null, [ + '' => true, + 'foo' => true, + 'foo.txt' => true, + ]], + ['/^.+$/', [ + '' => false, + 'foo' => true, + 'foo.txt' => true, + ]], + ['/^.+\..+$/', [ + '' => false, + 'foo' => false, + 'foo.txt' => true, + ]] + ]; + } + + #[DataProvider('checkFilterProvider')] + public function testCheckFilter($filter, $paths) { + $storage = $this->createMock(IStorage::class); + $storage->method('hasUpdated') + ->willReturn(true); + $watcher = new Watcher($storage); + $watcher->setPolicy(IWatcher::CHECK_ALWAYS); + + $watcher->setCheckFilter($filter); + + $entry = new CacheEntry([ + 'storage_mtime' => 0, + ]); + + foreach ($paths as $patch => $shouldUpdate) { + $this->assertEquals($shouldUpdate, $watcher->needsUpdate($patch, $entry)); + } + } }