From ca36c12414954865a04f5ecefa5fe82a05c58a7d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 3 Feb 2025 18:45:53 +1300 Subject: [PATCH] Add storage test case --- tests/e2e/General/UsageTest.php | 73 +++++---------------------------- 1 file changed, 11 insertions(+), 62 deletions(-) diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index 3bf727a45e..8d2b7fee6f 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -65,6 +65,12 @@ class UsageTest extends Scope return $date->format(self::$formatTz); } + public static function getExpectedStorage(): array { + return [ + 'databases' => 1_261_568, + ]; + } + public function testPrepareUsersStats(): array { $usersTotal = 0; @@ -518,6 +524,7 @@ class UsageTest extends Scope 'databasesTotal' => $databasesTotal, 'collectionsTotal' => $collectionsTotal, 'documentsTotal' => $documentsTotal, + 'storageTotal' => self::getExpectedStorage(), ]); } @@ -531,6 +538,7 @@ class UsageTest extends Scope $databasesTotal = $data['databasesTotal']; $collectionsTotal = $data['collectionsTotal']; $documentsTotal = $data['documentsTotal']; + $databaseStorageTotal = $data['storageTotal']['databases']; sleep(self::WAIT); @@ -552,6 +560,7 @@ class UsageTest extends Scope $this->validateDates($response['body']['requests']); $this->assertEquals($databasesTotal, $response['body']['databasesTotal']); $this->assertEquals($documentsTotal, $response['body']['documentsTotal']); + $this->assertEquals($databaseStorageTotal, $response['body']['databasesStorageTotal']); $response = $this->client->call( Client::METHOD_GET, @@ -565,6 +574,7 @@ class UsageTest extends Scope $this->validateDates($response['body']['collections']); $this->assertEquals($documentsTotal, $response['body']['documents'][array_key_last($response['body']['documents'])]['value']); $this->validateDates($response['body']['documents']); + $this->assertEquals($databaseStorageTotal, $response['body']['storageTotal']); $response = $this->client->call( Client::METHOD_GET, @@ -574,9 +584,9 @@ class UsageTest extends Scope $this->assertEquals($collectionsTotal, $response['body']['collections'][array_key_last($response['body']['collections'])]['value']); $this->validateDates($response['body']['collections']); - $this->assertEquals($documentsTotal, $response['body']['documents'][array_key_last($response['body']['documents'])]['value']); $this->validateDates($response['body']['documents']); + $this->assertEquals($databaseStorageTotal, $response['body']['storageTotal']); $response = $this->client->call( Client::METHOD_GET, @@ -590,67 +600,6 @@ class UsageTest extends Scope return $data; } - public function testDatabaseStoragePrepare(): array - { - $response = $this->client->call( - Client::METHOD_POST, - '/databases', - array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'] - ], $this->getHeaders()), - [ - 'databaseId' => 'unique()', - 'name' => 'dbStorageStats', - ] - ); - - $this->assertNotEmpty($response['body']['$id']); - $databaseId = $response['body']['$id']; - - $response = $this->client->call( - Client::METHOD_POST, - '/databases/' . $databaseId . '/collections', - array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'] - ], $this->getHeaders()), - [ - 'collectionId' => 'unique()', - 'name' => 'collectionStorageStats', - 'documentSecurity' => false, - 'permissions' => [ - Permission::read(Role::any()), - Permission::create(Role::any()), - Permission::update(Role::any()), - Permission::delete(Role::any()), - ], - ] - ); - - $this->assertNotEmpty($response['body']['$id']); - $collectionId = $response['body']['$id']; - - $response = $this->client->call( - Client::METHOD_POST, - '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes' . '/string', - array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'] - ], $this->getHeaders()), - [ - 'key' => 'data', - 'size' => 100000, - 'required' => true, - ] - ); - - return [ - 'databaseId' => $databaseId, - 'collectionId' => $collectionId, - ]; - } - /** @depends testDatabaseStats */ public function testPrepareFunctionsStats(array $data): array {