1
0
Fork 0
mirror of synced 2024-06-26 10:10:57 +12:00

Added a new Python FX test

This commit is contained in:
Eldad Fux 2020-12-09 23:26:13 +02:00
parent a6464ed8b9
commit c8bdf46a13
6 changed files with 43 additions and 10 deletions

View file

@ -7,6 +7,7 @@ use Tests\E2E\Client;
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\SideServer;
use Utopia\CLI\Console;
class FunctionsCustomServerTest extends Scope
{
@ -452,20 +453,32 @@ class FunctionsCustomServerTest extends Scope
public function testENVS():array
{
$functions = realpath(__DIR__ . '/../../../resources/functions');
/**
* Command for rebuilding code packages:
* bash tests/resources/functions/package.sh
*/
$envs = [
//[
// 'name' => 'php-7.4',
// 'code' => $functions.'/php-fx.tar.gz',
// 'command' => 'php function.php',
//],
[
'name' => 'php-7.4',
'code' => realpath(__DIR__ . '/../../../resources/functions/php-fx.tar.gz'),
'command' => 'php function.php',
],
[
'language' => 'Python',
'version' => '3.8',
'name' => 'python-3.8',
'code' => realpath(__DIR__ . '/../../../resources/functions/python/code.tar.gz'),
'code' => $functions.'/python.tar.gz',
'command' => 'python main.py',
],
];
foreach ($envs as $key => $env) {
$language = $env['language'] ?? '';
$version = $env['version'] ?? '';
$name = $env['name'] ?? '';
$code = $env['code'] ?? '';
$command = $env['command'] ?? '';
@ -526,8 +539,6 @@ class FunctionsCustomServerTest extends Scope
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
var_dump($executions['body']['executions'][0]);
$this->assertEquals($executions['headers']['status-code'], 200);
$this->assertEquals($executions['body']['sum'], 1);
@ -537,6 +548,15 @@ class FunctionsCustomServerTest extends Scope
$this->assertEquals($executions['body']['executions'][0]['trigger'], 'http');
$this->assertEquals($executions['body']['executions'][0]['status'], 'completed');
$this->assertEquals($executions['body']['executions'][0]['exitCode'], 0);
$stdout = explode("\n", $executions['body']['executions'][0]['stdout']);
$this->assertEquals($stdout[0], $functionId);
$this->assertEquals($stdout[1], 'Test '.$name);
$this->assertEquals($stdout[2], $tagId);
$this->assertEquals($stdout[3], 'http');
$this->assertEquals($stdout[4], $language);
$this->assertEquals($stdout[5], $version);
}
return [

View file

@ -0,0 +1,13 @@
echo 'Python Packaging'
cp -r $(pwd)/tests/resources/functions/python $(pwd)/tests/resources/functions/packages/python
docker run --rm -v $(pwd)/tests/resources/functions/packages/python:/app -w /app appwrite/env-python-3.8:1.0.0 ls -ll .
docker run --rm -v $(pwd)/tests/resources/functions/packages/python:/app -w /app --env PIP_TARGET=./.appwrite appwrite/env-python-3.8:1.0.0 pip install -r ./requirements.txt --upgrade --ignore-installed
docker run --rm -v $(pwd)/tests/resources/functions/packages/python:/app -w /app appwrite/env-python-3.8:1.0.0 tar -zcvf code.tar.gz .
mv $(pwd)/tests/resources/functions/packages/python/code.tar.gz $(pwd)/tests/resources/functions/python.tar.gz
rm -r $(pwd)/tests/resources/functions/packages/python

Binary file not shown.

View file

@ -21,5 +21,5 @@ print(os.environ["APPWRITE_FUNCTION_TAG"])
print(os.environ["APPWRITE_FUNCTION_TRIGGER"])
print(os.environ["APPWRITE_FUNCTION_ENV_NAME"])
print(os.environ["APPWRITE_FUNCTION_ENV_VERSION"])
#print(os.environ["APPWRITE_FUNCTION_EVENT"])
#print(os.environ["APPWRITE_FUNCTION_EVENT_PAYLOAD"])
print(os.environ["APPWRITE_FUNCTION_EVENT"])
print(os.environ["APPWRITE_FUNCTION_EVENT_PAYLOAD"])