ObjectStorePreviewCacheMountProviderTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2020, Morris Jobke <hey@morrisjobke.de>
  5. *
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace Test\Files\Mount;
  25. use OC\Files\Mount\ObjectStorePreviewCacheMountProvider;
  26. use OC\Files\ObjectStore\S3;
  27. use OC\Files\Storage\StorageFactory;
  28. use OCP\Files\Storage\IStorageFactory;
  29. use OCP\IConfig;
  30. use PHPUnit\Framework\MockObject\MockObject;
  31. use Psr\Log\LoggerInterface;
  32. /**
  33. * @group DB
  34. *
  35. * The DB permission is needed for the fake root storage initialization
  36. */
  37. class ObjectStorePreviewCacheMountProviderTest extends \Test\TestCase {
  38. /** @var ObjectStorePreviewCacheMountProvider */
  39. protected $provider;
  40. /** @var LoggerInterface|MockObject */
  41. protected $logger;
  42. /** @var IConfig|MockObject */
  43. protected $config;
  44. /** @var IStorageFactory|MockObject */
  45. protected $loader;
  46. protected function setUp(): void {
  47. parent::setUp();
  48. $this->logger = $this->createMock(LoggerInterface::class);
  49. $this->config = $this->createMock(IConfig::class);
  50. $this->loader = $this->createMock(StorageFactory::class);
  51. $this->provider = new ObjectStorePreviewCacheMountProvider($this->logger, $this->config);
  52. }
  53. public function testNoMultibucketObjectStorage() {
  54. $this->config->expects($this->once())
  55. ->method('getSystemValue')
  56. ->with('objectstore_multibucket')
  57. ->willReturn(null);
  58. $this->assertEquals([], $this->provider->getRootMounts($this->loader));
  59. }
  60. public function testMultibucketObjectStorage() {
  61. $objectstoreConfig = [
  62. 'class' => S3::class,
  63. 'arguments' => [
  64. 'bucket' => 'abc',
  65. 'num_buckets' => 64,
  66. 'key' => 'KEY',
  67. 'secret' => 'SECRET',
  68. 'hostname' => 'IP',
  69. 'port' => 'PORT',
  70. 'use_ssl' => false,
  71. 'use_path_style' => true,
  72. ],
  73. ];
  74. $this->config->expects($this->any())
  75. ->method('getSystemValue')
  76. ->willReturnCallback(function ($config) use ($objectstoreConfig) {
  77. if ($config === 'objectstore_multibucket') {
  78. return $objectstoreConfig;
  79. } elseif ($config === 'objectstore.multibucket.preview-distribution') {
  80. return true;
  81. }
  82. return null;
  83. });
  84. $this->config->expects($this->once())
  85. ->method('getSystemValueString')
  86. ->with('instanceid')
  87. ->willReturn('INSTANCEID');
  88. $mounts = $this->provider->getRootMounts($this->loader);
  89. // 256 mounts for the subfolders and 1 for the fake root
  90. $this->assertCount(257, $mounts);
  91. // do some sanity checks if they have correct mount point paths
  92. $this->assertEquals('/appdata_INSTANCEID/preview/0/0/', $mounts[0]->getMountPoint());
  93. $this->assertEquals('/appdata_INSTANCEID/preview/2/5/', $mounts[37]->getMountPoint());
  94. // also test the path of the fake bucket
  95. $this->assertEquals('/appdata_INSTANCEID/preview/old-multibucket/', $mounts[256]->getMountPoint());
  96. }
  97. }