Implement Keystone environment deployments
This commit is contained in:
61
tests/Feature/ServiceEndpointTest.php
Normal file
61
tests/Feature/ServiceEndpointTest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
use App\Actions\Services\RegisterServiceEndpoint;
|
||||
use App\Enums\ServiceEndpointScope;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\Provider;
|
||||
use App\Models\Server;
|
||||
use App\Models\Service;
|
||||
use App\Models\ServiceReplica;
|
||||
|
||||
it('prefers docker network endpoints for same-server communication', function () {
|
||||
$server = endpointTestServer();
|
||||
$service = Service::factory()->create(['server_id' => $server->id]);
|
||||
$producer = ServiceReplica::factory()->for($service)->for($server)->create([
|
||||
'internal_host' => 'postgres-1',
|
||||
'internal_port' => 5432,
|
||||
]);
|
||||
$consumer = ServiceReplica::factory()->for($server)->create();
|
||||
|
||||
$endpoint = app(RegisterServiceEndpoint::class)->execute($producer, $consumer);
|
||||
|
||||
expect($endpoint->scope)->toBe(ServiceEndpointScope::DOCKER_NETWORK)
|
||||
->and($endpoint->hostname)->toBe('postgres-1')
|
||||
->and($endpoint->ip_address)->toBeNull()
|
||||
->and($endpoint->priority)->toBe(10);
|
||||
});
|
||||
|
||||
it('uses private networking across servers before public fallback', function () {
|
||||
$producerServer = endpointTestServer(['private_ip' => '10.0.0.10', 'ipv4' => '203.0.113.10']);
|
||||
$consumerServer = endpointTestServer(['private_ip' => '10.0.0.11', 'ipv4' => '203.0.113.11']);
|
||||
$service = Service::factory()->create(['server_id' => $producerServer->id]);
|
||||
$producer = ServiceReplica::factory()->for($service)->for($producerServer)->create([
|
||||
'internal_port' => 8080,
|
||||
]);
|
||||
$consumer = ServiceReplica::factory()->for($consumerServer)->create();
|
||||
|
||||
$endpoint = app(RegisterServiceEndpoint::class)->execute($producer, $consumer, allowPublicFallback: true);
|
||||
|
||||
expect($endpoint->scope)->toBe(ServiceEndpointScope::PRIVATE_NETWORK)
|
||||
->and($endpoint->hostname)->toBe('10.0.0.10')
|
||||
->and($endpoint->priority)->toBe(20);
|
||||
});
|
||||
|
||||
function endpointTestServer(array $attributes = []): Server
|
||||
{
|
||||
$organisation = Organisation::factory()->create();
|
||||
$provider = Provider::factory()->forOrganisation($organisation)->create();
|
||||
$network = $organisation->networks()->create([
|
||||
'name' => 'keystone',
|
||||
'external_id' => 'net-12345',
|
||||
'provider_id' => $provider->id,
|
||||
'ip_range' => fake()->ipv4().'/24',
|
||||
]);
|
||||
|
||||
return Server::factory()->create([
|
||||
'organisation_id' => $organisation->id,
|
||||
'provider_id' => $provider->id,
|
||||
'network_id' => $network->id,
|
||||
...$attributes,
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user