test(BinaryFinder): Make sure the test is portable between systems

Signed-off-by: provokateurin <kate@provokateurin.de>
pull/54914/head
provokateurin 2025-09-05 09:47:47 +07:00
parent 39dc1dfd41
commit e391e50446
No known key found for this signature in database
1 changed files with 14 additions and 6 deletions

@ -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'));