aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/Mount
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Files/Mount')
-rw-r--r--tests/lib/Files/Mount/CacheMountProviderTest.php92
-rw-r--r--tests/lib/Files/Mount/ManagerTest.php25
-rw-r--r--tests/lib/Files/Mount/MountPointTest.php33
-rw-r--r--tests/lib/Files/Mount/MountTest.php21
-rw-r--r--tests/lib/Files/Mount/ObjectHomeMountProviderTest.php292
-rw-r--r--tests/lib/Files/Mount/ObjectStorePreviewCacheMountProviderTest.php25
-rw-r--r--tests/lib/Files/Mount/RootMountProviderTest.php76
7 files changed, 327 insertions, 237 deletions
diff --git a/tests/lib/Files/Mount/CacheMountProviderTest.php b/tests/lib/Files/Mount/CacheMountProviderTest.php
new file mode 100644
index 00000000000..003fc40eafc
--- /dev/null
+++ b/tests/lib/Files/Mount/CacheMountProviderTest.php
@@ -0,0 +1,92 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace Test\Files\Mount;
+
+use OC\Files\Mount\CacheMountProvider;
+use OC\Files\Storage\StorageFactory;
+use OCP\Files\Storage\IStorageFactory;
+use OCP\IConfig;
+use OCP\IUser;
+use Test\TestCase;
+
+class CacheMountProviderTestStream {
+ public static $statCounter = 0;
+ public static $mkdirCounter = 0;
+
+ public $context;
+
+ public function mkdir(string $path, int $mode, int $options): bool {
+ self::$mkdirCounter++;
+ return true;
+ }
+
+ public function url_stat(string $path, int $flags): array|false {
+ self::$statCounter++;
+ return false;
+ }
+}
+
+class CacheMountProviderTest extends TestCase {
+ private IConfig $config;
+ private IUser $user;
+ private IStorageFactory $storageFactory;
+
+ protected function setUp(): void {
+ $this->config = $this->createMock(IConfig::class);
+ $this->user = $this->createMock(IUser::class);
+ $this->storageFactory = new StorageFactory();
+ stream_wrapper_register('cachemountprovidertest', CacheMountProviderTestStream::class);
+ }
+
+ protected function tearDown(): void {
+ stream_wrapper_unregister('cachemountprovidertest');
+ }
+
+ public function testGetMountsForUser(): void {
+ $provider = new CacheMountProvider($this->config);
+
+ $this->assertCount(0, $provider->getMountsForUser($this->user, $this->storageFactory));
+ }
+
+ public function testGetMountsForUserCacheDir(): void {
+ $this->config->expects($this->exactly(1))
+ ->method('getSystemValueString')
+ ->willReturnMap([
+ ['cache_path', '', 'cachemountprovidertest:////cache_path'],
+ ]);
+ $this->user->method('getUID')
+ ->willReturn('bob');
+
+ $provider = new CacheMountProvider($this->config);
+ $mounts = $provider->getMountsForUser($this->user, $this->storageFactory);
+
+ $this->assertCount(2, $mounts);
+ $this->assertEquals(1, CacheMountProviderTestStream::$statCounter);
+ $this->assertEquals(2, CacheMountProviderTestStream::$mkdirCounter);
+
+ $cacheMountProvider = $mounts[0];
+ $this->assertEquals('/bob/cache/', $cacheMountProvider->getMountPoint());
+
+ $cacheStorage = $cacheMountProvider->getStorage();
+ $this->assertEquals('local::cachemountprovidertest://cache_path/bob/', $cacheStorage->getId());
+
+ $uploadsMountProvider = $mounts[1];
+ $this->assertEquals('/bob/uploads/', $uploadsMountProvider->getMountPoint());
+
+ $uploadsStorage = $uploadsMountProvider->getStorage();
+ $this->assertEquals('local::cachemountprovidertest://cache_path/bob/uploads/', $uploadsStorage->getId());
+
+ $cacheStorage->mkdir('foobar');
+ $this->assertEquals(3, CacheMountProviderTestStream::$mkdirCounter);
+
+ $uploadsStorage->mkdir('foobar');
+ $this->assertEquals(4, CacheMountProviderTestStream::$mkdirCounter);
+ }
+}
diff --git a/tests/lib/Files/Mount/ManagerTest.php b/tests/lib/Files/Mount/ManagerTest.php
index f69f8b239bb..e6cf3348664 100644
--- a/tests/lib/Files/Mount/ManagerTest.php
+++ b/tests/lib/Files/Mount/ManagerTest.php
@@ -1,18 +1,19 @@
<?php
+
/**
- * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Files\Mount;
+use OC\Files\Mount\MountPoint;
use OC\Files\SetupManagerFactory;
use OC\Files\Storage\Temporary;
class LongId extends Temporary {
- public function getId() {
+ public function getId(): string {
return 'long:' . str_repeat('foo', 50) . parent::getId();
}
}
@@ -28,34 +29,34 @@ class ManagerTest extends \Test\TestCase {
$this->manager = new \OC\Files\Mount\Manager($this->createMock(SetupManagerFactory::class));
}
- public function testFind() {
- $rootMount = new \OC\Files\Mount\MountPoint(new Temporary([]), '/');
+ public function testFind(): void {
+ $rootMount = new MountPoint(new Temporary([]), '/');
$this->manager->addMount($rootMount);
$this->assertEquals($rootMount, $this->manager->find('/'));
$this->assertEquals($rootMount, $this->manager->find('/foo/bar'));
$storage = new Temporary([]);
- $mount1 = new \OC\Files\Mount\MountPoint($storage, '/foo');
+ $mount1 = new MountPoint($storage, '/foo');
$this->manager->addMount($mount1);
$this->assertEquals($rootMount, $this->manager->find('/'));
$this->assertEquals($mount1, $this->manager->find('/foo/bar'));
$this->assertEquals(1, count($this->manager->findIn('/')));
- $mount2 = new \OC\Files\Mount\MountPoint(new Temporary([]), '/bar');
+ $mount2 = new MountPoint(new Temporary([]), '/bar');
$this->manager->addMount($mount2);
$this->assertEquals(2, count($this->manager->findIn('/')));
$id = $mount1->getStorageId();
$this->assertEquals([$mount1], $this->manager->findByStorageId($id));
- $mount3 = new \OC\Files\Mount\MountPoint($storage, '/foo/bar');
+ $mount3 = new MountPoint($storage, '/foo/bar');
$this->manager->addMount($mount3);
$this->assertEquals([$mount1, $mount3], $this->manager->findByStorageId($id));
}
- public function testLong() {
+ public function testLong(): void {
$storage = new LongId([]);
- $mount = new \OC\Files\Mount\MountPoint($storage, '/foo');
+ $mount = new MountPoint($storage, '/foo');
$this->manager->addMount($mount);
$id = $mount->getStorageId();
diff --git a/tests/lib/Files/Mount/MountPointTest.php b/tests/lib/Files/Mount/MountPointTest.php
index 106a8f9a932..bcbcc96e3a3 100644
--- a/tests/lib/Files/Mount/MountPointTest.php
+++ b/tests/lib/Files/Mount/MountPointTest.php
@@ -1,22 +1,21 @@
<?php
+
/**
- * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Files\Mount;
+use OC\Files\Mount\MountPoint;
use OC\Files\Storage\StorageFactory;
-use OCP\Files\Storage;
-
-class DummyStorage {
-}
+use OC\Lockdown\Filesystem\NullStorage;
+use OCP\Files\Storage\IStorage;
class MountPointTest extends \Test\TestCase {
- public function testGetStorage() {
- $storage = $this->createMock(Storage::class);
+ public function testGetStorage(): void {
+ $storage = $this->createMock(IStorage::class);
$storage->expects($this->once())
->method('getId')
->willReturn(123);
@@ -26,9 +25,9 @@ class MountPointTest extends \Test\TestCase {
->method('wrap')
->willReturn($storage);
- $mountPoint = new \OC\Files\Mount\MountPoint(
+ $mountPoint = new MountPoint(
// just use this because a real class is needed
- '\Test\Files\Mount\DummyStorage',
+ NullStorage::class,
'/mountpoint',
null,
$loader
@@ -42,20 +41,20 @@ class MountPointTest extends \Test\TestCase {
$this->assertEquals('/another/', $mountPoint->getMountPoint());
}
- public function testInvalidStorage() {
+ public function testInvalidStorage(): void {
$loader = $this->createMock(StorageFactory::class);
$loader->expects($this->once())
->method('wrap')
- ->will($this->throwException(new \Exception('Test storage init exception')));
+ ->willThrowException(new \Exception('Test storage init exception'));
$called = false;
- $wrapper = function ($mountPoint, $storage) use ($called) {
+ $wrapper = function ($mountPoint, $storage) use ($called): void {
$called = true;
};
- $mountPoint = new \OC\Files\Mount\MountPoint(
+ $mountPoint = new MountPoint(
// just use this because a real class is needed
- '\Test\Files\Mount\DummyStorage',
+ NullStorage::class,
'/mountpoint',
null,
$loader
diff --git a/tests/lib/Files/Mount/MountTest.php b/tests/lib/Files/Mount/MountTest.php
index 340e6931c1d..05c8a7d58e7 100644
--- a/tests/lib/Files/Mount/MountTest.php
+++ b/tests/lib/Files/Mount/MountTest.php
@@ -1,31 +1,32 @@
<?php
+
/**
- * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
+ * SPDX-FileCopyrightText: 2020-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Files\Mount;
+use OC\Files\Mount\MountPoint;
use OC\Files\Storage\StorageFactory;
use OC\Files\Storage\Wrapper\Wrapper;
class MountTest extends \Test\TestCase {
- public function testFromStorageObject() {
+ public function testFromStorageObject(): void {
$storage = $this->getMockBuilder('\OC\Files\Storage\Temporary')
->disableOriginalConstructor()
->getMock();
- $mount = new \OC\Files\Mount\MountPoint($storage, '/foo');
+ $mount = new MountPoint($storage, '/foo');
$this->assertInstanceOf('\OC\Files\Storage\Temporary', $mount->getStorage());
}
- public function testFromStorageClassname() {
- $mount = new \OC\Files\Mount\MountPoint('\OC\Files\Storage\Temporary', '/foo');
+ public function testFromStorageClassname(): void {
+ $mount = new MountPoint('\OC\Files\Storage\Temporary', '/foo');
$this->assertInstanceOf('\OC\Files\Storage\Temporary', $mount->getStorage());
}
- public function testWrapper() {
+ public function testWrapper(): void {
$test = $this;
$wrapper = function ($mountPoint, $storage) use (&$test) {
$test->assertEquals('/foo/', $mountPoint);
@@ -39,7 +40,7 @@ class MountTest extends \Test\TestCase {
$storage = $this->getMockBuilder('\OC\Files\Storage\Temporary')
->disableOriginalConstructor()
->getMock();
- $mount = new \OC\Files\Mount\MountPoint($storage, '/foo', [], $loader);
+ $mount = new MountPoint($storage, '/foo', [], $loader);
$this->assertInstanceOf('\OC\Files\Storage\Wrapper\Wrapper', $mount->getStorage());
}
}
diff --git a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php
index e53069ee2b8..ae0a53f2cc0 100644
--- a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php
+++ b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php
@@ -1,8 +1,16 @@
<?php
+/**
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
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;
@@ -27,53 +35,56 @@ 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() {
- $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());
+ public function testSingleBucket(): void {
+ $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() {
- $this->config->expects($this->exactly(2))
- ->method('getSystemValue')
- ->with($this->equalTo('objectstore_multibucket'), '')
- ->willReturn([
- 'class' => 'Test\Files\Mount\FakeObjectStore',
- ]);
+ public function testMultiBucket(): void {
+ $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())
+ $this->config
->method('setUserValue')
->with(
$this->equalTo('uid'),
@@ -83,42 +94,37 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
$this->equalTo(null)
);
- $config = $this->invokePrivate($this->provider, 'getMultiBucketObjectStoreConfig', [$this->user, $this->loader]);
-
- $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']);
- }
-
- public function testMultiBucketWithPrefix() {
- $this->config->expects($this->exactly(2))
- ->method('getSystemValue')
- ->with('objectstore_multibucket')
- ->willReturn([
- 'class' => 'Test\Files\Mount\FakeObjectStore',
- 'arguments' => [
- 'bucket' => 'myBucketPrefix',
- ],
- ]);
+ $mount = $this->provider->getHomeMountForUser($this->user, $this->loader);
+ $arguments = $this->invokePrivate($mount, 'arguments');
+
+ $objectStore = $arguments['objectstore'];
+ $this->assertInstanceOf(FakeObjectStore::class, $objectStore);
+ $this->assertEquals(['foo' => 'bar', 'bucket' => 49, 'multibucket' => true], $objectStore->getArguments());
+ }
+
+ public function testMultiBucketWithPrefix(): void {
+ $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')
@@ -130,66 +136,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() {
- $this->config->expects($this->once())
- ->method('getSystemValue')
- ->with('objectstore_multibucket')
- ->willReturn([
- 'class' => 'Test\Files\Mount\FakeObjectStore',
- 'arguments' => [
- 'bucket' => 'myBucketPrefix',
- ],
- ]);
+ public function testMultiBucketBucketAlreadySet(): void {
+ $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]);
-
- $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']);
- }
-
- public function testMultiBucketConfigFirst() {
- $this->config->expects($this->exactly(2))
- ->method('getSystemValue')
- ->with('objectstore_multibucket')
- ->willReturn([
- 'class' => 'Test\Files\Mount\FakeObjectStore',
- ]);
+ $mount = $this->provider->getHomeMountForUser($this->user, $this->loader);
+ $arguments = $this->invokePrivate($mount, 'arguments');
+
+ $objectStore = $arguments['objectstore'];
+ $this->assertInstanceOf(FakeObjectStore::class, $objectStore);
+ $this->assertEquals(['foo' => 'bar', 'bucket' => 'awesomeBucket1', 'multibucket' => true], $objectStore->getArguments());
+ }
+
+ public function testMultiBucketConfigFirst(): void {
+ $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');
@@ -199,18 +209,18 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
$this->assertInstanceOf('OC\Files\Mount\MountPoint', $mount);
}
- public function testMultiBucketConfigFirstFallBackSingle() {
- $this->config->expects($this->exactly(2))
- ->method('getSystemValue')
- ->withConsecutive(
- [$this->equalTo('objectstore_multibucket')],
- [$this->equalTo('objectstore')],
- )->willReturnOnConsecutiveCalls(
- '',
- [
+ public function testMultiBucketConfigFirstFallBackSingle(): void {
+ $this->config
+ ->method('getSystemValue')->willReturnMap([
+ ['objectstore_multibucket', null, null],
+ ['objectstore', null, [
'class' => 'Test\Files\Mount\FakeObjectStore',
- ],
- );
+ 'arguments' => [
+ 'foo' => 'bar',
+ 'bucket' => 'myBucketPrefix',
+ ],
+ ]],
+ ]);
$this->user->method('getUID')
->willReturn('uid');
@@ -220,24 +230,42 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
$this->assertInstanceOf('OC\Files\Mount\MountPoint', $mount);
}
- public function testNoObjectStore() {
- $this->config->expects($this->exactly(2))
- ->method('getSystemValue')
- ->willReturn('');
+ public function testNoObjectStore(): void {
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function ($key, $default) {
+ return $default;
+ });
$mount = $this->provider->getHomeMountForUser($this->user, $this->loader);
$this->assertNull($mount);
}
}
-class FakeObjectStore {
- private $arguments;
-
- public function __construct(array $arguments) {
- $this->arguments = $arguments;
+class FakeObjectStore implements IObjectStore {
+ public function __construct(
+ private array $arguments,
+ ) {
}
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/ObjectStorePreviewCacheMountProviderTest.php b/tests/lib/Files/Mount/ObjectStorePreviewCacheMountProviderTest.php
index da9ba8bacaf..9060bf0d5f5 100644
--- a/tests/lib/Files/Mount/ObjectStorePreviewCacheMountProviderTest.php
+++ b/tests/lib/Files/Mount/ObjectStorePreviewCacheMountProviderTest.php
@@ -2,25 +2,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020, Morris Jobke <hey@morrisjobke.de>
- *
- * @author Morris Jobke <hey@morrisjobke.de>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Files\Mount;
@@ -60,7 +43,7 @@ class ObjectStorePreviewCacheMountProviderTest extends \Test\TestCase {
$this->provider = new ObjectStorePreviewCacheMountProvider($this->logger, $this->config);
}
- public function testNoMultibucketObjectStorage() {
+ public function testNoMultibucketObjectStorage(): void {
$this->config->expects($this->once())
->method('getSystemValue')
->with('objectstore_multibucket')
@@ -69,7 +52,7 @@ class ObjectStorePreviewCacheMountProviderTest extends \Test\TestCase {
$this->assertEquals([], $this->provider->getRootMounts($this->loader));
}
- public function testMultibucketObjectStorage() {
+ public function testMultibucketObjectStorage(): void {
$objectstoreConfig = [
'class' => S3::class,
'arguments' => [
diff --git a/tests/lib/Files/Mount/RootMountProviderTest.php b/tests/lib/Files/Mount/RootMountProviderTest.php
index e5eaabf93be..bf29bfa070a 100644
--- a/tests/lib/Files/Mount/RootMountProviderTest.php
+++ b/tests/lib/Files/Mount/RootMountProviderTest.php
@@ -2,34 +2,20 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
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;
/**
@@ -55,11 +41,11 @@ 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() {
+ public function testLocal(): void {
$provider = $this->getProvider([
'datadirectory' => '/data',
]);
@@ -73,20 +59,20 @@ class RootMountProviderTest extends TestCase {
$this->assertEquals('/data/', $storage->getSourcePath(''));
}
- public function testObjectStore() {
+ public function testObjectStore(): void {
$provider = $this->getProvider([
'objectstore' => [
- "class" => "OC\Files\ObjectStore\S3",
- "arguments" => [
- "bucket" => "nextcloud",
- "autocreate" => true,
- "key" => "minio",
- "secret" => "minio123",
- "hostname" => "localhost",
- "port" => 9000,
- "use_ssl" => false,
- "use_path_style" => true,
- "uploadPartSize" => 52428800,
+ 'class' => "OC\Files\ObjectStore\S3",
+ 'arguments' => [
+ 'bucket' => 'nextcloud',
+ 'autocreate' => true,
+ 'key' => 'minio',
+ 'secret' => 'minio123',
+ 'hostname' => 'localhost',
+ 'port' => 9000,
+ 'use_ssl' => false,
+ 'use_path_style' => true,
+ 'uploadPartSize' => 52428800,
],
],
]);
@@ -106,20 +92,20 @@ class RootMountProviderTest extends TestCase {
$this->assertEquals('nextcloud', $objectStore->getBucket());
}
- public function testObjectStoreMultiBucket() {
+ public function testObjectStoreMultiBucket(): void {
$provider = $this->getProvider([
'objectstore_multibucket' => [
- "class" => "OC\Files\ObjectStore\S3",
- "arguments" => [
- "bucket" => "nextcloud",
- "autocreate" => true,
- "key" => "minio",
- "secret" => "minio123",
- "hostname" => "localhost",
- "port" => 9000,
- "use_ssl" => false,
- "use_path_style" => true,
- "uploadPartSize" => 52428800,
+ 'class' => "OC\Files\ObjectStore\S3",
+ 'arguments' => [
+ 'bucket' => 'nextcloud',
+ 'autocreate' => true,
+ 'key' => 'minio',
+ 'secret' => 'minio123',
+ 'hostname' => 'localhost',
+ 'port' => 9000,
+ 'use_ssl' => false,
+ 'use_path_style' => true,
+ 'uploadPartSize' => 52428800,
],
],
]);