Files
vito/tests/Feature/API/ServerTest.php
Rasel Islam Rafi 2318e1b1df Add Caddy Server Support Alongside Nginx (#600)
* added enum

* add config for caddy

* add svg icon

* add caddy service class

* wip

* install caddy

* create base Caddyfile with common snippets

* Create a systemd service to run Caddy in the background.

* create uninstall file

* wip

* create path

* create vhost

* get vhost

* delete site

* add php version change file

* add custom ssl

* create redirect file

* add vhost for caddy site & load balancer

* update svg

* fix caddy icon

* fix style

* add systemctl reload method

* Reload systemd after modifying the Caddy service file.

* add caddy

* added tests

* format with pint

* prevent multiple web server installations

* added error log & access log
2025-05-29 11:25:36 +02:00

135 lines
3.8 KiB
PHP

<?php
namespace Tests\Feature\API;
use App\Enums\Database;
use App\Enums\OperatingSystem;
use App\Enums\ServerProvider;
use App\Enums\ServerType;
use App\Enums\Webserver;
use App\Facades\SSH;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class ServerTest extends TestCase
{
use RefreshDatabase;
public function test_get_servers(): void
{
Sanctum::actingAs($this->user, ['read', 'write']);
$this->json('GET', route('api.projects.servers', [
'project' => $this->user->current_project_id,
]))
->assertSuccessful()
->assertJsonFragment([
'name' => $this->server->name,
]);
}
public function test_get_server(): void
{
Sanctum::actingAs($this->user, ['read', 'write']);
$this->json('GET', route('api.projects.servers.show', [
'project' => $this->user->current_project_id,
'server' => $this->server,
]))
->assertSuccessful()
->assertJsonFragment([
'name' => $this->server->name,
]);
}
public function test_create_server(): void
{
Sanctum::actingAs($this->user, ['read', 'write']);
SSH::fake('Active: active'); // fake output for service installations
$this->json('POST', route('api.projects.servers.create', [
'project' => $this->user->current_project_id,
]), [
'provider' => ServerProvider::CUSTOM,
'name' => 'test',
'ip' => '1.1.1.1',
'port' => '22',
'os' => OperatingSystem::UBUNTU22,
'webserver' => Webserver::NGINX,
'database' => Database::MYSQL80,
'php' => '8.2',
])
->assertSuccessful()
->assertJsonFragment([
'name' => 'test',
'type' => ServerType::REGULAR,
]);
}
public function test_create_server_with_caddy(): void
{
Sanctum::actingAs($this->user, ['read', 'write']);
SSH::fake('Active: active'); // fake output for service installations
$this->json('POST', route('api.projects.servers.create', [
'project' => $this->user->current_project_id,
]), [
'provider' => ServerProvider::CUSTOM,
'name' => 'test',
'ip' => '1.1.1.1',
'port' => '22',
'os' => OperatingSystem::UBUNTU22,
'webserver' => Webserver::CADDY,
'database' => Database::MYSQL80,
'php' => '8.2',
])
->assertSuccessful()
->assertJsonFragment([
'name' => 'test',
'type' => ServerType::REGULAR,
]);
}
public function test_delete_server(): void
{
Sanctum::actingAs($this->user, ['read', 'write']);
SSH::fake();
$this->json('DELETE', route('api.projects.servers.delete', [
'project' => $this->server->project_id,
'server' => $this->server->id,
]))
->assertNoContent();
}
public function test_reboot_server(): void
{
SSH::fake();
Sanctum::actingAs($this->user, ['read', 'write']);
$this->json('POST', route('api.projects.servers.reboot', [
'project' => $this->server->project_id,
'server' => $this->server->id,
]))
->assertNoContent();
}
public function test_upgrade_server(): void
{
SSH::fake('Available updates:0');
Sanctum::actingAs($this->user, ['read', 'write']);
$this->json('POST', route('api.projects.servers.upgrade', [
'project' => $this->server->project_id,
'server' => $this->server->id,
]))
->assertNoContent();
}
}