test: more tests
This commit is contained in:
@@ -5,6 +5,7 @@ use App\Models\GithubApp;
|
|||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\StandaloneDocker;
|
use App\Models\StandaloneDocker;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
ray()->clearAll();
|
ray()->clearAll();
|
||||||
@@ -31,8 +32,8 @@ beforeEach(function () {
|
|||||||
'db' => [
|
'db' => [
|
||||||
'image' => 'postgres',
|
'image' => 'postgres',
|
||||||
'environment' => [
|
'environment' => [
|
||||||
'POSTGRES_USER' => 'postgres',
|
'POSTGRES_USER' => '${POSTGRES_USER:-postgres}',
|
||||||
'POSTGRES_PASSWORD' => 'postgres',
|
'POSTGRES_PASSWORD' => '${POSTGRES_PASSWORD:-postgres}',
|
||||||
],
|
],
|
||||||
'volumes' => [
|
'volumes' => [
|
||||||
'dbdata:/var/lib/postgresql/data',
|
'dbdata:/var/lib/postgresql/data',
|
||||||
@@ -68,6 +69,7 @@ beforeEach(function () {
|
|||||||
|
|
||||||
$this->application = Application::create([
|
$this->application = Application::create([
|
||||||
'name' => 'Application for tests',
|
'name' => 'Application for tests',
|
||||||
|
'uuid' => 'bcoowoookw0co4cok4sgc4k8',
|
||||||
'repository_project_id' => 603035348,
|
'repository_project_id' => 603035348,
|
||||||
'git_repository' => 'coollabsio/coolify-examples',
|
'git_repository' => 'coollabsio/coolify-examples',
|
||||||
'git_branch' => 'main',
|
'git_branch' => 'main',
|
||||||
@@ -88,16 +90,90 @@ afterEach(function () {
|
|||||||
$this->application->forceDelete();
|
$this->application->forceDelete();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('ComposeParse', function () {
|
test('ComposeParsePreviewDeployment', function () {
|
||||||
// expect($this->jsonComposeFile)->toBeJson()->ray();
|
$pullRequestId = 1;
|
||||||
|
$previewId = 77;
|
||||||
|
expect($this->jsonComposeFile)->toBeJson()->ray();
|
||||||
|
|
||||||
$output = $this->application->dockerComposeParser(pull_request_id: 1, preview_id: 77);
|
$output = $this->application->dockerComposeParser(pull_request_id: $pullRequestId, preview_id: $previewId);
|
||||||
$outputOld = $this->application->parseCompose();
|
$outputOld = $this->application->parseCompose();
|
||||||
expect($output)->toBeInstanceOf(Collection::class);
|
expect($output)->toBeInstanceOf(Collection::class);
|
||||||
expect($outputOld)->toBeInstanceOf(Collection::class);
|
expect($outputOld)->toBeInstanceOf(Collection::class);
|
||||||
|
|
||||||
// ray(Yaml::dump($output->toArray(), 10, 2));
|
ray(Yaml::dump($output->toArray(), 10, 2));
|
||||||
ray(Yaml::dump($outputOld->toArray(), 10, 2));
|
$services = $output->get('services');
|
||||||
|
$servicesCount = count($this->composeFile['services']);
|
||||||
|
expect($services)->toHaveCount($servicesCount);
|
||||||
|
|
||||||
|
$appNull = $services->get('app');
|
||||||
|
expect($appNull)->toBeNull();
|
||||||
|
|
||||||
|
$dbNull = $services->get('db');
|
||||||
|
expect($dbNull)->toBeNull();
|
||||||
|
|
||||||
|
$app = $services->get("app-pr-{$pullRequestId}");
|
||||||
|
expect($app)->not->toBeNull();
|
||||||
|
|
||||||
|
$db = $services->get("db-pr-{$pullRequestId}");
|
||||||
|
expect($db)->not->toBeNull();
|
||||||
|
|
||||||
|
$appDependsOn = $app->get('depends_on');
|
||||||
|
expect($appDependsOn)->toContain('db-pr-'.$pullRequestId);
|
||||||
|
|
||||||
|
$dbDependsOn = $db->get('depends_on');
|
||||||
|
|
||||||
|
expect($dbDependsOn->keys()->first())->toContain('app-pr-'.$pullRequestId);
|
||||||
|
expect(data_get($dbDependsOn, 'app-pr-'.$pullRequestId.'.condition'))->toBe('service_healthy');
|
||||||
|
|
||||||
|
|
||||||
|
$environment = $app->get('environment');
|
||||||
|
expect($environment)->not->toBeNull();
|
||||||
|
|
||||||
|
$coolifyBranch = $environment->get('COOLIFY_BRANCH');
|
||||||
|
expect($coolifyBranch)->toBe("pull/{$pullRequestId}/head");
|
||||||
|
|
||||||
|
$coolifyContainerName = $environment->get('COOLIFY_CONTAINER_NAME');
|
||||||
|
expect($coolifyContainerName)->toMatch("/app-[a-z0-9]{24}-pr-{$pullRequestId}/");
|
||||||
|
|
||||||
|
$volumes = $app->get('volumes');
|
||||||
|
// /etc/nginx
|
||||||
|
$fileMount = $volumes->get(0);
|
||||||
|
$applicationConfigurationDir = application_configuration_dir();
|
||||||
|
expect($fileMount)->toBe("{$applicationConfigurationDir}/{$this->application->uuid}/nginx-pr-{$pullRequestId}:/etc/nginx");
|
||||||
|
|
||||||
|
// data:/var/www/html
|
||||||
|
$volumeMount = $volumes->get(1);
|
||||||
|
expect($volumeMount)->toBe("{$this->application->uuid}_data-pr-{$pullRequestId}:/var/www/html");
|
||||||
|
|
||||||
|
$containerName = $app->get('container_name');
|
||||||
|
expect($containerName)->toMatch("/app-[a-z0-9]{24}-pr-{$pullRequestId}/");
|
||||||
|
|
||||||
|
$labels = $app->get('labels');
|
||||||
|
expect($labels)->not->toBeNull();
|
||||||
|
expect($labels)->toContain('coolify.managed=true');
|
||||||
|
expect($labels)->toContain("coolify.pullRequestId={$pullRequestId}");
|
||||||
|
|
||||||
|
$topLevelVolumes = $output->get('volumes');
|
||||||
|
expect($topLevelVolumes)->not->toBeNull();
|
||||||
|
$firstVolume = $topLevelVolumes->first();
|
||||||
|
expect(data_get($firstVolume, 'name'))->toBe("{$this->application->uuid}_data-pr-{$pullRequestId}");
|
||||||
|
|
||||||
|
$topLevelNetworks = $output->get('networks');
|
||||||
|
expect($topLevelNetworks)->not->toBeNull();
|
||||||
|
$defaultNetwork = data_get($topLevelNetworks, 'default');
|
||||||
|
expect($defaultNetwork)->not->toBeNull();
|
||||||
|
expect(data_get($defaultNetwork, 'name'))->toBe('something');
|
||||||
|
expect(data_get($defaultNetwork, 'external'))->toBe(true);
|
||||||
|
|
||||||
|
$noinetNetwork = data_get($topLevelNetworks, 'noinet');
|
||||||
|
expect($noinetNetwork)->not->toBeNull();
|
||||||
|
expect(data_get($noinetNetwork, 'driver'))->toBe('bridge');
|
||||||
|
expect(data_get($noinetNetwork, 'internal'))->toBe(true);
|
||||||
|
|
||||||
|
$serviceNetwork = data_get($topLevelNetworks, "{$this->application->uuid}-{$pullRequestId}");
|
||||||
|
expect($serviceNetwork)->not->toBeNull();
|
||||||
|
expect(data_get($serviceNetwork, 'name'))->toBe("{$this->application->uuid}-{$pullRequestId}");
|
||||||
|
expect(data_get($serviceNetwork, 'external'))->toBe(true);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user