Cleans up tests.

This commit is contained in:
Joao Patricio 2023-03-31 17:54:55 +01:00
parent cd31ec8db1
commit a642cc2470
3 changed files with 9 additions and 19 deletions

View File

@ -31,7 +31,7 @@ class RunRemoteProcess
/**
* Create a new job instance.
*/
public function __construct(Activity $activity, bool $hideFromOutput)
public function __construct(Activity $activity, bool $hideFromOutput = false)
{
if ($activity->getExtraProperty('type') !== ActivityTypes::REMOTE_PROCESS->value && $activity->getExtraProperty('type') !== ActivityTypes::DEPLOYMENT->value) {

View File

@ -23,7 +23,9 @@ function remoteProcess(
?string $deployment_uuid = null,
?Model $model = null,
): Activity {
$command_string = implode("\n", $command);
// @TODO: Check if the user has access to this server
// checkTeam($server->team_id);
@ -31,7 +33,6 @@ function remoteProcess(
return resolve(DispatchRemoteProcess::class, [
'remoteProcessArgs' => new RemoteProcessArgs(
model: $model,
server_ip: $server->ip,
private_key_location: $private_key_location,
deployment_uuid: $deployment_uuid,
@ -41,6 +42,7 @@ function remoteProcess(
port: $server->port,
user: $server->user,
type: $deployment_uuid ? ActivityTypes::DEPLOYMENT->value : ActivityTypes::REMOTE_PROCESS->value,
model: $model,
),
])();
}

View File

@ -16,6 +16,7 @@
it('starts a docker container correctly', function () {
test()->actingAs(User::factory([
'uuid' => Str::uuid(),
'email' => Str::uuid().'@example.com',
@ -31,22 +32,9 @@
$containerName = 'coolify_test_' . now()->format('Ymd_his');
$host = Server::where('name', 'testing-local-docker-container')->first();
// Stop testing containers
$activity = remoteProcess([
"docker stop $(docker ps --filter='name={$coolifyNamePrefix}*' -aq)",
"docker rm $(docker ps --filter='name={$coolifyNamePrefix}*' -aq)",
], $host);
throw_if(
$activity->getExtraProperty('exitCode') !== 0,
new RuntimeException($activity->description),
);
expect($activity->getExtraProperty('exitCode'))->toBe(0);
// Assert there's no containers start with coolify_test_*
$activity = remoteProcess([$areThereCoolifyTestContainers], $host);
$containers = formatDockerCmdOutputToJson($activity->getExtraProperty('stdout'));
$containers = formatDockerCmdOutputToJson($activity->description);
expect($containers)->toBeEmpty();
// start a container nginx -d --name = $containerName
@ -55,13 +43,13 @@
// docker ps name = $container
$activity = remoteProcess([$areThereCoolifyTestContainers], $host);
$containers = formatDockerCmdOutputToJson($activity->getExtraProperty('stdout'));
$containers = formatDockerCmdOutputToJson($activity->description);
expect($containers->where('Names', $containerName)->count())->toBe(1);
// Stop testing containers
$activity = remoteProcess([
"docker stop $(docker ps --filter='name={$coolifyNamePrefix}*' -aq)",
"docker rm $(docker ps --filter='name={$coolifyNamePrefix}*' -aq)",
"docker ps --filter='name={$coolifyNamePrefix}*' -aq && " .
"docker rm -f $(docker ps --filter='name={$coolifyNamePrefix}*' -aq)"
], $host);
expect($activity->getExtraProperty('exitCode'))->toBe(0);
});