summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-08-07 17:31:03 +0200
committerVincent Petry <pvince81@owncloud.com>2015-08-07 17:31:03 +0200
commitb3a1aef93414ee1ec3a124f66a6964a27338b44c (patch)
treec933beada324e6bb810c4c57dbb1f7dde5320bbf /tests
parent404b5a2e4a4ddb1b2d6b8c430686b4c3fb68beb0 (diff)
parent75a5e6e12b18a9f5b7b113cd7e2c9c56c204084d (diff)
downloadnextcloud-server-b3a1aef93414ee1ec3a124f66a6964a27338b44c.tar.gz
nextcloud-server-b3a1aef93414ee1ec3a124f66a6964a27338b44c.zip
Merge pull request #13641 from owncloud/cache-storage-status
Store storage availability in database
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/files/mount/mountpoint.php21
-rw-r--r--tests/lib/files/storage/wrapper/availability.php149
2 files changed, 170 insertions, 0 deletions
diff --git a/tests/lib/files/mount/mountpoint.php b/tests/lib/files/mount/mountpoint.php
index 29610e6058d..d758c1b8d4d 100644
--- a/tests/lib/files/mount/mountpoint.php
+++ b/tests/lib/files/mount/mountpoint.php
@@ -70,4 +70,25 @@ class MountPoint extends \Test\TestCase {
// storage wrapper never called
$this->assertFalse($called);
}
+
+ public function testWrappedStorage() {
+ $storage = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Wrapper')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $loader = $this->getMock('\OCP\Files\Storage\IStorageFactory');
+ $loader->expects($this->never())
+ ->method('getInstance');
+ $loader->expects($this->never())
+ ->method('wrap');
+
+ $mountPoint = new \OC\Files\Mount\MountPoint(
+ $storage,
+ '/mountpoint',
+ null,
+ $loader
+ );
+
+ $this->assertEquals($storage, $mountPoint->getStorage());
+ }
}
diff --git a/tests/lib/files/storage/wrapper/availability.php b/tests/lib/files/storage/wrapper/availability.php
new file mode 100644
index 00000000000..9b394df8ca3
--- /dev/null
+++ b/tests/lib/files/storage/wrapper/availability.php
@@ -0,0 +1,149 @@
+<?php
+/**
+ * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+namespace Test\Files\Storage\Wrapper;
+
+class Availability extends \Test\TestCase {
+ protected function getWrapperInstance() {
+ $storage = $this->getMockBuilder('\OC\Files\Storage\Temporary')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $wrapper = new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]);
+ return [$storage, $wrapper];
+ }
+
+ /**
+ * Storage is available
+ */
+ public function testAvailable() {
+ list($storage, $wrapper) = $this->getWrapperInstance();
+ $storage->expects($this->once())
+ ->method('getAvailability')
+ ->willReturn(['available' => true, 'last_checked' => 0]);
+ $storage->expects($this->never())
+ ->method('test');
+ $storage->expects($this->once())
+ ->method('mkdir');
+
+ $wrapper->mkdir('foobar');
+ }
+
+ /**
+ * Storage marked unavailable, TTL not expired
+ *
+ * @expectedException \OCP\Files\StorageNotAvailableException
+ */
+ public function testUnavailable() {
+ list($storage, $wrapper) = $this->getWrapperInstance();
+ $storage->expects($this->once())
+ ->method('getAvailability')
+ ->willReturn(['available' => false, 'last_checked' => time()]);
+ $storage->expects($this->never())
+ ->method('test');
+ $storage->expects($this->never())
+ ->method('mkdir');
+
+ $wrapper->mkdir('foobar');
+ }
+
+ /**
+ * Storage marked unavailable, TTL expired
+ */
+ public function testUnavailableRecheck() {
+ list($storage, $wrapper) = $this->getWrapperInstance();
+ $storage->expects($this->once())
+ ->method('getAvailability')
+ ->willReturn(['available' => false, 'last_checked' => 0]);
+ $storage->expects($this->once())
+ ->method('test')
+ ->willReturn(true);
+ $storage->expects($this->once())
+ ->method('setAvailability')
+ ->with($this->equalTo(true));
+ $storage->expects($this->once())
+ ->method('mkdir');
+
+ $wrapper->mkdir('foobar');
+ }
+
+ /**
+ * Storage marked available, but throws StorageNotAvailableException
+ *
+ * @expectedException \OCP\Files\StorageNotAvailableException
+ */
+ public function testAvailableThrowStorageNotAvailable() {
+ list($storage, $wrapper) = $this->getWrapperInstance();
+ $storage->expects($this->once())
+ ->method('getAvailability')
+ ->willReturn(['available' => true, 'last_checked' => 0]);
+ $storage->expects($this->never())
+ ->method('test');
+ $storage->expects($this->once())
+ ->method('mkdir')
+ ->will($this->throwException(new \OCP\Files\StorageNotAvailableException()));
+ $storage->expects($this->once())
+ ->method('setAvailability')
+ ->with($this->equalTo(false));
+
+ $wrapper->mkdir('foobar');
+ }
+
+ /**
+ * Storage available, but call fails
+ * Method failure does not indicate storage unavailability
+ */
+ public function testAvailableFailure() {
+ list($storage, $wrapper) = $this->getWrapperInstance();
+ $storage->expects($this->once())
+ ->method('getAvailability')
+ ->willReturn(['available' => true, 'last_checked' => 0]);
+ $storage->expects($this->never())
+ ->method('test');
+ $storage->expects($this->once())
+ ->method('mkdir')
+ ->willReturn(false);
+ $storage->expects($this->never())
+ ->method('setAvailability');
+
+ $wrapper->mkdir('foobar');
+ }
+
+ /**
+ * Storage available, but throws exception
+ * Standard exception does not indicate storage unavailability
+ *
+ * @expectedException \Exception
+ */
+ public function testAvailableThrow() {
+ list($storage, $wrapper) = $this->getWrapperInstance();
+ $storage->expects($this->once())
+ ->method('getAvailability')
+ ->willReturn(['available' => true, 'last_checked' => 0]);
+ $storage->expects($this->never())
+ ->method('test');
+ $storage->expects($this->once())
+ ->method('mkdir')
+ ->will($this->throwException(new \Exception()));
+ $storage->expects($this->never())
+ ->method('setAvailability');
+
+ $wrapper->mkdir('foobar');
+ }
+}