Add empty file test

Signed-off-by: Bernd.Rederlechner@t-systems.com <bernd.rederlechner@t-systems.com>
This commit is contained in:
Bernd.Rederlechner@t-systems.com 2021-05-11 16:18:09 +00:00
parent 7d3b5956e4
commit f2256a2c11
1 changed files with 23 additions and 12 deletions

View File

@ -25,6 +25,8 @@ use Icewind\Streams\Wrapper;
use Icewind\Streams\CallbackWrapper; use Icewind\Streams\CallbackWrapper;
use OC\Files\ObjectStore\S3; use OC\Files\ObjectStore\S3;
use Aws\S3\S3Client;
use Aws\S3\Exception\S3MultipartUploadException;
class MultiPartUploadS3 extends S3 { class MultiPartUploadS3 extends S3 {
public function writeObject($urn, $stream, string $mimetype = null) { public function writeObject($urn, $stream, string $mimetype = null) {
@ -97,21 +99,30 @@ class S3Test extends ObjectStoreTest {
$this->assertEquals(substr($data, 210, 100), fread($read, 100)); $this->assertEquals(substr($data, 210, 100), fread($read, 100));
} }
public function testEmptyUpload() { function assertNoUpload($objectUrn) {
$s3 = $this->getInstance();
$s3client = $s3->getConnection();
$uploads = $s3client->listMultipartUploads([
'Bucket' => $s3->getBucket(),
'Prefix' => $objectUrn,
]);
//fwrite(STDERR, print_r($uploads, TRUE));
$this->assertArrayNotHasKey('Uploads', $uploads);
}
public function testMultipartException() {
//$this->expectException(S3MultipartUploadException::class);
$s3 = $this->getInstance(); $s3 = $this->getInstance();
$emptyStream = fopen('php://memory', 'w+'); // create an empty stream and check that it fits to the
$count = 0; // pre-conditions in writeObject for the empty case
$countStream = CallbackWrapper::wrap($emptyStream, function ($read) use (&$count) { $stupidStream = fopen("php://memory", "r");
$count += $read; fwrite($stupidStream, NULL);
});
$this->assertEquals($count, 0);
$this->assertTrue(feof($countStream));
$s3->writeObject('emptyuploadtest', $emptyString); $s3->writeObject('stupidstream', $stupidStream);
$result = $s3->readObject('emptyuploadtest'); // this method intendedly produces an S3Exception
$this->assertEquals('', stream_get_contents($result)); $this->assertNoUpload('stupidstream');
} }
} }