1
0
Fork 0
mirror of synced 2024-05-29 17:09:48 +12:00

tests: remove cloud function env tests

This commit is contained in:
Torsten Dittmann 2021-04-20 14:35:07 +02:00
parent 36665e19b1
commit 56c2c039b2

View file

@ -451,235 +451,233 @@ class FunctionsCustomServerTest extends Scope
return $data;
}
public function testENVS():array
{
// public function testENVS():array
// {
$functionsDir = realpath(__DIR__ . '/../../../resources/functions');
$envs = require('app/config/environments.php');
// $functionsDir = realpath(__DIR__ . '/../../../resources/functions');
// $envs = require('app/config/environments.php');
/**
* Command for rebuilding code packages:
* bash tests/resources/functions/package-*.sh
*/
$functions = [
// 'node-14.5' => [
// 'code' => $functionsDir.'/node.tar.gz',
// 'command' => 'node index.js',
// 'timeout' => 15,
// ],
'node-15.5' => [
'code' => $functionsDir.'/node.tar.gz',
'command' => 'node index.js',
'timeout' => 15,
],
// 'php-7.4' => [
// 'code' => $functionsDir.'/php.tar.gz',
// 'command' => 'php index.php',
// 'timeout' => 15,
// ],
'php-8.0' => [
'code' => $functionsDir.'/php.tar.gz',
'command' => 'php index.php',
'timeout' => 15,
],
// 'ruby-2.7' => [
// 'code' => $functionsDir.'/ruby.tar.gz',
// 'command' => 'ruby app.rb',
// 'timeout' => 15,
// ],
'ruby-3.0' => [
'code' => $functionsDir.'/ruby.tar.gz',
'command' => 'ruby app.rb',
'timeout' => 15,
],
// 'python-3.8' => [
// 'code' => $functionsDir.'/python.tar.gz',
// 'command' => 'python main.py',
// 'timeout' => 15,
// ],
'python-3.9' => [
'code' => $functionsDir.'/python.tar.gz',
'command' => 'python main.py',
'timeout' => 15,
],
// 'deno-1.2' => [
// 'code' => $functionsDir.'/deno.tar.gz',
// 'command' => 'deno run --allow-env index.ts',
// 'timeout' => 15,
// ],
// 'deno-1.5' => [
// 'code' => $functionsDir.'/deno.tar.gz',
// 'command' => 'deno run --allow-env index.ts',
// 'timeout' => 15,
// ],
// 'deno-1.6' => [
// 'code' => $functionsDir.'/deno.tar.gz',
// 'command' => 'deno run --allow-env index.ts',
// 'timeout' => 15,
// ],
'deno-1.8' => [
'code' => $functionsDir.'/deno.tar.gz',
'command' => 'deno run --allow-env index.ts',
'timeout' => 15,
],
// 'dart-2.10' => [
// 'code' => $functionsDir.'/dart.tar.gz',
// 'command' => 'dart main.dart',
// 'timeout' => 15,
// ],
'dart-2.12' => [
'code' => $functionsDir.'/dart.tar.gz',
'command' => 'dart main.dart',
'timeout' => 15,
],
// 'dotnet-3.1' => [
// 'code' => $functionsDir.'/dotnet-3.1.tar.gz',
// 'command' => 'dotnet dotnet.dll',
// 'timeout' => 15,
// ],
'dotnet-5.0' => [
'code' => $functionsDir.'/dotnet-5.0.tar.gz',
'command' => 'dotnet dotnet.dll',
'timeout' => 15,
]
];
// /**
// * Command for rebuilding code packages:
// * bash tests/resources/functions/package-*.sh
// */
// $functions = [
// // 'node-14.5' => [
// // 'code' => $functionsDir.'/node.tar.gz',
// // 'command' => 'node index.js',
// // 'timeout' => 15,
// // ],
// 'node-15.5' => [
// 'code' => $functionsDir.'/node.tar.gz',
// 'command' => 'node index.js',
// 'timeout' => 15,
// ],
// // 'php-7.4' => [
// // 'code' => $functionsDir.'/php.tar.gz',
// // 'command' => 'php index.php',
// // 'timeout' => 15,
// // ],
// 'php-8.0' => [
// 'code' => $functionsDir.'/php.tar.gz',
// 'command' => 'php index.php',
// 'timeout' => 15,
// ],
// // 'ruby-2.7' => [
// // 'code' => $functionsDir.'/ruby.tar.gz',
// // 'command' => 'ruby app.rb',
// // 'timeout' => 15,
// // ],
// 'ruby-3.0' => [
// 'code' => $functionsDir.'/ruby.tar.gz',
// 'command' => 'ruby app.rb',
// 'timeout' => 15,
// ],
// // 'python-3.8' => [
// // 'code' => $functionsDir.'/python.tar.gz',
// // 'command' => 'python main.py',
// // 'timeout' => 15,
// // ],
// 'python-3.9' => [
// 'code' => $functionsDir.'/python.tar.gz',
// 'command' => 'python main.py',
// 'timeout' => 15,
// ],
// // 'deno-1.2' => [
// // 'code' => $functionsDir.'/deno.tar.gz',
// // 'command' => 'deno run --allow-env index.ts',
// // 'timeout' => 15,
// // ],
// // 'deno-1.5' => [
// // 'code' => $functionsDir.'/deno.tar.gz',
// // 'command' => 'deno run --allow-env index.ts',
// // 'timeout' => 15,
// // ],
// // 'deno-1.6' => [
// // 'code' => $functionsDir.'/deno.tar.gz',
// // 'command' => 'deno run --allow-env index.ts',
// // 'timeout' => 15,
// // ],
// 'deno-1.8' => [
// 'code' => $functionsDir.'/deno.tar.gz',
// 'command' => 'deno run --allow-env index.ts',
// 'timeout' => 15,
// ],
// // 'dart-2.10' => [
// // 'code' => $functionsDir.'/dart.tar.gz',
// // 'command' => 'dart main.dart',
// // 'timeout' => 15,
// // ],
// 'dart-2.12' => [
// 'code' => $functionsDir.'/dart.tar.gz',
// 'command' => 'dart main.dart',
// 'timeout' => 15,
// ],
// // 'dotnet-3.1' => [
// // 'code' => $functionsDir.'/dotnet-3.1.tar.gz',
// // 'command' => 'dotnet dotnet.dll',
// // 'timeout' => 15,
// // ],
// 'dotnet-5.0' => [
// 'code' => $functionsDir.'/dotnet-5.0.tar.gz',
// 'command' => 'dotnet dotnet.dll',
// 'timeout' => 15,
// ]
// ];
foreach ($envs as $key => $env) {
if (array_key_exists($key, $functions)) {
$envs[$key] = array_merge($env, $functions[$key]);
} else {
unset($envs[$key]);
}
}
// foreach ($envs as $key => $env) {
// if (array_key_exists($key, $functions)) {
// $envs[$key] = array_merge($env, $functions[$key]);
// } else {
// unset($envs[$key]);
// }
// }
sleep(count($envs) * 20);
fwrite(STDERR, ".");
// sleep(count($envs) * 20);
// fwrite(STDERR, ".");
/**
* Test for SUCCESS
*/
$file = $this->client->call(Client::METHOD_POST, '/storage/files', array_merge([
'content-type' => 'multipart/form-data',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'),
'read' => ['*'],
'write' => ['*'],
'folderId' => 'xyz',
]);
// /**
// * Test for SUCCESS
// */
// $file = $this->client->call(Client::METHOD_POST, '/storage/files', array_merge([
// 'content-type' => 'multipart/form-data',
// 'x-appwrite-project' => $this->getProject()['$id'],
// ], $this->getHeaders()), [
// 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'),
// 'read' => ['*'],
// 'write' => ['*'],
// 'folderId' => 'xyz',
// ]);
$this->assertEquals($file['headers']['status-code'], 201);
$this->assertNotEmpty($file['body']['$id']);
// $this->assertEquals($file['headers']['status-code'], 201);
// $this->assertNotEmpty($file['body']['$id']);
$fileId = $file['body']['$id'] ?? '';
// $fileId = $file['body']['$id'] ?? '';
foreach ($envs as $key => $env) {
$name = $key ?? '';
$language = $env['name'] ?? '';
$version = $env['version'] ?? '';
$code = $env['code'] ?? '';
$command = $env['command'] ?? '';
$timeout = $env['timeout'] ?? 15;
// foreach ($envs as $key => $env) {
// $name = $key ?? '';
// $language = $env['name'] ?? '';
// $version = $env['version'] ?? '';
// $code = $env['code'] ?? '';
// $command = $env['command'] ?? '';
// $timeout = $env['timeout'] ?? 15;
$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://appwrite.test/v1',
'APPWRITE_PROJECT' => $this->getProject()['$id'],
'APPWRITE_SECRET' => $this->getProject()['apiKey'],
'APPWRITE_FILEID' => $fileId,
],
'events' => [],
'schedule' => '',
'timeout' => $timeout,
]);
// $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://appwrite.test/v1',
// 'APPWRITE_PROJECT' => $this->getProject()['$id'],
// 'APPWRITE_SECRET' => $this->getProject()['apiKey'],
// 'APPWRITE_FILEID' => $fileId,
// ],
// 'events' => [],
// 'schedule' => '',
// 'timeout' => $timeout,
// ]);
// var_dump('http://'.gethostbyname(trim(`hostname`)).'/v1');
// // var_dump('http://'.gethostbyname(trim(`hostname`)).'/v1');
$functionId = $function['body']['$id'] ?? '';
// $functionId = $function['body']['$id'] ?? '';
$this->assertEquals(201, $function['headers']['status-code']);
// $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)),
]);
// $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']);
// $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,
]);
// $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']);
// $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,
]);
// $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']);
// $executionId = $execution['body']['$id'] ?? '';
// $this->assertEquals(201, $execution['headers']['status-code']);
sleep(10);
// sleep(10);
$executions = $this->client->call(Client::METHOD_GET, '/functions/'.$functionId.'/executions', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
// $executions = $this->client->call(Client::METHOD_GET, '/functions/'.$functionId.'/executions', array_merge([
// 'content-type' => 'application/json',
// 'x-appwrite-project' => $this->getProject()['$id'],
// ], $this->getHeaders()));
if($executions['body']['executions'][0]['status'] !== 'completed') {
var_dump($env);
var_dump($executions['body']['executions'][0]);
$stdout = '';
$stderr = '';
Console::execute('docker logs appwrite-worker-functions', '', $stdout, $stderr);
var_dump($stdout);
var_dump($stderr);
}
// if($executions['body']['executions'][0]['status'] !== 'completed') {
// var_dump($env);
// var_dump($executions['body']['executions'][0]);
// $stdout = '';
// $stderr = '';
// Console::execute('docker logs appwrite-worker-functions', '', $stdout, $stderr);
// var_dump($stdout);
// var_dump($stderr);
// }
$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);
// $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);
$stdout = explode("\n", $executions['body']['executions'][0]['stdout']);
// $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);
// $this->assertEquals($stdout[6], $fileId);
fwrite(STDERR, ".");
}
// $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);
// // $this->assertEquals($stdout[6], $fileId);
// fwrite(STDERR, ".");
// }
// return [
// 'functionId' => $functionId,
// ];
// }
return [
'functionId' => $functionId,
];
}
/**
* @depends testENVS
*/
public function testTimeout()
{
$name = 'php-8.0';