From e391e5044619ad668aa702bc2c10a810b25a363a Mon Sep 17 00:00:00 2001 From: provokateurin Date: Fri, 5 Sep 2025 09:47:47 +0200 Subject: [PATCH] test(BinaryFinder): Make sure the test is portable between systems Signed-off-by: provokateurin --- tests/lib/BinaryFinderTest.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/lib/BinaryFinderTest.php b/tests/lib/BinaryFinderTest.php index af7bf8b9126..fd289ae1940 100644 --- a/tests/lib/BinaryFinderTest.php +++ b/tests/lib/BinaryFinderTest.php @@ -13,6 +13,8 @@ use OC\Memcache\ArrayCache; use OCP\ICache; use OCP\ICacheFactory; use OCP\IConfig; +use OCP\ITempManager; +use OCP\Server; class BinaryFinderTest extends TestCase { private ICache $cache; @@ -43,8 +45,8 @@ class BinaryFinderTest extends TestCase { return $default; }); $finder = new BinaryFinder($this->cacheFactory, $config); - $this->assertEquals($finder->findBinaryPath('cat'), '/usr/bin/cat'); - $this->assertEquals($this->cache->get('cat'), '/usr/bin/cat'); + $this->assertStringEndsWith('/cat', $finder->findBinaryPath('cat')); + $this->assertStringEndsWith('/cat', $this->cache->get('cat')); } public function testDefaultDoesNotFindCata() { @@ -61,22 +63,28 @@ class BinaryFinderTest extends TestCase { } public function testCustomPathFindsCat() { + $tmpdir = Server::get(ITempManager::class)->getTemporaryFolder(); + touch($tmpdir . '/cat'); + chmod($tmpdir . '/cat', 100); + $config = $this->createMock(IConfig::class); $config ->method('getSystemValue') ->with('binary_search_paths', $this->anything()) - ->willReturn(['/usr/bin']); + ->willReturn([$tmpdir]); $finder = new BinaryFinder($this->cacheFactory, $config); - $this->assertEquals($finder->findBinaryPath('cat'), '/usr/bin/cat'); - $this->assertEquals($this->cache->get('cat'), '/usr/bin/cat'); + $this->assertEquals($tmpdir . '/cat', $finder->findBinaryPath('cat')); + $this->assertEquals($tmpdir . '/cat', $this->cache->get('cat')); } public function testWrongCustomPathDoesNotFindCat() { + $tmpdir = Server::get(ITempManager::class)->getTemporaryFolder(); + $config = $this->createMock(IConfig::class); $config ->method('getSystemValue') ->with('binary_search_paths') - ->willReturn(['/wrong']); + ->willReturn([$tmpdir]); $finder = new BinaryFinder($this->cacheFactory, $config); $this->assertFalse($finder->findBinaryPath('cat')); $this->assertFalse($this->cache->get('cat'));