From 3ba46f3b50645c563c45996e5ccea884129ee187 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 19 Mar 2020 15:28:02 +0100 Subject: add basic tests for s3 seeking and add some error handling if reopen return the wrong range Signed-off-by: Robin Appelman --- tests/lib/Files/ObjectStore/ObjectStoreTest.php | 2 +- tests/lib/Files/ObjectStore/S3Test.php | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/lib/Files/ObjectStore/ObjectStoreTest.php b/tests/lib/Files/ObjectStore/ObjectStoreTest.php index 1383c0149a2..67c41eb7ccc 100644 --- a/tests/lib/Files/ObjectStore/ObjectStoreTest.php +++ b/tests/lib/Files/ObjectStore/ObjectStoreTest.php @@ -31,7 +31,7 @@ abstract class ObjectStoreTest extends TestCase { */ abstract protected function getInstance(); - private function stringToStream($data) { + protected function stringToStream($data) { $stream = fopen('php://temp', 'w+'); fwrite($stream, $data); rewind($stream); diff --git a/tests/lib/Files/ObjectStore/S3Test.php b/tests/lib/Files/ObjectStore/S3Test.php index b56978f4fee..525e020445a 100644 --- a/tests/lib/Files/ObjectStore/S3Test.php +++ b/tests/lib/Files/ObjectStore/S3Test.php @@ -27,7 +27,7 @@ use OC\Files\ObjectStore\S3; class MultiPartUploadS3 extends S3 { function writeObject($urn, $stream) { $this->getConnection()->upload($this->bucket, $urn, $stream, 'private', [ - 'mup_threshold' => 1 + 'mup_threshold' => 1, ]); } } @@ -36,8 +36,8 @@ class NonSeekableStream extends Wrapper { public static function wrap($source) { $context = stream_context_create([ 'nonseek' => [ - 'source' => $source - ] + 'source' => $source, + ], ]); return Wrapper::wrapSource($source, $context, 'nonseek', self::class); } @@ -83,4 +83,20 @@ class S3Test extends ObjectStoreTest { $this->assertEquals(file_get_contents(__FILE__), stream_get_contents($result)); } + + public function testSeek() { + $data = file_get_contents(__FILE__); + + $instance = $this->getInstance(); + $instance->writeObject('seek', $this->stringToStream($data)); + + $read = $instance->readObject('seek'); + $this->assertEquals(substr($data, 0, 100), fread($read, 100)); + + fseek($read, 10); + $this->assertEquals(substr($data, 10, 100), fread($read, 100)); + + fseek($read, 100, SEEK_CUR); + $this->assertEquals(substr($data, 210, 100), fread($read, 100)); + } } -- cgit v1.2.3