coolify/tests/Feature/DockerCustomCommandsTest.php

218 lines
6.3 KiB
PHP
Raw Normal View History

2024-02-09 12:38:17 +00:00
<?php
2025-04-23 11:22:01 +00:00
test('Hostname', function () {
$input = '--hostname=test';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'hostname' => 'test',
]);
});
test('HostnameWithoutEqualSign', function () {
$input = '--hostname test';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'hostname' => 'test',
]);
});
test('HostnameWithoutEqualSignAndHyphens', function () {
$input = '--hostname my-super-host';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'hostname' => 'my-super-host',
]);
});
test('HostnameWithHyphens', function () {
$input = '--hostname=my-super-host';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'hostname' => 'my-super-host',
]);
});
2024-02-14 08:21:25 +00:00
test('ConvertCapAdd', function () {
2025-04-23 11:22:01 +00:00
$input = '--cap-add=NET_ADMIN --cap-add=NET_RAW --cap-add SYS_ADMIN';
$output = convertDockerRunToCompose($input);
2024-02-09 12:38:17 +00:00
expect($output)->toBe([
'cap_add' => ['NET_ADMIN', 'NET_RAW', 'SYS_ADMIN'],
2024-08-21 18:32:02 +00:00
]);
2024-02-09 12:38:17 +00:00
});
2024-02-14 07:42:47 +00:00
2024-02-25 22:13:27 +00:00
test('ConvertIp', function () {
$input = '--cap-add=NET_ADMIN --cap-add=NET_RAW --cap-add SYS_ADMIN --ip 127.0.0.1 --ip 127.0.0.2';
$output = convertDockerRunToCompose($input);
2024-02-25 22:13:27 +00:00
expect($output)->toBe([
'cap_add' => ['NET_ADMIN', 'NET_RAW', 'SYS_ADMIN'],
2024-06-10 20:43:34 +00:00
'ip' => ['127.0.0.1', '127.0.0.2'],
2024-08-21 18:32:02 +00:00
]);
2024-02-25 22:13:27 +00:00
});
2024-02-14 08:21:25 +00:00
test('ConvertPrivilegedAndInit', function () {
2024-02-14 07:42:47 +00:00
$input = '---privileged --init';
$output = convertDockerRunToCompose($input);
2024-02-14 07:42:47 +00:00
expect($output)->toBe([
'privileged' => true,
'init' => true,
2024-08-21 18:32:02 +00:00
]);
2024-02-14 07:42:47 +00:00
});
2024-02-14 08:21:25 +00:00
test('ConvertUlimit', function () {
2024-02-14 07:42:47 +00:00
$input = '--ulimit nofile=262144:262144';
$output = convertDockerRunToCompose($input);
2024-02-14 07:42:47 +00:00
expect($output)->toBe([
'ulimits' => [
'nofile' => [
'soft' => '262144',
'hard' => '262144',
],
],
2024-08-21 18:32:02 +00:00
]);
2024-02-14 07:42:47 +00:00
});
2024-11-06 11:26:05 +00:00
test('ConvertGpusWithGpuId', function () {
$input = '--gpus "device=GPU-0000000000000000"';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'deploy' => [
'resources' => [
'reservations' => [
'devices' => [
[
'driver' => 'nvidia',
'capabilities' => ['gpu'],
'device_ids' => ['GPU-0000000000000000'],
],
],
],
],
],
]);
});
test('ConvertGpus', function () {
$input = '--gpus all';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
2024-11-06 11:26:05 +00:00
'deploy' => [
'resources' => [
'reservations' => [
'devices' => [
[
'driver' => 'nvidia',
'capabilities' => ['gpu'],
],
],
],
],
],
]);
});
test('ConvertGpusWithQuotes', function () {
2024-11-06 11:26:05 +00:00
$input = '--gpus "device=0,1"';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
2024-11-06 11:26:05 +00:00
'deploy' => [
'resources' => [
'reservations' => [
'devices' => [
[
'driver' => 'nvidia',
'capabilities' => ['gpu'],
'device_ids' => ['0', '1'],
],
],
],
],
],
]);
});
2025-11-03 13:44:06 +00:00
test('ConvertEntrypointSimple', function () {
$input = '--entrypoint /bin/sh';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => '/bin/sh',
]);
});
test('ConvertEntrypointWithEquals', function () {
$input = '--entrypoint=/bin/bash';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => '/bin/bash',
]);
});
test('ConvertEntrypointWithArguments', function () {
$input = '--entrypoint "sh -c npm install"';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => 'sh -c npm install',
]);
});
test('ConvertEntrypointWithSingleQuotes', function () {
$input = "--entrypoint 'memcached -m 256'";
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => 'memcached -m 256',
]);
});
test('ConvertEntrypointWithOtherOptions', function () {
$input = '--entrypoint /bin/bash --cap-add SYS_ADMIN --privileged';
$output = convertDockerRunToCompose($input);
expect($output)->toHaveKeys(['entrypoint', 'cap_add', 'privileged'])
->and($output['entrypoint'])->toBe('/bin/bash')
->and($output['cap_add'])->toBe(['SYS_ADMIN'])
->and($output['privileged'])->toBe(true);
});
test('ConvertEntrypointComplex', function () {
$input = '--entrypoint "sh -c \'npm install && npm start\'"';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => "sh -c 'npm install && npm start'",
]);
});
test('ConvertEntrypointWithEscapedDoubleQuotes', function () {
$input = '--entrypoint "python -c \"print(\'hi\')\""';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => "python -c \"print('hi')\"",
]);
});
test('ConvertEntrypointWithEscapedSingleQuotesInDoubleQuotes', function () {
$input = '--entrypoint "sh -c \"echo \'hello\'\""';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => "sh -c \"echo 'hello'\"",
]);
});
test('ConvertEntrypointSingleQuotedWithDoubleQuotesInside', function () {
$input = '--entrypoint \'python -c "print(\"hi\")"\'';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => 'python -c "print(\"hi\")"',
]);
});
2026-03-01 17:49:40 +00:00
test('ConvertIp6', function () {
$input = '--ip6 2001:db8::1';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'ip6' => ['2001:db8::1'],
]);
});
test('ConvertIpAndIp6Together', function () {
$input = '--ip 172.20.0.5 --ip6 2001:db8::1';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'ip' => ['172.20.0.5'],
'ip6' => ['2001:db8::1'],
]);
});