2023-03-20 21:17:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Tests\Support\Output;
|
|
|
|
|
|
|
|
it('starts a docker container correctly', function () {
|
|
|
|
|
|
|
|
$coolifyNamePrefix = 'coolify_test_';
|
|
|
|
$format = '{"ID":"{{ .ID }}", "Image": "{{ .Image }}", "Names":"{{ .Names }}"}';
|
|
|
|
$areThereCoolifyTestContainers = "docker ps --filter=\"name={$coolifyNamePrefix}*\" --format '{$format}' ";
|
|
|
|
|
|
|
|
// Generate a known name
|
|
|
|
$containerName = 'coolify_test_' . now()->format('Ymd_his');
|
|
|
|
$host = 'testing-host';
|
|
|
|
|
|
|
|
// Assert there's no containers start with coolify_test_*
|
2023-03-21 09:31:16 +00:00
|
|
|
$activity = remoteProcess($areThereCoolifyTestContainers, $host);
|
2023-03-21 09:08:36 +00:00
|
|
|
$containers = Output::containerList($activity->getExtraProperty('stdout'));
|
2023-03-20 21:17:28 +00:00
|
|
|
expect($containers)->toBeEmpty();
|
|
|
|
|
|
|
|
// start a container nginx -d --name = $containerName
|
2023-03-21 10:32:38 +00:00
|
|
|
$activity = remoteProcess("docker run -d --rm --name {$containerName} nginx", $host);
|
2023-03-21 09:08:36 +00:00
|
|
|
expect($activity->getExtraProperty('exitCode'))->toBe(0);
|
2023-03-20 21:17:28 +00:00
|
|
|
|
|
|
|
// docker ps name = $container
|
2023-03-21 09:31:16 +00:00
|
|
|
$activity = remoteProcess($areThereCoolifyTestContainers, $host);
|
2023-03-21 09:08:36 +00:00
|
|
|
$containers = Output::containerList($activity->getExtraProperty('stdout'));
|
2023-03-20 21:17:28 +00:00
|
|
|
expect($containers->where('Names', $containerName)->count())->toBe(1);
|
|
|
|
|
|
|
|
// Stop testing containers
|
2023-03-21 09:31:16 +00:00
|
|
|
$activity = remoteProcess("docker stop $(docker ps --filter='name={$coolifyNamePrefix}*' -q)", $host);
|
2023-03-21 09:08:36 +00:00
|
|
|
expect($activity->getExtraProperty('exitCode'))->toBe(0);
|
2023-03-20 21:17:28 +00:00
|
|
|
});
|