1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
<?php
declare(strict_types=1);
/**
* 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\S3;
use OC\Files\Storage\LocalRootStorage;
use OC\Files\Storage\StorageFactory;
use OCP\IConfig;
use Psr\Log\LoggerInterface;
use Test\TestCase;
/**
* @group DB
*/
class RootMountProviderTest extends TestCase {
private StorageFactory $loader;
protected function setUp(): void {
parent::setUp();
$this->loader = new StorageFactory();
}
private function getConfig(array $systemConfig): IConfig {
$config = $this->createMock(IConfig::class);
$config->method('getSystemValue')
->willReturnCallback(function (string $key, $default) use ($systemConfig) {
return $systemConfig[$key] ?? $default;
});
return $config;
}
private function getProvider(array $systemConfig): RootMountProvider {
$config = $this->getConfig($systemConfig);
$provider = new RootMountProvider($config, $this->createMock(LoggerInterface::class));
return $provider;
}
public function testLocal() {
$provider = $this->getProvider([
'datadirectory' => '/data',
]);
$mounts = $provider->getRootMounts($this->loader);
$this->assertCount(1, $mounts);
$mount = $mounts[0];
$this->assertEquals('/', $mount->getMountPoint());
/** @var LocalRootStorage $storage */
$storage = $mount->getStorage();
$this->assertInstanceOf(LocalRootStorage::class, $storage);
$this->assertEquals('/data/', $storage->getSourcePath(''));
}
public function testObjectStore() {
$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,
],
],
]);
$mounts = $provider->getRootMounts($this->loader);
$this->assertCount(1, $mounts);
$mount = $mounts[0];
$this->assertEquals('/', $mount->getMountPoint());
/** @var ObjectStoreStorage $storage */
$storage = $mount->getStorage();
$this->assertInstanceOf(ObjectStoreStorage::class, $storage);
$class = new \ReflectionClass($storage);
$prop = $class->getProperty('objectStore');
$prop->setAccessible(true);
/** @var S3 $objectStore */
$objectStore = $prop->getValue($storage);
$this->assertEquals('nextcloud', $objectStore->getBucket());
}
public function testObjectStoreMultiBucket() {
$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,
],
],
]);
$mounts = $provider->getRootMounts($this->loader);
$this->assertCount(1, $mounts);
$mount = $mounts[0];
$this->assertEquals('/', $mount->getMountPoint());
/** @var ObjectStoreStorage $storage */
$storage = $mount->getStorage();
$this->assertInstanceOf(ObjectStoreStorage::class, $storage);
$class = new \ReflectionClass($storage);
$prop = $class->getProperty('objectStore');
$prop->setAccessible(true);
/** @var S3 $objectStore */
$objectStore = $prop->getValue($storage);
$this->assertEquals('nextcloud0', $objectStore->getBucket());
}
}
|