]> source.dussan.org Git - nextcloud-server.git/commitdiff
Scanner: additional tests for reusing etags during scanning
authorRobin Appelman <icewind@owncloud.com>
Mon, 12 Aug 2013 13:37:15 +0000 (15:37 +0200)
committerRobin Appelman <icewind@owncloud.com>
Mon, 12 Aug 2013 15:30:14 +0000 (17:30 +0200)
tests/lib/files/cache/scanner.php
tests/lib/files/utils/scanner.php [new file with mode: 0644]

index 4e059d2cf03942af9ad546c24014d8fd3bba71c8..3ab1f8408cca86a12138002224755a927580ec9d 100644 (file)
@@ -143,6 +143,24 @@ class Scanner extends \PHPUnit_Framework_TestCase {
                $newData = $this->cache->get('');
                $this->assertEquals($oldData['etag'], $newData['etag']);
                $this->assertEquals(-1, $newData['size']);
+
+               $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE);
+               $oldData = $this->cache->get('');
+               $this->assertNotEquals(-1, $oldData['size']);
+               $this->scanner->scanFile('', \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE);
+               $newData = $this->cache->get('');
+               $this->assertEquals($oldData['etag'], $newData['etag']);
+               $this->assertEquals($oldData['size'], $newData['size']);
+
+               $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE);
+               $newData = $this->cache->get('');
+               $this->assertEquals($oldData['etag'], $newData['etag']);
+               $this->assertEquals($oldData['size'], $newData['size']);
+
+               $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE);
+               $newData = $this->cache->get('');
+               $this->assertEquals($oldData['etag'], $newData['etag']);
+               $this->assertEquals($oldData['size'], $newData['size']);
        }
 
        public function testRemovedFile() {
diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php
new file mode 100644 (file)
index 0000000..a021d21
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Utils;
+
+use OC\Files\Mount\Mount;
+use OC\Files\Storage\Temporary;
+
+class TestScanner extends \OC\Files\Utils\Scanner {
+       /**
+        * @var \OC\Files\Mount\Mount[] $mounts
+        */
+       private $mounts = array();
+
+       /**
+        * @param \OC\Files\Mount\Mount $mount
+        */
+       public function addMount($mount) {
+               $this->mounts[] = $mount;
+       }
+
+       protected function getMounts($dir) {
+               return $this->mounts;
+       }
+}
+
+class Scanner extends \PHPUnit_Framework_TestCase {
+       public function testReuseExistingRoot() {
+               $storage = new Temporary(array());
+               $mount = new Mount($storage, '');
+               $cache = $storage->getCache();
+
+               $storage->mkdir('folder');
+               $storage->file_put_contents('foo.txt', 'qwerty');
+               $storage->file_put_contents('folder/bar.txt', 'qwerty');
+
+               $scanner = new TestScanner('');
+               $scanner->addMount($mount);
+
+               $scanner->scan('');
+               $this->assertTrue($cache->inCache('folder/bar.txt'));
+               $oldRoot = $cache->get('');
+
+               $scanner->scan('');
+               $newRoot = $cache->get('');
+               $this->assertEquals($oldRoot, $newRoot);
+       }
+
+       public function testReuseExistingFile() {
+               $storage = new Temporary(array());
+               $mount = new Mount($storage, '');
+               $cache = $storage->getCache();
+
+               $storage->mkdir('folder');
+               $storage->file_put_contents('foo.txt', 'qwerty');
+               $storage->file_put_contents('folder/bar.txt', 'qwerty');
+
+               $scanner = new TestScanner('');
+               $scanner->addMount($mount);
+
+               $scanner->scan('');
+               $this->assertTrue($cache->inCache('folder/bar.txt'));
+               $old = $cache->get('folder/bar.txt');
+
+               $scanner->scan('');
+               $new = $cache->get('folder/bar.txt');
+               $this->assertEquals($old, $new);
+       }
+}