Improve tests

This commit is contained in:
Matej Bačo
2024-08-19 14:18:57 +00:00
parent 32191334c7
commit d87f47ee3c
4 changed files with 77 additions and 3 deletions
+1 -1
View File
@@ -262,7 +262,7 @@ class Builds extends Action
Console::execute('rm -rf ' . \escapeshellarg($tmpTemplateDirectory), '', $stdout, $stderr);
$build = $dbForProject->updateDocument('builds', $build->getId(), $build->setAttribute('source', $source));
$deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment->setAttribute('path', $source));
$deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment->setAttribute('path', $source)->setAttribute('size', $directorySize));
}
} elseif ($isNewBuild && $isVcsEnabled) {
// VCS and VCS+Temaplte
@@ -13,6 +13,7 @@ trait AccountBase
$email = uniqid() . 'user@localhost.test';
$password = 'password';
$name = 'User Name';
\var_dump($email);
/**
* Test for SUCCESS
@@ -730,7 +730,8 @@ class FunctionsCustomServerTest extends Scope
$largeTag = $this->client->call(Client::METHOD_POST, '/functions/' . $data['functionId'] . '/deployments', array_merge($headers, $this->getHeaders()), [
'entrypoint' => 'index.php',
'code' => $curlFile,
'activate' => true
'activate' => true,
'commands' => 'cp blue.mp4 copy.mp4 && ls -al' // +7MB buildSize
]);
$counter++;
$id = $largeTag['body']['$id'];
@@ -741,7 +742,23 @@ class FunctionsCustomServerTest extends Scope
$this->assertNotEmpty($largeTag['body']['$id']);
$this->assertEquals(true, (new DatetimeValidator())->isValid($largeTag['body']['$createdAt']));
$this->assertEquals('index.php', $largeTag['body']['entrypoint']);
$this->assertGreaterThan(10000, $largeTag['body']['size']);
$this->assertGreaterThan(1024 * 1024 * 5, $largeTag['body']['size']); // ~7MB video file
$this->assertLessThan(1024 * 1024 * 10, $largeTag['body']['size']); // ~7MB video file
$deploymentSize = $largeTag['body']['size'];
$deploymentId = $largeTag['body']['$id'];
$this->awaitDeploymentIsBuilt($data['functionId'], $deploymentId, true);
$response = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/deployments/' . $deploymentId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals($deploymentSize, $response['body']['size']);
$this->assertGreaterThan(1024 * 1024 * 10, $response['body']['buildSize']); // ~7MB video file + 10MB sample file
return $data;
}
@@ -790,6 +807,8 @@ class FunctionsCustomServerTest extends Scope
$this->assertEquals($function['body']['total'], 3);
$this->assertIsArray($function['body']['deployments']);
$this->assertCount(3, $function['body']['deployments']);
$this->assertArrayHasKey('size', $function['body']['deployments'][0]);
$this->assertArrayHasKey('buildSize', $function['body']['deployments'][0]);
/**
* Test search queries
@@ -995,6 +1014,58 @@ class FunctionsCustomServerTest extends Scope
$this->assertEquals($function['headers']['status-code'], 200);
$this->assertEquals(3, $function['body']['total']);
/**
* Ensure size output and size filters work exactly.
* Prevents buildSize being counted towards deployemtn size
*/
$response = $this->client->call(
Client::METHOD_GET,
'/functions/' . $data['functionId'] . '/deployments',
array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()),
[
Query::limit(1)->toString(),
]
);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertGreaterThanOrEqual(1, $response['body']['total']);
$this->assertNotEmpty($response['body']['deployments'][0]['$id']);
$this->assertNotEmpty($response['body']['deployments'][0]['size']);
$deploymentId = $function['body']['deployments'][0]['$id'];
$deploymentSize = $function['body']['deployments'][0]['size'];
$response = $this->client->call(
Client::METHOD_GET,
'/functions/' . $data['functionId'] . '/deployments',
array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()),
[
'queries' => [
Query::equal('size', [$deploymentSize])->toString(),
],
]
);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertGreaterThan(0, $response['body']['total']);
$found = false;
foreach ($response['body']['deployments'] as $deployment) {
if($deployment['$id'] === $deploymentId) {
$found = true;
$this->assertEquals($deploymentSize, $deployment['size']);
break;
}
}
$this->assertTrue($found);
return $data;
}
@@ -1015,6 +1086,8 @@ class FunctionsCustomServerTest extends Scope
$this->assertGreaterThan(0, $function['body']['buildTime']);
$this->assertNotEmpty($function['body']['status']);
$this->assertNotEmpty($function['body']['buildLogs']);
$this->assertArrayHasKey('size', $function['body']);
$this->assertArrayHasKey('buildSize', $function['body']);
/**
* Test for FAILURE