1
0
Fork 0
mirror of synced 2024-06-29 11:40:45 +12:00

ZSTD compression test

This commit is contained in:
Damodar Lohani 2022-08-31 02:49:13 +00:00
parent 4ba8e725ea
commit 77c72970e8
2 changed files with 55 additions and 0 deletions

View file

@ -66,6 +66,13 @@ class Bucket extends Model
'example' => ['jpg', 'png'],
'array' => true
])
->addRule('compression', [
'type' => self::TYPE_STRING,
'description' => 'Compression method chosen.',
'default' => [],
'example' => 'gzip',
'array' => false
])
->addRule('encryption', [
'type' => self::TYPE_BOOLEAN,
'description' => 'Bucket is encrypted.',

View file

@ -243,6 +243,54 @@ trait StorageBase
return ['bucketId' => $bucketId, 'fileId' => $file['body']['$id'], 'largeFileId' => $largeFile['body']['$id'], 'largeBucketId' => $bucket2['body']['$id']];
}
public function testCreateBucketFileZstdCompression(): void
{
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
], [
'bucketId' => ID::unique(),
'name' => 'Test Bucket',
'fileSecurity' => true,
'maximumFileSize' => 2000000, //2MB
'allowedFileExtensions' => ["jpg", "png"],
'compression' => 'zstd',
'permissions' => [
Permission::read(Role::any()),
Permission::create(Role::any()),
Permission::update(Role::any()),
Permission::delete(Role::any()),
],
]);
$this->assertEquals(201, $bucket['headers']['status-code']);
$this->assertNotEmpty($bucket['body']['$id']);
$this->assertEquals('zstd', $bucket['body']['compression']);
$bucketId = $bucket['body']['$id'];
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([
'content-type' => 'multipart/form-data',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'fileId' => ID::unique(),
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'),
'permissions' => [
Permission::read(Role::any()),
Permission::update(Role::any()),
Permission::delete(Role::any()),
],
]);
$this->assertEquals(201, $file['headers']['status-code']);
$this->assertNotEmpty($file['body']['$id']);
$this->assertEquals(true, DateTime::isValid($file['body']['$createdAt']));
$this->assertEquals('logo.png', $file['body']['name']);
$this->assertEquals('image/png', $file['body']['mimeType']);
$this->assertEquals(47218, $file['body']['sizeOriginal']);
$this->assertTrue(md5_file(realpath(__DIR__ . '/../../../resources/logo.png')) != $file['body']['signature']); // should validate that the file is encrypted
}
/**
* @depends testCreateBucketFile
*/