mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge branch '1.8.x' into feat-health-module
This commit is contained in:
@@ -2334,7 +2334,8 @@ trait Base
|
||||
buckets {
|
||||
_id
|
||||
name
|
||||
enabled
|
||||
enabled,
|
||||
totalSize
|
||||
}
|
||||
}
|
||||
}';
|
||||
@@ -2344,6 +2345,7 @@ trait Base
|
||||
_id
|
||||
name
|
||||
enabled
|
||||
totalSize
|
||||
}
|
||||
}';
|
||||
case self::UPDATE_BUCKET:
|
||||
|
||||
@@ -105,12 +105,24 @@ class StorageServerTest extends Scope
|
||||
$buckets = $buckets['body']['data']['storageListBuckets'];
|
||||
$this->assertIsArray($buckets);
|
||||
|
||||
if (!empty($buckets['buckets'])) {
|
||||
foreach ($buckets['buckets'] as $bucket) {
|
||||
$this->assertArrayHasKey('totalSize', $bucket);
|
||||
$this->assertIsInt($bucket['totalSize']);
|
||||
|
||||
/* always 0 because the stats worker runs hourly! */
|
||||
$this->assertGreaterThanOrEqual(0, $bucket['totalSize']);
|
||||
}
|
||||
}
|
||||
|
||||
return $buckets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateBucket
|
||||
* @depends testCreateFile
|
||||
* @param $bucket
|
||||
* @param $file
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
@@ -134,6 +146,7 @@ class StorageServerTest extends Scope
|
||||
$this->assertArrayNotHasKey('errors', $bucket['body']);
|
||||
$bucket = $bucket['body']['data']['storageGetBucket'];
|
||||
$this->assertEquals('Actors', $bucket['name']);
|
||||
$this->assertArrayHasKey('totalSize', $bucket);
|
||||
|
||||
return $bucket;
|
||||
}
|
||||
|
||||
@@ -951,4 +951,69 @@ trait StorageBase
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testBucketTotalSize(): 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 Size',
|
||||
'permissions' => [
|
||||
Permission::read(Role::any()),
|
||||
Permission::create(Role::any()),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $bucket['headers']['status-code']);
|
||||
$bucketId = $bucket['body']['$id'];
|
||||
|
||||
// bucket should have totalSize = 0 (no files)
|
||||
$emptyBucket = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId, [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $emptyBucket['headers']['status-code']);
|
||||
$this->assertArrayHasKey('totalSize', $emptyBucket['body']);
|
||||
$this->assertEquals(0, $emptyBucket['body']['totalSize']);
|
||||
|
||||
// upload first file
|
||||
$file1 = $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'),
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $file1['headers']['status-code']);
|
||||
|
||||
// upload second file
|
||||
$file2 = $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/image.webp'), 'image/webp', 'image.webp'),
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $file2['headers']['status-code']);
|
||||
|
||||
$bucket = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId, [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $bucket['headers']['status-code']);
|
||||
$this->assertArrayHasKey('totalSize', $bucket['body']);
|
||||
$this->assertIsInt($bucket['body']['totalSize']);
|
||||
|
||||
/* will always be 0 in tests because the worker runs hourly! */
|
||||
$this->assertGreaterThanOrEqual(0, $bucket['body']['totalSize']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,14 @@ class StorageCustomServerTest extends Scope
|
||||
$this->assertEquals($id, $response['body']['buckets'][0]['$id']);
|
||||
$this->assertEquals('Test Bucket', $response['body']['buckets'][0]['name']);
|
||||
|
||||
foreach ($response['body']['buckets'] as $bucket) {
|
||||
$this->assertArrayHasKey('totalSize', $bucket);
|
||||
$this->assertIsInt($bucket['totalSize']);
|
||||
|
||||
/* always 0 because the stats worker runs hourly! */
|
||||
$this->assertGreaterThanOrEqual(0, $bucket['totalSize']);
|
||||
}
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/storage/buckets', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
@@ -186,6 +194,7 @@ class StorageCustomServerTest extends Scope
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertEquals($id, $response['body']['$id']);
|
||||
$this->assertEquals('Test Bucket', $response['body']['name']);
|
||||
$this->assertArrayHasKey('totalSize', $response['body']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
|
||||
Reference in New Issue
Block a user