New direction; removed wireguard, readme update

This commit is contained in:
2025-09-07 11:37:52 +01:00
parent 82556535ba
commit a91780d1d5
21 changed files with 102 additions and 5622 deletions

View File

@@ -2,8 +2,6 @@
use App\Actions\Services\CreateService;
use App\Drivers\Driver;
use App\Drivers\Postgres\Postgres17Driver;
use App\Enums\NetworkType;
use App\Enums\ServiceCategory;
use App\Enums\ServiceStatus;
use App\Enums\ServiceType;
@@ -21,21 +19,21 @@ use Illuminate\Support\Facades\Bus;
uses(RefreshDatabase::class);
function setupTestEnvironment() {
function setupTestEnvironment()
{
$user = User::factory()->create();
$organisation = Organisation::factory()->create([
'owner_id' => $user->id
]);
$provider = Provider::factory()->create([
'organisation_id' => $organisation->id
]);
$network = Network::create([
'name' => 'test-network',
'ip_range' => '10.0.0.0/24',
'type' => NetworkType::EXTERNAL,
'external_id' => 'ext-12345',
'organisation_id' => $organisation->id,
'provider_id' => $provider->id,
@@ -44,7 +42,7 @@ function setupTestEnvironment() {
$server = Server::factory()->create([
'organisation_id' => $organisation->id,
'provider_id' => $provider->id,
'external_network_id' => $network->id,
'network_id' => $network->id,
]);
return [
@@ -58,41 +56,42 @@ function setupTestEnvironment() {
test('create service page is accessible', function () {
$setup = setupTestEnvironment();
$this->actingAs($setup['user']);
$response = $this->get(route('services.create', [
'organisation' => $setup['organisation']->id,
'server' => $setup['server']->id
]));
$response->assertStatus(200);
$response->assertInertia(fn (AssertableInertia $page) => $page
->component('services/Create')
->has('server')
->has('services')
$response->assertInertia(
fn(AssertableInertia $page) => $page
->component('services/Create')
->has('server')
->has('services')
);
});
test('store service with valid data', function () {
$setup = setupTestEnvironment();
$this->actingAs($setup['user']);
$mockDefaultCredentials = [
'user' => 'test-user',
'password' => 'test-password',
'db' => 'test-db'
];
$mockDriver = Mockery::mock(Driver::class);
$mockDriver->shouldReceive('defaultCredentials')->andReturn($mockDefaultCredentials);
// intercept the driver
$this->partialMock(Service::class, function ($mock) use ($mockDriver) {
$mock->shouldReceive('driver')->andReturn($mockDriver);
});
Bus::fake();
$data = [
@@ -113,7 +112,7 @@ test('store service with valid data', function () {
'server' => $setup['server']->id
]));
$response->assertSessionHas('success', 'Service created successfully');
$this->assertDatabaseHas('services', [
'name' => 'test-postgres-database',
'server_id' => $setup['server']->id,
@@ -123,13 +122,13 @@ test('store service with valid data', function () {
'driver_name' => 'postgres.17',
'status' => ServiceStatus::NOT_INSTALLED->value,
]);
Bus::assertDispatched(DeployService::class);
});
test('store service with invalid data', function () {
$setup = setupTestEnvironment();
$this->actingAs($setup['user']);
$data = [
@@ -149,9 +148,9 @@ test('store service with invalid data', function () {
test('store service validates version exists in config', function () {
$setup = setupTestEnvironment();
$this->actingAs($setup['user']);
// Mock the config to simulate the version not existing
Config::set('keystone.services.' . ServiceCategory::DATABASE->value . '.' . ServiceType::POSTGRES->value . '.versions', [
'16' => [
@@ -160,7 +159,7 @@ test('store service validates version exists in config', function () {
'image' => 'postgres:16',
]
]);
$data = [
'name' => 'test-postgres-database',
'category' => ServiceCategory::DATABASE->value,
@@ -172,15 +171,15 @@ test('store service validates version exists in config', function () {
'organisation' => $setup['organisation']->id,
'server' => $setup['server']->id
]), $data);
$response->assertSessionHasErrors(['version']);
});
test('store service with non-existent server returns 404', function () {
$setup = setupTestEnvironment();
$this->actingAs($setup['user']);
$data = [
'name' => 'test-postgres-database',
'category' => ServiceCategory::DATABASE->value,
@@ -192,27 +191,27 @@ test('store service with non-existent server returns 404', function () {
'organisation' => $setup['organisation']->id,
'server' => 9999
]), $data);
$response->assertStatus(404);
});
test('create service page with non-existent server returns 404', function () {
$setup = setupTestEnvironment();
$this->actingAs($setup['user']);
$response = $this->get(route('services.create', [
'organisation' => $setup['organisation']->id,
'server' => 9999
]));
$response->assertStatus(404);
});
test('store service is properly created and dispatched', function () {
$setup = setupTestEnvironment();
$this->actingAs($setup['user']);
// Setup mock credentials and driver
$mockDriver = Mockery::mock(Driver::class)->shouldReceive('defaultCredentials')
->andReturn([
@@ -221,7 +220,7 @@ test('store service is properly created and dispatched', function () {
'db' => 'test-db'
])
->getMock();
// Setup test data
$testData = [
'name' => 'test-postgres-database',
@@ -229,12 +228,12 @@ test('store service is properly created and dispatched', function () {
'type' => ServiceType::POSTGRES->value,
'version' => '17',
];
// Mock service class to return our mock driver
$this->partialMock(Service::class, function ($mock) use ($mockDriver) {
$mock->shouldReceive('driver')->andReturn($mockDriver);
});
// Mock CreateService action
$this->mock(CreateService::class, function ($mock) use ($setup, $testData) {
$service = new Service([
@@ -247,9 +246,9 @@ test('store service is properly created and dispatched', function () {
'driver_name' => 'postgres.17',
'status' => ServiceStatus::NOT_INSTALLED,
]);
$service->setRelation('server', $setup['server']);
$mock->shouldReceive('execute')
->once()
->withArgs(function ($server, $name, $category, $type, $version) use ($setup, $testData) {
@@ -261,7 +260,7 @@ test('store service is properly created and dispatched', function () {
})
->andReturn($service);
});
Bus::fake();
// Execute request
@@ -287,7 +286,7 @@ test('store service is properly created and dispatched', function () {
'driver_name' => 'postgres.17',
'status' => ServiceStatus::NOT_INSTALLED->value,
]);
// Assert job was dispatched
Bus::assertDispatched(DeployService::class);
});
});