From 693ca9a92ff268ecbd16c7bd7795a177869ea785 Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Wed, 18 Mar 2015 16:19:04 +0000 Subject: Add unit tests for gc() for \OC\Cache\FileGlobalGC --- tests/lib/cache/fileglobalgc.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests/lib/cache') diff --git a/tests/lib/cache/fileglobalgc.php b/tests/lib/cache/fileglobalgc.php index 0b0a4cb002d..4f032538e7d 100644 --- a/tests/lib/cache/fileglobalgc.php +++ b/tests/lib/cache/fileglobalgc.php @@ -70,4 +70,38 @@ class FileGlobalGC extends TestCase { mkdir($this->cacheDir . 'asd'); $this->assertEquals([$this->cacheDir . 'foo'], $this->gc->getExpiredPaths($this->cacheDir, $time)); } + + public function testGcUnlink() { + $time = time(); + $this->addCacheFile('foo', $time - 10); + $this->addCacheFile('bar', $time - 10); + $this->addCacheFile('asd', $time + 10); + + $config = $this->getMock('\OCP\IConfig'); + $config->expects($this->once()) + ->method('getAppValue') + ->with('core', 'global_cache_gc_lastrun', 0) + ->willReturn($time - \OC\Cache\FileGlobalGC::CLEANUP_TTL_SEC - 1); + $config->expects($this->once()) + ->method('setAppValue'); + + $this->gc->gc($config, $this->cacheDir); + $this->assertFileNotExists($this->cacheDir . 'foo'); + $this->assertFileNotExists($this->cacheDir . 'bar'); + $this->assertFileExists($this->cacheDir . 'asd'); + } + + public function testGcLastRun() { + $time = time(); + + $config = $this->getMock('\OCP\IConfig'); + $config->expects($this->once()) + ->method('getAppValue') + ->with('core', 'global_cache_gc_lastrun', 0) + ->willReturn($time); + $config->expects($this->never()) + ->method('setAppValue'); + + $this->gc->gc($config, $this->cacheDir); + } } -- cgit v1.2.3