mirror of https://github.com/nextcloud/server
cleanup scannertest a bit
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
cb97e8f15c
commit
1850d0ae96
|
@ -8,7 +8,14 @@
|
|||
|
||||
namespace Test\Files\Cache;
|
||||
|
||||
use OC;
|
||||
use OC\Files\Cache\Cache;
|
||||
use OC\Files\Cache\CacheEntry;
|
||||
use OC\Files\Cache\Scanner;
|
||||
use OC\Files\Storage\Storage;
|
||||
use OC\Files\Storage\Temporary;
|
||||
use OCP\Files\Cache\IScanner;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
* Class ScannerTest
|
||||
|
@ -17,34 +24,21 @@ use OC\Files\Cache\CacheEntry;
|
|||
*
|
||||
* @package Test\Files\Cache
|
||||
*/
|
||||
class ScannerTest extends \Test\TestCase {
|
||||
/**
|
||||
* @var \OC\Files\Storage\Storage $storage
|
||||
*/
|
||||
private $storage;
|
||||
|
||||
/**
|
||||
* @var \OC\Files\Cache\Scanner $scanner
|
||||
*/
|
||||
private $scanner;
|
||||
|
||||
/**
|
||||
* @var \OC\Files\Cache\Cache $cache
|
||||
*/
|
||||
private $cache;
|
||||
class ScannerTest extends TestCase {
|
||||
private Storage $storage;
|
||||
private Scanner $scanner;
|
||||
private Cache $cache;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->storage = new \OC\Files\Storage\Temporary([]);
|
||||
$this->scanner = new \OC\Files\Cache\Scanner($this->storage);
|
||||
$this->cache = new \OC\Files\Cache\Cache($this->storage);
|
||||
$this->storage = new Temporary([]);
|
||||
$this->scanner = new Scanner($this->storage);
|
||||
$this->cache = new Cache($this->storage);
|
||||
}
|
||||
|
||||
protected function tearDown(): void {
|
||||
if ($this->cache) {
|
||||
$this->cache->clear();
|
||||
}
|
||||
$this->cache->clear();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
@ -60,7 +54,7 @@ class ScannerTest extends \Test\TestCase {
|
|||
$this->assertEquals($cachedData['mimetype'], 'text/plain');
|
||||
$this->assertNotEquals($cachedData['parent'], -1); //parent folders should be scanned automatically
|
||||
|
||||
$data = file_get_contents(\OC::$SERVERROOT . '/core/img/logo/logo.png');
|
||||
$data = file_get_contents(OC::$SERVERROOT . '/core/img/logo/logo.png');
|
||||
$this->storage->file_put_contents('foo.png', $data);
|
||||
$this->scanner->scanFile('foo.png');
|
||||
|
||||
|
@ -74,7 +68,7 @@ class ScannerTest extends \Test\TestCase {
|
|||
$data = "dummy file data\n";
|
||||
$this->storage->file_put_contents('foo🙈.txt', $data);
|
||||
|
||||
if (\OC::$server->getDatabaseConnection()->supports4ByteText()) {
|
||||
if (OC::$server->getDatabaseConnection()->supports4ByteText()) {
|
||||
$this->assertNotNull($this->scanner->scanFile('foo🙈.txt'));
|
||||
$this->assertTrue($this->cache->inCache('foo🙈.txt'), true);
|
||||
|
||||
|
@ -98,7 +92,7 @@ class ScannerTest extends \Test\TestCase {
|
|||
|
||||
private function fillTestFolders() {
|
||||
$textData = "dummy file data\n";
|
||||
$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo/logo.png');
|
||||
$imgData = file_get_contents(OC::$SERVERROOT . '/core/img/logo/logo.png');
|
||||
$this->storage->mkdir('folder');
|
||||
$this->storage->file_put_contents('foo.txt', $textData);
|
||||
$this->storage->file_put_contents('foo.png', $imgData);
|
||||
|
@ -130,7 +124,7 @@ class ScannerTest extends \Test\TestCase {
|
|||
public function testShallow() {
|
||||
$this->fillTestFolders();
|
||||
|
||||
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
||||
$this->scanner->scan('', IScanner::SCAN_SHALLOW);
|
||||
$this->assertEquals($this->cache->inCache(''), true);
|
||||
$this->assertEquals($this->cache->inCache('foo.txt'), true);
|
||||
$this->assertEquals($this->cache->inCache('foo.png'), true);
|
||||
|
@ -143,7 +137,7 @@ class ScannerTest extends \Test\TestCase {
|
|||
$this->assertEquals(-1, $cachedDataFolder['size']);
|
||||
$this->assertEquals(-1, $cachedDataFolder2['size']);
|
||||
|
||||
$this->scanner->scan('folder', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
||||
$this->scanner->scan('folder', IScanner::SCAN_SHALLOW);
|
||||
|
||||
$cachedDataFolder2 = $this->cache->get('folder');
|
||||
|
||||
|
@ -160,7 +154,7 @@ class ScannerTest extends \Test\TestCase {
|
|||
$this->storage->mkdir('folder2');
|
||||
$this->storage->file_put_contents('folder2/bar.txt', 'foobar');
|
||||
|
||||
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
||||
$this->scanner->scan('', IScanner::SCAN_SHALLOW);
|
||||
$this->assertFalse($this->cache->inCache('folder/bar.txt'));
|
||||
$this->assertFalse($this->cache->inCache('folder/2bar.txt'));
|
||||
$cachedData = $this->cache->get('');
|
||||
|
@ -182,7 +176,7 @@ class ScannerTest extends \Test\TestCase {
|
|||
$this->storage->mkdir('folder2');
|
||||
$this->storage->file_put_contents('folder2/bar.txt', 'foobar');
|
||||
|
||||
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
||||
$this->scanner->scan('', IScanner::SCAN_SHALLOW);
|
||||
$this->assertFalse($this->cache->inCache('folder/bar.txt'));
|
||||
$this->assertFalse($this->cache->inCache('folder/2bar.txt'));
|
||||
$this->assertFalse($this->cache->inCache('folder2/bar.txt'));
|
||||
|
@ -191,7 +185,7 @@ class ScannerTest extends \Test\TestCase {
|
|||
$cachedData = $this->cache->get('');
|
||||
$this->assertEquals(-1, $cachedData['size']);
|
||||
|
||||
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE_INCOMPLETE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE);
|
||||
$this->scanner->scan('', IScanner::SCAN_RECURSIVE_INCOMPLETE, IScanner::REUSE_ETAG | IScanner::REUSE_SIZE);
|
||||
|
||||
$this->assertTrue($this->cache->inCache('folder/bar.txt'));
|
||||
$this->assertTrue($this->cache->inCache('folder/bar.txt'));
|
||||
|
@ -248,7 +242,7 @@ class ScannerTest extends \Test\TestCase {
|
|||
$oldData = $this->cache->get('');
|
||||
$this->storage->unlink('folder/bar.txt');
|
||||
$this->cache->put('folder', ['mtime' => $this->storage->filemtime('folder'), 'storage_mtime' => $this->storage->filemtime('folder')]);
|
||||
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_SIZE);
|
||||
$this->scanner->scan('', IScanner::SCAN_SHALLOW, IScanner::REUSE_SIZE);
|
||||
$newData = $this->cache->get('');
|
||||
$this->assertIsString($oldData['etag']);
|
||||
$this->assertIsString($newData['etag']);
|
||||
|
@ -256,25 +250,25 @@ class ScannerTest extends \Test\TestCase {
|
|||
$this->assertEquals($oldData['size'], $newData['size']);
|
||||
|
||||
$oldData = $newData;
|
||||
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG);
|
||||
$this->scanner->scan('', IScanner::SCAN_SHALLOW, IScanner::REUSE_ETAG);
|
||||
$newData = $this->cache->get('');
|
||||
$this->assertSame($oldData['etag'], $newData['etag']);
|
||||
$this->assertEquals(-1, $newData['size']);
|
||||
|
||||
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE);
|
||||
$this->scanner->scan('', IScanner::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);
|
||||
$this->scanner->scanFile('', IScanner::REUSE_ETAG + IScanner::REUSE_SIZE);
|
||||
$newData = $this->cache->get('');
|
||||
$this->assertSame($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);
|
||||
$this->scanner->scan('', IScanner::SCAN_RECURSIVE, IScanner::REUSE_ETAG + IScanner::REUSE_SIZE);
|
||||
$newData = $this->cache->get('');
|
||||
$this->assertSame($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);
|
||||
$this->scanner->scan('', IScanner::SCAN_SHALLOW, IScanner::REUSE_ETAG + IScanner::REUSE_SIZE);
|
||||
$newData = $this->cache->get('');
|
||||
$this->assertSame($oldData['etag'], $newData['etag']);
|
||||
$this->assertEquals($oldData['size'], $newData['size']);
|
||||
|
@ -286,7 +280,7 @@ class ScannerTest extends \Test\TestCase {
|
|||
$this->scanner->scan('');
|
||||
$this->assertTrue($this->cache->inCache('foo.txt'));
|
||||
$this->storage->unlink('foo.txt');
|
||||
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
||||
$this->scanner->scan('', IScanner::SCAN_SHALLOW);
|
||||
$this->assertFalse($this->cache->inCache('foo.txt'));
|
||||
}
|
||||
|
||||
|
@ -296,7 +290,7 @@ class ScannerTest extends \Test\TestCase {
|
|||
$this->scanner->scan('');
|
||||
$this->assertTrue($this->cache->inCache('folder/bar.txt'));
|
||||
$this->storage->rmdir('/folder');
|
||||
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
||||
$this->scanner->scan('', IScanner::SCAN_SHALLOW);
|
||||
$this->assertFalse($this->cache->inCache('folder'));
|
||||
$this->assertFalse($this->cache->inCache('folder/bar.txt'));
|
||||
}
|
||||
|
@ -317,7 +311,7 @@ class ScannerTest extends \Test\TestCase {
|
|||
$this->scanner->scan('folder/bar.txt');
|
||||
|
||||
// manipulate etag to simulate an empty etag
|
||||
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG);
|
||||
$this->scanner->scan('', IScanner::SCAN_SHALLOW, IScanner::REUSE_ETAG);
|
||||
/** @var CacheEntry $data0 */
|
||||
$data0 = $this->cache->get('folder/bar.txt');
|
||||
$this->assertIsString($data0['etag']);
|
||||
|
@ -329,7 +323,7 @@ class ScannerTest extends \Test\TestCase {
|
|||
$this->cache->put('folder/bar.txt', $data0->getData());
|
||||
|
||||
// rescan
|
||||
$this->scanner->scan('folder/bar.txt', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG);
|
||||
$this->scanner->scan('folder/bar.txt', IScanner::SCAN_SHALLOW, IScanner::REUSE_ETAG);
|
||||
|
||||
// verify cache content
|
||||
$newData0 = $this->cache->get('folder/bar.txt');
|
||||
|
@ -344,7 +338,7 @@ class ScannerTest extends \Test\TestCase {
|
|||
$oldFolderId = $this->cache->getId('folder');
|
||||
|
||||
// delete the folder without removing the children
|
||||
$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
|
||||
$query = OC::$server->getDatabaseConnection()->getQueryBuilder();
|
||||
$query->delete('filecache')
|
||||
->where($query->expr()->eq('fileid', $query->createNamedParameter($oldFolderId)));
|
||||
$query->execute();
|
||||
|
@ -370,7 +364,7 @@ class ScannerTest extends \Test\TestCase {
|
|||
$oldFolderId = $this->cache->getId('folder');
|
||||
|
||||
// delete the folder without removing the children
|
||||
$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
|
||||
$query = OC::$server->getDatabaseConnection()->getQueryBuilder();
|
||||
$query->delete('filecache')
|
||||
->where($query->expr()->eq('fileid', $query->createNamedParameter($oldFolderId)));
|
||||
$query->execute();
|
||||
|
@ -379,7 +373,7 @@ class ScannerTest extends \Test\TestCase {
|
|||
$this->assertEquals($oldFolderId, $cachedData['parent']);
|
||||
$this->assertFalse($this->cache->inCache('folder'));
|
||||
|
||||
$this->scanner->scan('folder', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
||||
$this->scanner->scan('folder', IScanner::SCAN_SHALLOW);
|
||||
|
||||
$this->assertTrue($this->cache->inCache('folder'));
|
||||
$newFolderId = $this->cache->getId('folder');
|
||||
|
|
Loading…
Reference in New Issue