wowowowowo
Some checks failed
CI / Lint (push) Failing after 22s
CI / Tests (push) Failing after 33s

This commit is contained in:
2026-05-28 15:15:41 +01:00
parent 8f603122e2
commit 5b977c1f41
129 changed files with 9943 additions and 722 deletions

View File

@@ -1,8 +1,17 @@
<?php
use App\Enums\EnvironmentAttachmentRole;
use App\Enums\ServiceCategory;
use App\Enums\ServiceType;
use App\Models\Application;
use App\Models\Environment;
use App\Models\Network;
use App\Models\Organisation;
use App\Models\Provider;
use App\Models\Server;
use App\Models\Service;
use App\Models\ServiceReplica;
use App\Models\ServiceSlice;
use App\Models\User;
use Inertia\Testing\AssertableInertia;
@@ -53,3 +62,77 @@ it('404s when the environment does not belong to the application', function () {
$response->assertNotFound();
});
it('renders caddyfile previews for gateway attachments', function () {
$organisation = Organisation::factory()->create();
$application = Application::factory()->create([
'organisation_id' => $organisation->id,
]);
$environment = Environment::factory()->create([
'application_id' => $application->id,
]);
$gateway = Service::factory()->for($environment)->create([
'organisation_id' => $organisation->id,
'name' => 'gateway',
'category' => ServiceCategory::GATEWAY,
'type' => ServiceType::CADDY,
'version' => '2',
'version_track' => '2',
'driver_name' => 'caddy.2',
]);
$web = Service::factory()->for($environment)->create([
'organisation_id' => $organisation->id,
'name' => 'web',
'category' => ServiceCategory::APPLICATION,
'type' => ServiceType::LARAVEL,
'version' => 'php-8.4',
'version_track' => 'php-8.4',
'driver_name' => 'laravel.php-8.4',
'process_roles' => ['web'],
]);
$provider = Provider::factory()->forOrganisation($organisation)->create();
$network = Network::query()->create([
'organisation_id' => $organisation->id,
'provider_id' => $provider->id,
'name' => 'private',
'ip_range' => '10.0.0.0/16',
]);
$server = Server::factory()
->forOrganisation($organisation->id)
->forProvider((string) $provider->id)
->forNetwork((string) $network->id)
->create();
ServiceReplica::factory()->for($web)->for($server)->create([
'internal_host' => 'web-1',
'internal_port' => 8080,
]);
$slice = ServiceSlice::factory()->for($gateway)->for($environment)->create([
'name' => 'billing',
'type' => 'route',
'config' => [
'domain' => 'billing.example.com',
'path_prefix' => '/app',
'tls_enabled' => false,
],
]);
$attachment = $environment->attachments()->create([
'service_id' => $gateway->id,
'service_slice_id' => $slice->id,
'role' => EnvironmentAttachmentRole::GATEWAY,
'is_primary' => true,
]);
$response = $this->get(route('environments.show', [
'organisation' => $organisation->id,
'application' => $application->id,
'environment' => $environment->id,
]));
$response->assertOk()
->assertInertia(fn (AssertableInertia $page) => $page
->component('environments/Show', false)
->where('gatewayRoutePreviews.0.attachment_id', $attachment->id)
->where('gatewayRoutePreviews.0.caddyfile', fn (string $caddyfile): bool => str_contains($caddyfile, 'http://billing.example.com {')
&& str_contains($caddyfile, 'handle_path /app* {')
&& str_contains($caddyfile, 'reverse_proxy web-1:8080')));
});