ObjectStorePreviewCacheMountProviderTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\Files\Mount;
  8. use OC\Files\Mount\ObjectStorePreviewCacheMountProvider;
  9. use OC\Files\ObjectStore\S3;
  10. use OC\Files\Storage\StorageFactory;
  11. use OCP\Files\Storage\IStorageFactory;
  12. use OCP\IConfig;
  13. use PHPUnit\Framework\MockObject\MockObject;
  14. use Psr\Log\LoggerInterface;
  15. /**
  16. * @group DB
  17. *
  18. * The DB permission is needed for the fake root storage initialization
  19. */
  20. class ObjectStorePreviewCacheMountProviderTest extends \Test\TestCase {
  21. /** @var ObjectStorePreviewCacheMountProvider */
  22. protected $provider;
  23. /** @var LoggerInterface|MockObject */
  24. protected $logger;
  25. /** @var IConfig|MockObject */
  26. protected $config;
  27. /** @var IStorageFactory|MockObject */
  28. protected $loader;
  29. protected function setUp(): void {
  30. parent::setUp();
  31. $this->logger = $this->createMock(LoggerInterface::class);
  32. $this->config = $this->createMock(IConfig::class);
  33. $this->loader = $this->createMock(StorageFactory::class);
  34. $this->provider = new ObjectStorePreviewCacheMountProvider($this->logger, $this->config);
  35. }
  36. public function testNoMultibucketObjectStorage() {
  37. $this->config->expects($this->once())
  38. ->method('getSystemValue')
  39. ->with('objectstore_multibucket')
  40. ->willReturn(null);
  41. $this->assertEquals([], $this->provider->getRootMounts($this->loader));
  42. }
  43. public function testMultibucketObjectStorage() {
  44. $objectstoreConfig = [
  45. 'class' => S3::class,
  46. 'arguments' => [
  47. 'bucket' => 'abc',
  48. 'num_buckets' => 64,
  49. 'key' => 'KEY',
  50. 'secret' => 'SECRET',
  51. 'hostname' => 'IP',
  52. 'port' => 'PORT',
  53. 'use_ssl' => false,
  54. 'use_path_style' => true,
  55. ],
  56. ];
  57. $this->config->expects($this->any())
  58. ->method('getSystemValue')
  59. ->willReturnCallback(function ($config) use ($objectstoreConfig) {
  60. if ($config === 'objectstore_multibucket') {
  61. return $objectstoreConfig;
  62. } elseif ($config === 'objectstore.multibucket.preview-distribution') {
  63. return true;
  64. }
  65. return null;
  66. });
  67. $this->config->expects($this->once())
  68. ->method('getSystemValueString')
  69. ->with('instanceid')
  70. ->willReturn('INSTANCEID');
  71. $mounts = $this->provider->getRootMounts($this->loader);
  72. // 256 mounts for the subfolders and 1 for the fake root
  73. $this->assertCount(257, $mounts);
  74. // do some sanity checks if they have correct mount point paths
  75. $this->assertEquals('/appdata_INSTANCEID/preview/0/0/', $mounts[0]->getMountPoint());
  76. $this->assertEquals('/appdata_INSTANCEID/preview/2/5/', $mounts[37]->getMountPoint());
  77. // also test the path of the fake bucket
  78. $this->assertEquals('/appdata_INSTANCEID/preview/old-multibucket/', $mounts[256]->getMountPoint());
  79. }
  80. }