aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2022-11-30 15:48:45 +0100
committerRobin Appelman <robin@icewind.nl>2025-05-28 15:32:31 +0200
commit7599162c7b879dc3299f1512b92d77209bc92f13 (patch)
tree02dea83f3ff898aa9ebb758077675a89a9de4da9 /tests
parent9530277f208694e2dffe03a3f758a15c062a0195 (diff)
downloadnextcloud-server-7599162c7b879dc3299f1512b92d77209bc92f13.tar.gz
nextcloud-server-7599162c7b879dc3299f1512b92d77209bc92f13.zip
feat: move primary object store configuration to a single placeprimary-object-store-settings
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Files/Mount/ObjectHomeMountProviderTest.php242
-rw-r--r--tests/lib/Files/Mount/RootMountProviderTest.php7
-rw-r--r--tests/lib/TestCase.php5
3 files changed, 142 insertions, 112 deletions
diff --git a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php
index 3daf82461cb..2b809835953 100644
--- a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php
+++ b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php
@@ -7,6 +7,9 @@
namespace Test\Files\Mount;
use OC\Files\Mount\ObjectHomeMountProvider;
+use OC\Files\ObjectStore\PrimaryObjectStoreConfig;
+use OCP\App\IAppManager;
+use OCP\Files\ObjectStore\IObjectStore;
use OCP\Files\Storage\IStorageFactory;
use OCP\IConfig;
use OCP\IUser;
@@ -31,51 +34,54 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
$this->user = $this->createMock(IUser::class);
$this->loader = $this->createMock(IStorageFactory::class);
- $this->provider = new ObjectHomeMountProvider($this->config);
+ $objectStoreConfig = new PrimaryObjectStoreConfig($this->config, $this->createMock(IAppManager::class));
+ $this->provider = new ObjectHomeMountProvider($objectStoreConfig);
}
public function testSingleBucket(): void {
- $this->config->expects($this->once())
- ->method('getSystemValue')
- ->with($this->equalTo('objectstore'), '')
- ->willReturn([
- 'class' => 'Test\Files\Mount\FakeObjectStore',
- ]);
-
- $this->user->expects($this->never())->method($this->anything());
- $this->loader->expects($this->never())->method($this->anything());
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function ($key, $default) {
+ if ($key === 'objectstore') {
+ return [
+ 'class' => 'Test\Files\Mount\FakeObjectStore',
+ 'arguments' => [
+ 'foo' => 'bar'
+ ],
+ ];
+ } else {
+ return $default;
+ }
+ });
- $config = $this->invokePrivate($this->provider, 'getSingleBucketObjectStoreConfig', [$this->user, $this->loader]);
+ $mount = $this->provider->getHomeMountForUser($this->user, $this->loader);
+ $arguments = $this->invokePrivate($mount, 'arguments');
- $this->assertArrayHasKey('class', $config);
- $this->assertEquals($config['class'], 'Test\Files\Mount\FakeObjectStore');
- $this->assertArrayHasKey('arguments', $config);
- $this->assertArrayHasKey('user', $config['arguments']);
- $this->assertSame($this->user, $config['arguments']['user']);
- $this->assertArrayHasKey('objectstore', $config['arguments']);
- $this->assertInstanceOf('Test\Files\Mount\FakeObjectStore', $config['arguments']['objectstore']);
+ $objectStore = $arguments['objectstore'];
+ $this->assertInstanceOf(FakeObjectStore::class, $objectStore);
+ $this->assertEquals(['foo' => 'bar', 'multibucket' => false], $objectStore->getArguments());
}
public function testMultiBucket(): void {
- $this->config->expects($this->exactly(2))
- ->method('getSystemValue')
- ->with($this->equalTo('objectstore_multibucket'), '')
- ->willReturn([
- 'class' => 'Test\Files\Mount\FakeObjectStore',
- ]);
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function ($key, $default) {
+ if ($key === 'objectstore_multibucket') {
+ return [
+ 'class' => 'Test\Files\Mount\FakeObjectStore',
+ 'arguments' => [
+ 'foo' => 'bar'
+ ],
+ ];
+ } else {
+ return $default;
+ }
+ });
$this->user->method('getUID')
->willReturn('uid');
$this->loader->expects($this->never())->method($this->anything());
- $this->config->expects($this->once())
- ->method('getUserValue')
- ->with(
- $this->equalTo('uid'),
- $this->equalTo('homeobjectstore'),
- $this->equalTo('bucket'),
- $this->equalTo(null)
- )->willReturn(null);
+ $this->config->method('getUserValue')
+ ->willReturn(null);
$this->config->expects($this->once())
->method('setUserValue')
@@ -87,42 +93,37 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
$this->equalTo(null)
);
- $config = $this->invokePrivate($this->provider, 'getMultiBucketObjectStoreConfig', [$this->user, $this->loader]);
+ $mount = $this->provider->getHomeMountForUser($this->user, $this->loader);
+ $arguments = $this->invokePrivate($mount, 'arguments');
- $this->assertArrayHasKey('class', $config);
- $this->assertEquals($config['class'], 'Test\Files\Mount\FakeObjectStore');
- $this->assertArrayHasKey('arguments', $config);
- $this->assertArrayHasKey('user', $config['arguments']);
- $this->assertSame($this->user, $config['arguments']['user']);
- $this->assertArrayHasKey('objectstore', $config['arguments']);
- $this->assertInstanceOf('Test\Files\Mount\FakeObjectStore', $config['arguments']['objectstore']);
- $this->assertArrayHasKey('bucket', $config['arguments']);
- $this->assertEquals('49', $config['arguments']['bucket']);
+ $objectStore = $arguments['objectstore'];
+ $this->assertInstanceOf(FakeObjectStore::class, $objectStore);
+ $this->assertEquals(['foo' => 'bar', 'bucket' => 49, 'multibucket' => true], $objectStore->getArguments());
}
public function testMultiBucketWithPrefix(): void {
- $this->config->expects($this->exactly(2))
- ->method('getSystemValue')
- ->with('objectstore_multibucket')
- ->willReturn([
- 'class' => 'Test\Files\Mount\FakeObjectStore',
- 'arguments' => [
- 'bucket' => 'myBucketPrefix',
- ],
- ]);
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function ($key, $default) {
+ if ($key === 'objectstore_multibucket') {
+ return [
+ 'class' => 'Test\Files\Mount\FakeObjectStore',
+ 'arguments' => [
+ 'foo' => 'bar',
+ 'bucket' => 'myBucketPrefix',
+ ],
+ ];
+ } else {
+ return $default;
+ }
+ });
$this->user->method('getUID')
->willReturn('uid');
$this->loader->expects($this->never())->method($this->anything());
- $this->config->expects($this->once())
+ $this->config
->method('getUserValue')
- ->with(
- $this->equalTo('uid'),
- $this->equalTo('homeobjectstore'),
- $this->equalTo('bucket'),
- $this->equalTo(null)
- )->willReturn(null);
+ ->willReturn(null);
$this->config->expects($this->once())
->method('setUserValue')
@@ -134,66 +135,70 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
$this->equalTo(null)
);
- $config = $this->invokePrivate($this->provider, 'getMultiBucketObjectStoreConfig', [$this->user, $this->loader]);
+ $mount = $this->provider->getHomeMountForUser($this->user, $this->loader);
+ $arguments = $this->invokePrivate($mount, 'arguments');
- $this->assertArrayHasKey('class', $config);
- $this->assertEquals($config['class'], 'Test\Files\Mount\FakeObjectStore');
- $this->assertArrayHasKey('arguments', $config);
- $this->assertArrayHasKey('user', $config['arguments']);
- $this->assertSame($this->user, $config['arguments']['user']);
- $this->assertArrayHasKey('objectstore', $config['arguments']);
- $this->assertInstanceOf('Test\Files\Mount\FakeObjectStore', $config['arguments']['objectstore']);
- $this->assertArrayHasKey('bucket', $config['arguments']);
- $this->assertEquals('myBucketPrefix49', $config['arguments']['bucket']);
+ $objectStore = $arguments['objectstore'];
+ $this->assertInstanceOf(FakeObjectStore::class, $objectStore);
+ $this->assertEquals(['foo' => 'bar', 'bucket' => 'myBucketPrefix49', 'multibucket' => true], $objectStore->getArguments());
}
public function testMultiBucketBucketAlreadySet(): void {
- $this->config->expects($this->once())
- ->method('getSystemValue')
- ->with('objectstore_multibucket')
- ->willReturn([
- 'class' => 'Test\Files\Mount\FakeObjectStore',
- 'arguments' => [
- 'bucket' => 'myBucketPrefix',
- ],
- ]);
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function ($key, $default) {
+ if ($key === 'objectstore_multibucket') {
+ return [
+ 'class' => 'Test\Files\Mount\FakeObjectStore',
+ 'arguments' => [
+ 'foo' => 'bar',
+ 'bucket' => 'myBucketPrefix',
+ ],
+ ];
+ } else {
+ return $default;
+ }
+ });
$this->user->method('getUID')
->willReturn('uid');
$this->loader->expects($this->never())->method($this->anything());
- $this->config->expects($this->once())
+ $this->config
->method('getUserValue')
- ->with(
- $this->equalTo('uid'),
- $this->equalTo('homeobjectstore'),
- $this->equalTo('bucket'),
- $this->equalTo(null)
- )->willReturn('awesomeBucket1');
+ ->willReturnCallback(function ($uid, $app, $key, $default) {
+ if ($uid === 'uid' && $app === 'homeobjectstore' && $key === 'bucket') {
+ return 'awesomeBucket1';
+ } else {
+ return $default;
+ }
+ });
$this->config->expects($this->never())
->method('setUserValue');
- $config = $this->invokePrivate($this->provider, 'getMultiBucketObjectStoreConfig', [$this->user, $this->loader]);
+ $mount = $this->provider->getHomeMountForUser($this->user, $this->loader);
+ $arguments = $this->invokePrivate($mount, 'arguments');
- $this->assertArrayHasKey('class', $config);
- $this->assertEquals($config['class'], 'Test\Files\Mount\FakeObjectStore');
- $this->assertArrayHasKey('arguments', $config);
- $this->assertArrayHasKey('user', $config['arguments']);
- $this->assertSame($this->user, $config['arguments']['user']);
- $this->assertArrayHasKey('objectstore', $config['arguments']);
- $this->assertInstanceOf('Test\Files\Mount\FakeObjectStore', $config['arguments']['objectstore']);
- $this->assertArrayHasKey('bucket', $config['arguments']);
- $this->assertEquals('awesomeBucket1', $config['arguments']['bucket']);
+ $objectStore = $arguments['objectstore'];
+ $this->assertInstanceOf(FakeObjectStore::class, $objectStore);
+ $this->assertEquals(['foo' => 'bar', 'bucket' => 'awesomeBucket1', 'multibucket' => true], $objectStore->getArguments());
}
public function testMultiBucketConfigFirst(): void {
- $this->config->expects($this->exactly(2))
- ->method('getSystemValue')
- ->with('objectstore_multibucket')
- ->willReturn([
- 'class' => 'Test\Files\Mount\FakeObjectStore',
- ]);
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function ($key, $default) {
+ if ($key === 'objectstore_multibucket') {
+ return [
+ 'class' => 'Test\Files\Mount\FakeObjectStore',
+ 'arguments' => [
+ 'foo' => 'bar',
+ 'bucket' => 'myBucketPrefix',
+ ],
+ ];
+ } else {
+ return $default;
+ }
+ });
$this->user->method('getUID')
->willReturn('uid');
@@ -204,11 +209,15 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
}
public function testMultiBucketConfigFirstFallBackSingle(): void {
- $this->config->expects($this->exactly(2))
+ $this->config
->method('getSystemValue')->willReturnMap([
- ['objectstore_multibucket', '', ''],
- ['objectstore', '', [
+ ['objectstore_multibucket', null, null],
+ ['objectstore', null, [
'class' => 'Test\Files\Mount\FakeObjectStore',
+ 'arguments' => [
+ 'foo' => 'bar',
+ 'bucket' => 'myBucketPrefix',
+ ],
]],
]);
@@ -221,16 +230,17 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
}
public function testNoObjectStore(): void {
- $this->config->expects($this->exactly(2))
- ->method('getSystemValue')
- ->willReturn('');
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function ($key, $default) {
+ return $default;
+ });
$mount = $this->provider->getHomeMountForUser($this->user, $this->loader);
$this->assertNull($mount);
}
}
-class FakeObjectStore {
+class FakeObjectStore implements IObjectStore {
private $arguments;
public function __construct(array $arguments) {
@@ -240,4 +250,22 @@ class FakeObjectStore {
public function getArguments() {
return $this->arguments;
}
+
+ public function getStorageId() {
+ }
+
+ public function readObject($urn) {
+ }
+
+ public function writeObject($urn, $stream, ?string $mimetype = null) {
+ }
+
+ public function deleteObject($urn) {
+ }
+
+ public function objectExists($urn) {
+ }
+
+ public function copyObject($from, $to) {
+ }
}
diff --git a/tests/lib/Files/Mount/RootMountProviderTest.php b/tests/lib/Files/Mount/RootMountProviderTest.php
index 2613cfd4b7b..bf29bfa070a 100644
--- a/tests/lib/Files/Mount/RootMountProviderTest.php
+++ b/tests/lib/Files/Mount/RootMountProviderTest.php
@@ -10,11 +10,12 @@ namespace Test\Files\Mount;
use OC\Files\Mount\RootMountProvider;
use OC\Files\ObjectStore\ObjectStoreStorage;
+use OC\Files\ObjectStore\PrimaryObjectStoreConfig;
use OC\Files\ObjectStore\S3;
use OC\Files\Storage\LocalRootStorage;
use OC\Files\Storage\StorageFactory;
+use OCP\App\IAppManager;
use OCP\IConfig;
-use Psr\Log\LoggerInterface;
use Test\TestCase;
/**
@@ -40,8 +41,8 @@ class RootMountProviderTest extends TestCase {
private function getProvider(array $systemConfig): RootMountProvider {
$config = $this->getConfig($systemConfig);
- $provider = new RootMountProvider($config, $this->createMock(LoggerInterface::class));
- return $provider;
+ $objectStoreConfig = new PrimaryObjectStoreConfig($config, $this->createMock(IAppManager::class));
+ return new RootMountProvider($objectStoreConfig, $config);
}
public function testLocal(): void {
diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php
index 918edf7150e..9ca2606ce72 100644
--- a/tests/lib/TestCase.php
+++ b/tests/lib/TestCase.php
@@ -15,6 +15,7 @@ use OC\Files\Filesystem;
use OC\Files\Mount\CacheMountProvider;
use OC\Files\Mount\LocalHomeMountProvider;
use OC\Files\Mount\RootMountProvider;
+use OC\Files\ObjectStore\PrimaryObjectStoreConfig;
use OC\Files\SetupManager;
use OC\Template\Base;
use OCP\Command\IBus;
@@ -25,7 +26,6 @@ use OCP\IDBConnection;
use OCP\IL10N;
use OCP\Lock\ILockingProvider;
use OCP\Security\ISecureRandom;
-use Psr\Log\LoggerInterface;
if (version_compare(\PHPUnit\Runner\Version::id(), 10, '>=')) {
trait OnNotSuccessfulTestTrait {
@@ -332,7 +332,8 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
$config = \OC::$server->get(IConfig::class);
$mountProviderCollection->registerProvider(new CacheMountProvider($config));
$mountProviderCollection->registerHomeProvider(new LocalHomeMountProvider());
- $mountProviderCollection->registerRootProvider(new RootMountProvider($config, \OC::$server->get(LoggerInterface::class)));
+ $objectStoreConfig = \OC::$server->get(PrimaryObjectStoreConfig::class);
+ $mountProviderCollection->registerRootProvider(new RootMountProvider($objectStoreConfig, $config));
$setupManager->setupRoot();