coolify/tests/Feature/DockerCommandsTest.php

34 lines
1.4 KiB
PHP
Raw Normal View History

2023-03-20 22:17:28 +01: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_*
$activity = coolifyProcess($areThereCoolifyTestContainers, $host);
ray($activity);
$containers = Output::containerList($activity->getExtraProperty('stdout'));
2023-03-20 22:17:28 +01:00
expect($containers)->toBeEmpty();
// start a container nginx -d --name = $containerName
$activity = coolifyProcess("docker run -d --name {$containerName} nginx", $host);
expect($activity->getExtraProperty('exitCode'))->toBe(0);
2023-03-20 22:17:28 +01:00
// docker ps name = $container
$activity = coolifyProcess($areThereCoolifyTestContainers, $host);
$containers = Output::containerList($activity->getExtraProperty('stdout'));
2023-03-20 22:17:28 +01:00
expect($containers->where('Names', $containerName)->count())->toBe(1);
// Stop testing containers
$activity = coolifyProcess("docker stop $(docker ps --filter='name={$coolifyNamePrefix}*' -q)", $host);
expect($activity->getExtraProperty('exitCode'))->toBe(0);
2023-03-20 22:17:28 +01:00
});