Added new env tests
This commit is contained in:
parent
d48c103858
commit
9a5acbb0cb
5 changed files with 122 additions and 3 deletions
|
@ -7,7 +7,7 @@ use Tests\E2E\Scopes\ProjectCustom;
|
|||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\SideClient;
|
||||
|
||||
class FunctionsConsoleClientTest extends Scope
|
||||
class FunctionsCustomClientTest extends Scope
|
||||
{
|
||||
use FunctionsBase;
|
||||
use ProjectCustom;
|
||||
|
|
|
@ -8,7 +8,7 @@ use Tests\E2E\Scopes\ProjectCustom;
|
|||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\SideServer;
|
||||
|
||||
class FunctionsConsoleServerTest extends Scope
|
||||
class FunctionsCustomServerTest extends Scope
|
||||
{
|
||||
use FunctionsBase;
|
||||
use ProjectCustom;
|
||||
|
@ -339,7 +339,6 @@ class FunctionsConsoleServerTest extends Scope
|
|||
return array_merge($data, ['executionId' => $executionId]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @depends testCreateExecution
|
||||
*/
|
||||
|
@ -450,4 +449,98 @@ class FunctionsConsoleServerTest extends Scope
|
|||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testENVS():array
|
||||
{
|
||||
$envs = [
|
||||
[
|
||||
'name' => 'php-7.4',
|
||||
'code' => realpath(__DIR__ . '/../../../resources/functions/php-fx.tar.gz'),
|
||||
'command' => 'php function.php',
|
||||
],
|
||||
[
|
||||
'name' => 'python-3.8',
|
||||
'code' => realpath(__DIR__ . '/../../../resources/functions/python/code.tar.gz'),
|
||||
'command' => 'python main.py',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($envs as $key => $env) {
|
||||
$name = $env['name'] ?? '';
|
||||
$code = $env['code'] ?? '';
|
||||
$command = $env['command'] ?? '';
|
||||
|
||||
$function = $this->client->call(Client::METHOD_POST, '/functions', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'Test '.$name,
|
||||
'env' => $name,
|
||||
'vars' => [
|
||||
'APPWRITE_ENDPOINT' => 'http://'.gethostbyname(trim(`hostname`)).'/v1',
|
||||
'APPWRITE_PROJECT' => $this->getProject()['$id'],
|
||||
'APPWRITE_SECRET' => $this->getProject()['apiKey'],
|
||||
],
|
||||
'events' => [],
|
||||
'schedule' => '',
|
||||
'timeout' => 10,
|
||||
]);
|
||||
|
||||
$functionId = $function['body']['$id'] ?? '';
|
||||
|
||||
$this->assertEquals(201, $function['headers']['status-code']);
|
||||
|
||||
$tag = $this->client->call(Client::METHOD_POST, '/functions/'.$functionId.'/tags', array_merge([
|
||||
'content-type' => 'multipart/form-data',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'command' => $command,
|
||||
'code' => new CURLFile($code, 'application/x-gzip', basename($code)),
|
||||
]);
|
||||
|
||||
$tagId = $tag['body']['$id'] ?? '';
|
||||
$this->assertEquals(201, $tag['headers']['status-code']);
|
||||
|
||||
$tag = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/tag', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'tag' => $tagId,
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $tag['headers']['status-code']);
|
||||
|
||||
$execution = $this->client->call(Client::METHOD_POST, '/functions/'.$functionId.'/executions', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'async' => 1,
|
||||
]);
|
||||
|
||||
$executionId = $execution['body']['$id'] ?? '';
|
||||
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||
|
||||
sleep(15);
|
||||
|
||||
$executions = $this->client->call(Client::METHOD_GET, '/functions/'.$functionId.'/executions', array_merge([
|
||||
'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);
|
||||
$this->assertIsArray($executions['body']['executions']);
|
||||
$this->assertCount(1, $executions['body']['executions']);
|
||||
$this->assertEquals($executions['body']['executions'][0]['$id'], $executionId);
|
||||
$this->assertEquals($executions['body']['executions'][0]['trigger'], 'http');
|
||||
$this->assertEquals($executions['body']['executions'][0]['status'], 'completed');
|
||||
$this->assertEquals($executions['body']['executions'][0]['exitCode'], 0);
|
||||
}
|
||||
|
||||
return [
|
||||
'functionId' => $functionId,
|
||||
];
|
||||
}
|
||||
}
|
BIN
tests/resources/functions/python/code.tar.gz
Normal file
BIN
tests/resources/functions/python/code.tar.gz
Normal file
Binary file not shown.
25
tests/resources/functions/python/main.py
Normal file
25
tests/resources/functions/python/main.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
import json
|
||||
import os
|
||||
from appwrite.client import Client
|
||||
from appwrite.services.storage import Storage
|
||||
|
||||
#payload = json.loads(os.environ["APPWRITE_FUNCTION_EVENT_PAYLOAD"] or "{}")
|
||||
#fileID = payload["$id"] or os.environ["APPWRITE_FILE"]
|
||||
|
||||
# Setup appwrite client
|
||||
client = Client()
|
||||
client.set_endpoint(os.environ["APPWRITE_ENDPOINT"]) # PRIVATE IP OF YOUR APPWRITE CONTAINER
|
||||
client.set_project(os.environ["APPWRITE_PROJECT"]) # YOUR PROJECT ID
|
||||
client.set_key(os.environ["APPWRITE_SECRET"])
|
||||
|
||||
storage = Storage(client)
|
||||
#result = storage.get_file("")
|
||||
|
||||
print(os.environ["APPWRITE_FUNCTION_ID"])
|
||||
print(os.environ["APPWRITE_FUNCTION_NAME"])
|
||||
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"])
|
1
tests/resources/functions/python/requirements.txt
Normal file
1
tests/resources/functions/python/requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
appwrite
|
Loading…
Reference in a new issue