mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 16:46:37 +00:00
- Delete Blade components, component classes, Livewire components and views that nothing uses after the redesign. - Delete tests that only compare Blade/CSS source text; keep the source checks for authorization gates, stable wire:key values and escaping. - Update stale tests to the current UI and behaviour. - Update DESIGN.md to the current navigation and layout. - Add a lesson: test behaviour, not source markup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
73 lines
2.8 KiB
PHP
73 lines
2.8 KiB
PHP
<?php
|
|
|
|
use App\Actions\Database\StartDatabaseProxy;
|
|
use App\Models\Environment;
|
|
use App\Models\Project;
|
|
use App\Models\Server;
|
|
use App\Models\StandaloneDocker;
|
|
use App\Models\StandalonePostgresql;
|
|
use App\Models\Team;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Notification;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
Notification::fake();
|
|
});
|
|
|
|
test('database proxy is disabled on port already allocated error', function () {
|
|
$team = Team::factory()->create();
|
|
$server = Server::factory()->create(['team_id' => $team->id]);
|
|
$destination = StandaloneDocker::query()->where('server_id', $server->id)->firstOrFail();
|
|
$project = Project::factory()->create(['team_id' => $team->id]);
|
|
$environment = Environment::factory()->create(['project_id' => $project->id]);
|
|
|
|
$database = StandalonePostgresql::create([
|
|
'name' => 'postgres',
|
|
'image' => 'postgres:16-alpine',
|
|
'postgres_user' => 'postgres',
|
|
'postgres_password' => 'password',
|
|
'postgres_db' => 'postgres',
|
|
'environment_id' => $environment->id,
|
|
'destination_id' => $destination->id,
|
|
'destination_type' => $destination->getMorphClass(),
|
|
'is_public' => true,
|
|
'public_port' => 5432,
|
|
]);
|
|
|
|
expect($database->is_public)->toBeTrue();
|
|
|
|
$action = new StartDatabaseProxy;
|
|
|
|
// Use reflection to test the private method directly
|
|
$method = new ReflectionMethod($action, 'isNonTransientError');
|
|
|
|
expect($method->invoke($action, 'Bind for 0.0.0.0:5432 failed: port is already allocated'))->toBeTrue();
|
|
expect($method->invoke($action, 'address already in use'))->toBeTrue();
|
|
expect($method->invoke($action, 'some other error'))->toBeFalse();
|
|
});
|
|
|
|
test('isNonTransientError detects port conflict patterns', function () {
|
|
$action = new StartDatabaseProxy;
|
|
$method = new ReflectionMethod($action, 'isNonTransientError');
|
|
|
|
expect($method->invoke($action, 'Bind for 0.0.0.0:5432 failed: port is already allocated'))->toBeTrue()
|
|
->and($method->invoke($action, 'address already in use'))->toBeTrue()
|
|
->and($method->invoke($action, 'Bind for 0.0.0.0:3306 failed: port is already allocated'))->toBeTrue()
|
|
->and($method->invoke($action, 'network timeout'))->toBeFalse()
|
|
->and($method->invoke($action, 'connection refused'))->toBeFalse();
|
|
});
|
|
|
|
test('buildProxyTimeoutConfig normalizes invalid values to default', function (?int $input, string $expected) {
|
|
$action = new StartDatabaseProxy;
|
|
$method = new ReflectionMethod($action, 'buildProxyTimeoutConfig');
|
|
|
|
expect($method->invoke($action, $input))->toBe($expected);
|
|
})->with([
|
|
[null, 'proxy_timeout 3600s;'],
|
|
[0, 'proxy_timeout 3600s;'],
|
|
[-10, 'proxy_timeout 3600s;'],
|
|
[120, 'proxy_timeout 120s;'],
|
|
]);
|