From d47fd8d7084d3b97384141f5a1195431edf787c2 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 23 May 2026 17:10:25 +0200 Subject: [PATCH] test: mock ocm discovery in external share test saves ~50s while running tests Signed-off-by: Robin Appelman --- apps/files_sharing/lib/External/Storage.php | 2 +- apps/files_sharing/tests/ExternalStorageTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/lib/External/Storage.php b/apps/files_sharing/lib/External/Storage.php index 90a50f785dd..929d9cbf976 100644 --- a/apps/files_sharing/lib/External/Storage.php +++ b/apps/files_sharing/lib/External/Storage.php @@ -63,7 +63,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, $this->manager = $options['manager']; $this->cloudId = $options['cloudId']; $this->logger = Server::get(LoggerInterface::class); - $discoveryService = Server::get(IOCMDiscoveryService::class); + $discoveryService = $options['discoveryService'] ?? Server::get(IOCMDiscoveryService::class); $this->config = Server::get(IConfig::class); $this->appConfig = Server::get(IAppConfig::class); $this->shareManager = Server::get(IShareManager::class); diff --git a/apps/files_sharing/tests/ExternalStorageTest.php b/apps/files_sharing/tests/ExternalStorageTest.php index b038d2c7349..38040a47d71 100644 --- a/apps/files_sharing/tests/ExternalStorageTest.php +++ b/apps/files_sharing/tests/ExternalStorageTest.php @@ -15,6 +15,8 @@ use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\ICertificateManager; +use OCP\OCM\IOCMDiscoveryService; +use OCP\OCM\IOCMProvider; use OCP\Server; /** @@ -62,6 +64,9 @@ class ExternalStorageTest extends \Test\TestCase { $manager = $this->createMock(ExternalShareManager::class); $client = $this->createMock(IClient::class); $response = $this->createMock(IResponse::class); + $discoveryService = $this->createMock(IOCMDiscoveryService::class); + $ocmProvider = $this->createMock(IOCMProvider::class); + $client ->expects($this->any()) ->method('get') @@ -74,6 +79,12 @@ class ExternalStorageTest extends \Test\TestCase { ->expects($this->any()) ->method('newClient') ->willReturn($client); + $discoveryService->method('discover') + ->willReturn($ocmProvider); + $ocmProvider->method('extractProtocolEntry') + ->willReturn('/public.php/webdav'); + $ocmProvider->method('getEndPoint') + ->willReturn($uri); return new TestSharingExternalStorage( [ @@ -86,6 +97,7 @@ class ExternalStorageTest extends \Test\TestCase { 'manager' => $manager, 'certificateManager' => $certificateManager, 'HttpClientService' => $httpClientService, + 'discoveryService' => $discoveryService, ] ); }