mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
test: remove tests that do not exercise app code
Remove tests that copy app logic into the test, grep PHP source as text, only check literals, constants, class_exists or PHP built-ins, duplicate other tests, or are always skipped. Keep source checks that guard security and authorization rules. Rename a duplicate Pest helper so the full suite loads, drop the missing v5/Browser path, and remove the CLAUDE.md symlink in favor of AGENTS.md. Correct AGENTS.md: Dusk is not installed and the upgrade script is scripts/upgrade.sh.
This commit is contained in:
@@ -14,127 +14,6 @@
|
||||
* - Both flags are injected in a single str_replace operation
|
||||
* - Build arguments are appended when not using build secrets
|
||||
*/
|
||||
it('injects --env-file flag into custom build command', function () {
|
||||
$customCommand = 'docker compose -f ./docker-compose.yaml build';
|
||||
|
||||
// Simulate the injection logic from ApplicationDeploymentJob
|
||||
if (! str_contains($customCommand, '--env-file')) {
|
||||
$customCommand = str_replace(
|
||||
'docker compose',
|
||||
'docker compose --env-file /artifacts/build-time.env',
|
||||
$customCommand
|
||||
);
|
||||
}
|
||||
|
||||
expect($customCommand)->toBe('docker compose --env-file /artifacts/build-time.env -f ./docker-compose.yaml build');
|
||||
expect($customCommand)->toContain('--env-file /artifacts/build-time.env');
|
||||
});
|
||||
|
||||
it('does not duplicate --env-file flag when already present', function () {
|
||||
$customCommand = 'docker compose --env-file /custom/.env -f ./docker-compose.yaml build';
|
||||
|
||||
// Simulate the injection logic from ApplicationDeploymentJob
|
||||
if (! str_contains($customCommand, '--env-file')) {
|
||||
$customCommand = str_replace(
|
||||
'docker compose',
|
||||
'docker compose --env-file /artifacts/build-time.env',
|
||||
$customCommand
|
||||
);
|
||||
}
|
||||
|
||||
expect($customCommand)->toBe('docker compose --env-file /custom/.env -f ./docker-compose.yaml build');
|
||||
expect(substr_count($customCommand, '--env-file'))->toBe(1);
|
||||
});
|
||||
|
||||
it('preserves custom build command structure with env-file injection', function () {
|
||||
$customCommand = 'docker compose -f ./custom/path/docker-compose.prod.yaml build --no-cache';
|
||||
|
||||
// Simulate the injection logic from ApplicationDeploymentJob
|
||||
if (! str_contains($customCommand, '--env-file')) {
|
||||
$customCommand = str_replace(
|
||||
'docker compose',
|
||||
'docker compose --env-file /artifacts/build-time.env',
|
||||
$customCommand
|
||||
);
|
||||
}
|
||||
|
||||
expect($customCommand)->toBe('docker compose --env-file /artifacts/build-time.env -f ./custom/path/docker-compose.prod.yaml build --no-cache');
|
||||
expect($customCommand)->toContain('--env-file /artifacts/build-time.env');
|
||||
expect($customCommand)->toContain('-f ./custom/path/docker-compose.prod.yaml');
|
||||
expect($customCommand)->toContain('build --no-cache');
|
||||
});
|
||||
|
||||
it('handles multiple docker compose commands in custom build command', function () {
|
||||
// Edge case: Only the first 'docker compose' should get the env-file flag
|
||||
$customCommand = 'docker compose -f ./docker-compose.yaml build';
|
||||
|
||||
// Simulate the injection logic from ApplicationDeploymentJob
|
||||
if (! str_contains($customCommand, '--env-file')) {
|
||||
$customCommand = str_replace(
|
||||
'docker compose',
|
||||
'docker compose --env-file /artifacts/build-time.env',
|
||||
$customCommand
|
||||
);
|
||||
}
|
||||
|
||||
// Note: str_replace replaces ALL occurrences, which is acceptable in this case
|
||||
// since you typically only have one 'docker compose' command
|
||||
expect($customCommand)->toContain('docker compose --env-file /artifacts/build-time.env');
|
||||
});
|
||||
|
||||
it('verifies build args would be appended correctly', function () {
|
||||
$customCommand = 'docker compose --env-file /artifacts/build-time.env -f ./docker-compose.yaml build';
|
||||
$buildArgs = collect([
|
||||
'--build-arg NODE_ENV=production',
|
||||
'--build-arg API_URL=https://api.example.com',
|
||||
]);
|
||||
|
||||
// Simulate build args appending logic
|
||||
$buildArgsString = $buildArgs->implode(' ');
|
||||
$buildArgsString = str_replace("'", "'\\''", $buildArgsString);
|
||||
$customCommand .= " {$buildArgsString}";
|
||||
|
||||
expect($customCommand)->toContain('--build-arg NODE_ENV=production');
|
||||
expect($customCommand)->toContain('--build-arg API_URL=https://api.example.com');
|
||||
expect($customCommand)->toBe(
|
||||
'docker compose --env-file /artifacts/build-time.env -f ./docker-compose.yaml build --build-arg NODE_ENV=production --build-arg API_URL=https://api.example.com'
|
||||
);
|
||||
});
|
||||
|
||||
it('properly escapes single quotes in build args', function () {
|
||||
$buildArg = "--build-arg MESSAGE='Hello World'";
|
||||
|
||||
// Simulate the escaping logic from ApplicationDeploymentJob
|
||||
$escapedBuildArg = str_replace("'", "'\\''", $buildArg);
|
||||
|
||||
expect($escapedBuildArg)->toBe("--build-arg MESSAGE='\\''Hello World'\\''");
|
||||
});
|
||||
|
||||
it('handles DOCKER_BUILDKIT prefix with env-file injection', function () {
|
||||
$customCommand = 'docker compose -f ./docker-compose.yaml build';
|
||||
|
||||
// Simulate the injection logic from ApplicationDeploymentJob
|
||||
if (! str_contains($customCommand, '--env-file')) {
|
||||
$customCommand = str_replace(
|
||||
'docker compose',
|
||||
'docker compose --env-file /artifacts/build-time.env',
|
||||
$customCommand
|
||||
);
|
||||
}
|
||||
|
||||
// Simulate BuildKit support
|
||||
$dockerBuildkitSupported = true;
|
||||
if ($dockerBuildkitSupported) {
|
||||
$customCommand = "DOCKER_BUILDKIT=1 {$customCommand}";
|
||||
}
|
||||
|
||||
expect($customCommand)->toBe('DOCKER_BUILDKIT=1 docker compose --env-file /artifacts/build-time.env -f ./docker-compose.yaml build');
|
||||
expect($customCommand)->toStartWith('DOCKER_BUILDKIT=1');
|
||||
expect($customCommand)->toContain('--env-file /artifacts/build-time.env');
|
||||
});
|
||||
|
||||
// Tests for -f flag injection
|
||||
|
||||
it('injects -f flag with compose file path into custom build command', function () {
|
||||
$customCommand = 'docker compose build';
|
||||
$composeFilePath = '/artifacts/deployment-uuid/backend/docker-compose.yaml';
|
||||
@@ -536,86 +415,6 @@ it('injects -f flag when command contains -fast flag (not -f)', function () {
|
||||
expect($customCommand)->toContain('-f /artifacts/uuid/docker-compose.yaml');
|
||||
});
|
||||
|
||||
// Path normalization tests for preview methods
|
||||
|
||||
it('normalizes path when baseDirectory is root slash', function () {
|
||||
$baseDirectory = '/';
|
||||
$composeLocation = '/docker-compose.yaml';
|
||||
|
||||
// Normalize baseDirectory to prevent double slashes
|
||||
$normalizedBase = $baseDirectory === '/' ? '' : rtrim($baseDirectory, '/');
|
||||
$path = ".{$normalizedBase}{$composeLocation}";
|
||||
|
||||
expect($path)->toBe('./docker-compose.yaml');
|
||||
expect($path)->not->toContain('//');
|
||||
});
|
||||
|
||||
it('normalizes path when baseDirectory has trailing slash', function () {
|
||||
$baseDirectory = '/backend/';
|
||||
$composeLocation = '/docker-compose.yaml';
|
||||
|
||||
// Normalize baseDirectory to prevent double slashes
|
||||
$normalizedBase = $baseDirectory === '/' ? '' : rtrim($baseDirectory, '/');
|
||||
$path = ".{$normalizedBase}{$composeLocation}";
|
||||
|
||||
expect($path)->toBe('./backend/docker-compose.yaml');
|
||||
expect($path)->not->toContain('//');
|
||||
});
|
||||
|
||||
it('handles empty baseDirectory correctly', function () {
|
||||
$baseDirectory = '';
|
||||
$composeLocation = '/docker-compose.yaml';
|
||||
|
||||
// Normalize baseDirectory to prevent double slashes
|
||||
$normalizedBase = $baseDirectory === '/' ? '' : rtrim($baseDirectory, '/');
|
||||
$path = ".{$normalizedBase}{$composeLocation}";
|
||||
|
||||
expect($path)->toBe('./docker-compose.yaml');
|
||||
expect($path)->not->toContain('//');
|
||||
});
|
||||
|
||||
it('handles normal baseDirectory without trailing slash', function () {
|
||||
$baseDirectory = '/backend';
|
||||
$composeLocation = '/docker-compose.yaml';
|
||||
|
||||
// Normalize baseDirectory to prevent double slashes
|
||||
$normalizedBase = $baseDirectory === '/' ? '' : rtrim($baseDirectory, '/');
|
||||
$path = ".{$normalizedBase}{$composeLocation}";
|
||||
|
||||
expect($path)->toBe('./backend/docker-compose.yaml');
|
||||
expect($path)->not->toContain('//');
|
||||
});
|
||||
|
||||
it('handles nested baseDirectory with trailing slash', function () {
|
||||
$baseDirectory = '/app/backend/';
|
||||
$composeLocation = '/docker-compose.prod.yaml';
|
||||
|
||||
// Normalize baseDirectory to prevent double slashes
|
||||
$normalizedBase = $baseDirectory === '/' ? '' : rtrim($baseDirectory, '/');
|
||||
$path = ".{$normalizedBase}{$composeLocation}";
|
||||
|
||||
expect($path)->toBe('./app/backend/docker-compose.prod.yaml');
|
||||
expect($path)->not->toContain('//');
|
||||
});
|
||||
|
||||
it('produces correct preview path with normalized baseDirectory', function () {
|
||||
$testCases = [
|
||||
['baseDir' => '/', 'compose' => '/docker-compose.yaml', 'expected' => './docker-compose.yaml'],
|
||||
['baseDir' => '', 'compose' => '/docker-compose.yaml', 'expected' => './docker-compose.yaml'],
|
||||
['baseDir' => '/backend', 'compose' => '/docker-compose.yaml', 'expected' => './backend/docker-compose.yaml'],
|
||||
['baseDir' => '/backend/', 'compose' => '/docker-compose.yaml', 'expected' => './backend/docker-compose.yaml'],
|
||||
['baseDir' => '/app/src/', 'compose' => '/docker-compose.prod.yaml', 'expected' => './app/src/docker-compose.prod.yaml'],
|
||||
];
|
||||
|
||||
foreach ($testCases as $case) {
|
||||
$normalizedBase = $case['baseDir'] === '/' ? '' : rtrim($case['baseDir'], '/');
|
||||
$path = ".{$normalizedBase}{$case['compose']}";
|
||||
|
||||
expect($path)->toBe($case['expected'], "Failed for baseDir: {$case['baseDir']}");
|
||||
expect($path)->not->toContain('//', "Double slash found for baseDir: {$case['baseDir']}");
|
||||
}
|
||||
});
|
||||
|
||||
// Tests for injectDockerComposeBuildArgs() helper function
|
||||
it('injects build args when building specific service', function () {
|
||||
$command = 'docker compose build web';
|
||||
|
||||
Reference in New Issue
Block a user