Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ObjectStorePreviewCacheMountProviderTest.php « Mount « Files « lib « tests - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ef2ede729cea8f7257e9650d41f87bb277e58dd8 (plain)
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
<?php

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/>.
 *
 */

namespace Test\Files\Mount;

use OC\Files\Mount\ObjectStorePreviewCacheMountProvider;
use OC\Files\ObjectStore\S3;
use OC\Files\Storage\StorageFactory;
use OCP\Files\Storage\IStorageFactory;
use OCP\IConfig;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;

/**
 * @group DB
 *
 * The DB permission is needed for the fake root storage initialization
 */
class ObjectStorePreviewCacheMountProviderTest extends \Test\TestCase {

	/** @var ObjectStorePreviewCacheMountProvider */
	protected $provider;

	/** @var LoggerInterface|MockObject */
	protected $logger;
	/** @var IConfig|MockObject */
	protected $config;
	/** @var IStorageFactory|MockObject */
	protected $loader;


	protected function setUp(): void {
		parent::setUp();

		$this->logger = $this->createMock(LoggerInterface::class);
		$this->config = $this->createMock(IConfig::class);
		$this->loader = $this->createMock(StorageFactory::class);

		$this->provider = new ObjectStorePreviewCacheMountProvider($this->logger, $this->config);
	}

	public function testNoMultibucketObjectStorage() {
		$this->config->expects($this->once())
			->method('getSystemValue')
			->with('objectstore_multibucket')
			->willReturn(null);

		$this->assertEquals([], $this->provider->getRootMounts($this->loader));
	}

	public function testMultibucketObjectStorage() {
		$objectstoreConfig = [
			'class' => S3::class,
			'arguments' => [
				'bucket' => 'abc',
				'num_buckets' => 64,
				'key' => 'KEY',
				'secret' => 'SECRET',
				'hostname' => 'IP',
				'port' => 'PORT',
				'use_ssl' => false,
				'use_path_style' => true,
			],
		];
		$this->config->expects($this->any())
			->method('getSystemValue')
			->willReturnCallback(function ($config) use ($objectstoreConfig) {
				if ($config === 'objectstore_multibucket') {
					return $objectstoreConfig;
				} elseif ($config === 'objectstore.multibucket.preview-distribution') {
					return true;
				}
				return null;
			});
		$this->config->expects($this->once())
			->method('getSystemValueString')
			->with('instanceid')
			->willReturn('INSTANCEID');

		$mounts = $this->provider->getRootMounts($this->loader);

		// 256 mounts for the subfolders and 1 for the fake root
		$this->assertCount(257, $mounts);

		// do some sanity checks if they have correct mount point paths
		$this->assertEquals('/appdata_INSTANCEID/preview/0/0/', $mounts[0]->getMountPoint());
		$this->assertEquals('/appdata_INSTANCEID/preview/2/5/', $mounts[37]->getMountPoint());
		// also test the path of the fake bucket
		$this->assertEquals('/appdata_INSTANCEID/preview/old-multibucket/', $mounts[256]->getMountPoint());
	}
}