mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 05:56:16 +00:00
refactoring (#116)
- refactoring architecture - fix incomplete ssh logs - code editor for scripts in the app - remove Jobs and SSHCommands
This commit is contained in:
@ -2,10 +2,10 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Jobs\Site\UpdateBranch;
|
||||
use App\Enums\DeploymentStatus;
|
||||
use App\Facades\SSH;
|
||||
use App\Models\GitHook;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
@ -47,9 +47,64 @@ public function test_update_deployment_script()
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_deploy(): void
|
||||
{
|
||||
SSH::fake();
|
||||
Http::fake([
|
||||
'github.com/*' => Http::response([
|
||||
'sha' => '123',
|
||||
'commit' => [
|
||||
'message' => 'test commit message',
|
||||
'name' => 'test commit name',
|
||||
'email' => 'test@example.com',
|
||||
'url' => 'https://github.com/commit-url',
|
||||
],
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$this->site->deploymentScript->update([
|
||||
'content' => 'git pull',
|
||||
]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$response = $this->post(route('servers.sites.application.deploy', [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
|
||||
$response->assertSessionHas('toast.type', 'success');
|
||||
$response->assertSessionHas('toast.message', 'Deployment started!');
|
||||
|
||||
$this->assertDatabaseHas('deployments', [
|
||||
'site_id' => $this->site->id,
|
||||
'status' => DeploymentStatus::FINISHED,
|
||||
]);
|
||||
|
||||
SSH::assertExecutedContains('cd /home/vito/'.$this->site->domain);
|
||||
SSH::assertExecutedContains('git pull');
|
||||
|
||||
$this->get(route('servers.sites.show', [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
]))
|
||||
->assertOk()
|
||||
->assertSee('test commit message');
|
||||
|
||||
$deployment = $this->site->deployments()->first();
|
||||
|
||||
$this->get(route('servers.sites.application.deployment.log', [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
'deployment' => $deployment,
|
||||
]))
|
||||
->assertRedirect()
|
||||
->assertSessionHas('content', 'fake output');
|
||||
}
|
||||
|
||||
public function test_change_branch()
|
||||
{
|
||||
Bus::fake();
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
@ -58,9 +113,14 @@ public function test_change_branch()
|
||||
'site' => $this->site,
|
||||
]), [
|
||||
'branch' => 'master',
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
])
|
||||
->assertSessionDoesntHaveErrors()
|
||||
->assertSessionHas('toast.type', 'success');
|
||||
|
||||
Bus::assertDispatched(UpdateBranch::class);
|
||||
$this->site->refresh();
|
||||
$this->assertEquals('master', $this->site->branch);
|
||||
|
||||
SSH::assertExecutedContains('git checkout -f master');
|
||||
}
|
||||
|
||||
public function test_enable_auto_deployment()
|
||||
@ -68,7 +128,7 @@ public function test_enable_auto_deployment()
|
||||
Http::fake([
|
||||
'github.com/*' => Http::response([
|
||||
'id' => '123',
|
||||
], 201),
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
@ -80,18 +140,21 @@ public function test_enable_auto_deployment()
|
||||
|
||||
$this->site->refresh();
|
||||
|
||||
$this->assertTrue($this->site->auto_deployment);
|
||||
$this->assertTrue($this->site->isAutoDeployment());
|
||||
}
|
||||
|
||||
public function test_disable_auto_deployment()
|
||||
{
|
||||
Http::fake([
|
||||
'github.com/*' => Http::response([], 204),
|
||||
'api.github.com/repos/organization/repository' => Http::response([
|
||||
'id' => '123',
|
||||
], 200),
|
||||
'api.github.com/repos/organization/repository/hooks/*' => Http::response([], 204),
|
||||
]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
GitHook::factory()->create([
|
||||
$hook = GitHook::factory()->create([
|
||||
'site_id' => $this->site->id,
|
||||
'source_control_id' => $this->site->source_control_id,
|
||||
]);
|
||||
@ -103,6 +166,22 @@ public function test_disable_auto_deployment()
|
||||
|
||||
$this->site->refresh();
|
||||
|
||||
$this->assertFalse($this->site->auto_deployment);
|
||||
$this->assertFalse($this->site->isAutoDeployment());
|
||||
}
|
||||
|
||||
public function test_update_env_file(): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(route('servers.sites.application.env', [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
]), [
|
||||
'env' => 'APP_ENV=production',
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
|
||||
SSH::assertExecutedContains('echo "APP_ENV=production" | tee /home/vito/'.$this->site->domain.'/.env');
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace Tests\Feature\Auth;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use JsonException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PasswordConfirmationTest extends TestCase
|
||||
@ -19,9 +18,6 @@ public function test_confirm_password_screen_can_be_rendered(): void
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_password_can_be_confirmed(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
@ -31,7 +27,7 @@ public function test_password_can_be_confirmed(): void
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
$response->assertSessionHasNoErrors();
|
||||
$response->assertSessionDoesntHaveErrors();
|
||||
}
|
||||
|
||||
public function test_password_is_not_confirmed_with_invalid_password(): void
|
||||
|
@ -56,7 +56,7 @@ public function test_password_can_be_reset_with_valid_token(): void
|
||||
'password_confirmation' => 'password',
|
||||
]);
|
||||
|
||||
$response->assertSessionHasNoErrors();
|
||||
$response->assertSessionDoesntHaveErrors();
|
||||
|
||||
return true;
|
||||
});
|
||||
|
@ -22,7 +22,7 @@ public function test_see_cronjobs_list()
|
||||
]);
|
||||
|
||||
$this->get(route('servers.cronjobs', $this->server))
|
||||
->assertSeeText($cronjob->frequency_label);
|
||||
->assertSeeText($cronjob->frequencyLabel());
|
||||
}
|
||||
|
||||
public function test_delete_cronjob()
|
||||
@ -34,16 +34,20 @@ public function test_delete_cronjob()
|
||||
/** @var CronJob $cronjob */
|
||||
$cronjob = CronJob::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
'user' => 'vito',
|
||||
]);
|
||||
|
||||
$this->delete(route('servers.cronjobs.destroy', [
|
||||
'server' => $this->server,
|
||||
'cronJob' => $cronjob,
|
||||
]))->assertSessionHasNoErrors();
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseMissing('cron_jobs', [
|
||||
'id' => $cronjob->id,
|
||||
]);
|
||||
|
||||
SSH::assertExecutedContains("echo '' | sudo -u vito crontab -");
|
||||
SSH::assertExecutedContains('sudo -u vito crontab -l');
|
||||
}
|
||||
|
||||
public function test_create_cronjob()
|
||||
@ -56,7 +60,7 @@ public function test_create_cronjob()
|
||||
'command' => 'ls -la',
|
||||
'user' => 'vito',
|
||||
'frequency' => '* * * * *',
|
||||
])->assertSessionHasNoErrors();
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseHas('cron_jobs', [
|
||||
'server_id' => $this->server->id,
|
||||
@ -65,5 +69,33 @@ public function test_create_cronjob()
|
||||
'frequency' => '* * * * *',
|
||||
'status' => CronjobStatus::READY,
|
||||
]);
|
||||
|
||||
SSH::assertExecutedContains("echo '* * * * * ls -la' | sudo -u vito crontab -");
|
||||
SSH::assertExecutedContains('sudo -u vito crontab -l');
|
||||
}
|
||||
|
||||
public function test_create_custom_cronjob()
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(route('servers.cronjobs.store', $this->server), [
|
||||
'command' => 'ls -la',
|
||||
'user' => 'vito',
|
||||
'frequency' => 'custom',
|
||||
'custom' => '* * * 1 1',
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseHas('cron_jobs', [
|
||||
'server_id' => $this->server->id,
|
||||
'command' => 'ls -la',
|
||||
'user' => 'vito',
|
||||
'frequency' => '* * * 1 1',
|
||||
'status' => CronjobStatus::READY,
|
||||
]);
|
||||
|
||||
SSH::assertExecutedContains("echo '* * * 1 1 ls -la' | sudo -u vito crontab -");
|
||||
SSH::assertExecutedContains('sudo -u vito crontab -l');
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,14 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Enums\BackupFileStatus;
|
||||
use App\Enums\BackupStatus;
|
||||
use App\Facades\SSH;
|
||||
use App\Jobs\Backup\RunBackup;
|
||||
use App\Models\Backup;
|
||||
use App\Models\Database;
|
||||
use App\Models\StorageProvider;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DatabaseBackupTest extends TestCase
|
||||
@ -18,12 +18,11 @@ class DatabaseBackupTest extends TestCase
|
||||
|
||||
public function test_create_backup(): void
|
||||
{
|
||||
SSH::fake();
|
||||
Http::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Bus::fake();
|
||||
|
||||
SSH::fake()->outputShouldBe('test');
|
||||
|
||||
$database = Database::factory()->create([
|
||||
'server_id' => $this->server,
|
||||
]);
|
||||
@ -38,13 +37,15 @@ public function test_create_backup(): void
|
||||
'backup_storage' => $storage->id,
|
||||
'backup_interval' => '0 * * * *',
|
||||
'backup_keep' => '10',
|
||||
])->assertSessionHasNoErrors();
|
||||
|
||||
Bus::assertDispatched(RunBackup::class);
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseHas('backups', [
|
||||
'status' => BackupStatus::RUNNING,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('backup_files', [
|
||||
'status' => BackupFileStatus::CREATED,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_see_backups_list(): void
|
||||
@ -70,7 +71,7 @@ public function test_see_backups_list(): void
|
||||
->assertSee($backup->database->name);
|
||||
}
|
||||
|
||||
public function test_delete_database(): void
|
||||
public function test_delete_backup(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
@ -90,7 +91,7 @@ public function test_delete_database(): void
|
||||
]);
|
||||
|
||||
$this->delete(route('servers.databases.backups.destroy', [$this->server, $backup]))
|
||||
->assertSessionHasNoErrors();
|
||||
->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseMissing('backups', [
|
||||
'id' => $backup->id,
|
||||
|
@ -16,11 +16,11 @@ public function test_create_database(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
SSH::fake()->outputShouldBe('test');
|
||||
SSH::fake();
|
||||
|
||||
$this->post(route('servers.databases.store', $this->server), [
|
||||
'name' => 'database',
|
||||
])->assertSessionHasNoErrors();
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseHas('databases', [
|
||||
'name' => 'database',
|
||||
@ -44,14 +44,14 @@ public function test_delete_database(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
SSH::fake()->outputShouldBe('test');
|
||||
SSH::fake();
|
||||
|
||||
$database = Database::factory()->create([
|
||||
'server_id' => $this->server,
|
||||
]);
|
||||
|
||||
$this->delete(route('servers.databases.destroy', [$this->server, $database]))
|
||||
->assertSessionHasNoErrors();
|
||||
->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseMissing('databases', [
|
||||
'id' => $database->id,
|
||||
|
@ -21,7 +21,7 @@ public function test_create_database_user(): void
|
||||
$this->post(route('servers.databases.users.store', $this->server), [
|
||||
'username' => 'user',
|
||||
'password' => 'password',
|
||||
])->assertSessionHasNoErrors();
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseHas('database_users', [
|
||||
'username' => 'user',
|
||||
@ -52,7 +52,7 @@ public function test_delete_database_user(): void
|
||||
]);
|
||||
|
||||
$this->delete(route('servers.databases.users.destroy', [$this->server, $databaseUser]))
|
||||
->assertSessionHasNoErrors();
|
||||
->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseMissing('database_users', [
|
||||
'id' => $databaseUser->id,
|
||||
|
@ -24,7 +24,7 @@ public function test_create_firewall_rule(): void
|
||||
'port' => '1234',
|
||||
'source' => '0.0.0.0',
|
||||
'mask' => '0',
|
||||
])->assertSessionHasNoErrors();
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseHas('firewall_rules', [
|
||||
'port' => '1234',
|
||||
@ -58,7 +58,7 @@ public function test_delete_firewall_rule(): void
|
||||
$this->delete(route('servers.firewall.destroy', [
|
||||
'server' => $this->server,
|
||||
'firewallRule' => $rule,
|
||||
]))->assertSessionHasNoErrors();
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseMissing('firewall_rules', [
|
||||
'id' => $rule->id,
|
||||
|
@ -6,7 +6,6 @@
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use JsonException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class NotificationChannelsTest extends TestCase
|
||||
@ -14,9 +13,6 @@ class NotificationChannelsTest extends TestCase
|
||||
use RefreshDatabase;
|
||||
use WithFaker;
|
||||
|
||||
/**
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_add_email_channel(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
@ -25,7 +21,7 @@ public function test_add_email_channel(): void
|
||||
'provider' => NotificationChannel::EMAIL,
|
||||
'email' => 'email@example.com',
|
||||
'label' => 'Email',
|
||||
])->assertSessionHasNoErrors();
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
|
||||
/** @var \App\Models\NotificationChannel $channel */
|
||||
$channel = \App\Models\NotificationChannel::query()
|
||||
@ -36,9 +32,6 @@ public function test_add_email_channel(): void
|
||||
$this->assertTrue($channel->connected);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_add_slack_channel(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
@ -49,7 +42,7 @@ public function test_add_slack_channel(): void
|
||||
'provider' => NotificationChannel::SLACK,
|
||||
'webhook_url' => 'https://hooks.slack.com/services/123/token',
|
||||
'label' => 'Slack',
|
||||
])->assertSessionHasNoErrors();
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
|
||||
/** @var \App\Models\NotificationChannel $channel */
|
||||
$channel = \App\Models\NotificationChannel::query()
|
||||
@ -60,9 +53,6 @@ public function test_add_slack_channel(): void
|
||||
$this->assertTrue($channel->connected);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_add_discord_channel(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
@ -73,7 +63,7 @@ public function test_add_discord_channel(): void
|
||||
'provider' => NotificationChannel::DISCORD,
|
||||
'webhook_url' => 'https://discord.com/api/webhooks/123/token',
|
||||
'label' => 'Discord',
|
||||
])->assertSessionHasNoErrors();
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
|
||||
/** @var \App\Models\NotificationChannel $channel */
|
||||
$channel = \App\Models\NotificationChannel::query()
|
||||
@ -87,9 +77,7 @@ public function test_add_discord_channel(): void
|
||||
/*
|
||||
* @TODO fix json comparison
|
||||
*/
|
||||
/**
|
||||
* @throws JsonException
|
||||
*/
|
||||
|
||||
public function test_add_telegram_channel(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
@ -101,7 +89,7 @@ public function test_add_telegram_channel(): void
|
||||
'bot_token' => 'token',
|
||||
'chat_id' => '123',
|
||||
'label' => 'Telegram',
|
||||
])->assertSessionHasNoErrors();
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
|
||||
/** @var \App\Models\NotificationChannel $channel */
|
||||
$channel = \App\Models\NotificationChannel::query()
|
||||
@ -123,9 +111,6 @@ public function test_see_channels_list(): void
|
||||
->assertSee($channel->provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_delete_channel(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
@ -133,7 +118,7 @@ public function test_delete_channel(): void
|
||||
$channel = \App\Models\NotificationChannel::factory()->create();
|
||||
|
||||
$this->delete(route('notification-channels.delete', $channel->id))
|
||||
->assertSessionHasNoErrors();
|
||||
->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseMissing('notification_channels', [
|
||||
'id' => $channel->id,
|
||||
|
@ -3,12 +3,9 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Enums\ServiceStatus;
|
||||
use App\Jobs\Installation\InstallPHP;
|
||||
use App\Jobs\Installation\UninstallPHP;
|
||||
use App\Jobs\PHP\InstallPHPExtension;
|
||||
use App\Facades\SSH;
|
||||
use App\Models\Service;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PHPTest extends TestCase
|
||||
@ -17,21 +14,26 @@ class PHPTest extends TestCase
|
||||
|
||||
public function test_install_new_php(): void
|
||||
{
|
||||
Bus::fake();
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(route('servers.php.install', [
|
||||
'server' => $this->server,
|
||||
'version' => '8.1',
|
||||
]))->assertSessionHasNoErrors();
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
|
||||
Bus::assertDispatched(InstallPHP::class);
|
||||
$this->assertDatabaseHas('services', [
|
||||
'server_id' => $this->server->id,
|
||||
'type' => 'php',
|
||||
'version' => '8.1',
|
||||
'status' => ServiceStatus::READY,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_uninstall_php(): void
|
||||
{
|
||||
Bus::fake();
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
@ -52,9 +54,11 @@ public function test_uninstall_php(): void
|
||||
$this->delete(route('servers.php.uninstall', [
|
||||
'server' => $this->server,
|
||||
'version' => '8.1',
|
||||
]))->assertSessionHasNoErrors();
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
|
||||
Bus::assertDispatched(UninstallPHP::class);
|
||||
$this->assertDatabaseMissing('services', [
|
||||
'id' => $php->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_cannot_uninstall_php(): void
|
||||
@ -69,6 +73,8 @@ public function test_cannot_uninstall_php(): void
|
||||
|
||||
public function test_change_default_php_cli(): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$php = Service::factory()->create([
|
||||
@ -85,7 +91,7 @@ public function test_change_default_php_cli(): void
|
||||
$this->post(route('servers.php.default-cli', [
|
||||
'server' => $this->server,
|
||||
'version' => '8.1',
|
||||
]))->assertSessionHasNoErrors();
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
|
||||
$php->refresh();
|
||||
|
||||
@ -94,7 +100,7 @@ public function test_change_default_php_cli(): void
|
||||
|
||||
public function test_install_extension(): void
|
||||
{
|
||||
Bus::fake();
|
||||
SSH::fake('output... [PHP Modules] gmp');
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
@ -102,14 +108,16 @@ public function test_install_extension(): void
|
||||
'server' => $this->server,
|
||||
'version' => '8.2',
|
||||
'extension' => 'gmp',
|
||||
]))->assertSessionHasNoErrors();
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
|
||||
Bus::assertDispatched(InstallPHPExtension::class);
|
||||
$php = $this->server->php('8.2');
|
||||
|
||||
$this->assertContains('gmp', $php->type_data['extensions']);
|
||||
}
|
||||
|
||||
public function test_extension_already_installed(): void
|
||||
{
|
||||
Bus::fake();
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
@ -126,7 +134,5 @@ public function test_extension_already_installed(): void
|
||||
'version' => '8.2',
|
||||
'extension' => 'gmp',
|
||||
]))->assertSessionHasErrors();
|
||||
|
||||
Bus::assertNotDispatched(InstallPHPExtension::class);
|
||||
}
|
||||
}
|
||||
|
@ -4,23 +4,19 @@
|
||||
|
||||
use App\Models\Project;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use JsonException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ProjectsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_create_project(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(route('projects.create'), [
|
||||
'name' => 'test',
|
||||
])->assertSessionHasNoErrors();
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseHas('projects', [
|
||||
'name' => 'test',
|
||||
@ -39,9 +35,6 @@ public function test_see_projects_list(): void
|
||||
->assertSee($project->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_delete_project(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
@ -51,16 +44,13 @@ public function test_delete_project(): void
|
||||
]);
|
||||
|
||||
$this->delete(route('projects.delete', $project))
|
||||
->assertSessionHasNoErrors();
|
||||
->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseMissing('projects', [
|
||||
'id' => $project->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_edit_project(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
@ -71,7 +61,7 @@ public function test_edit_project(): void
|
||||
|
||||
$this->post(route('projects.update', $project), [
|
||||
'name' => 'new-name',
|
||||
])->assertSessionHasNoErrors();
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseHas('projects', [
|
||||
'id' => $project->id,
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Enums\QueueStatus;
|
||||
use App\Facades\SSH;
|
||||
use App\Models\Queue;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
@ -32,6 +33,8 @@ public function test_see_queues()
|
||||
|
||||
public function test_delete_queue()
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$queue = Queue::factory()->create([
|
||||
@ -47,14 +50,15 @@ public function test_delete_queue()
|
||||
])
|
||||
)->assertRedirect();
|
||||
|
||||
$this->assertDatabaseHas('queues', [
|
||||
$this->assertDatabaseMissing('queues', [
|
||||
'id' => $queue->id,
|
||||
'status' => QueueStatus::DELETING,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_create_queue()
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(
|
||||
@ -79,7 +83,7 @@ public function test_create_queue()
|
||||
'auto_start' => 1,
|
||||
'auto_restart' => 1,
|
||||
'numprocs' => 1,
|
||||
'status' => QueueStatus::CREATING,
|
||||
'status' => QueueStatus::RUNNING,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,9 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Enums\SshKeyStatus;
|
||||
use App\Jobs\SshKey\DeleteSshKeyFromServer;
|
||||
use App\Jobs\SshKey\DeploySshKeyToServer;
|
||||
use App\Facades\SSH;
|
||||
use App\Models\SshKey;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ServerKeysTest extends TestCase
|
||||
@ -34,7 +32,7 @@ public function test_see_server_keys()
|
||||
|
||||
public function test_delete_ssh_key()
|
||||
{
|
||||
Bus::fake();
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
@ -50,18 +48,15 @@ public function test_delete_ssh_key()
|
||||
|
||||
$this->delete(route('servers.ssh-keys.destroy', [$this->server, $sshKey]));
|
||||
|
||||
$this->assertDatabaseHas('server_ssh_keys', [
|
||||
$this->assertDatabaseMissing('server_ssh_keys', [
|
||||
'server_id' => $this->server->id,
|
||||
'ssh_key_id' => $sshKey->id,
|
||||
'status' => SshKeyStatus::DELETING,
|
||||
]);
|
||||
|
||||
Bus::assertDispatched(DeleteSshKeyFromServer::class);
|
||||
}
|
||||
|
||||
public function test_add_new_ssh_key()
|
||||
{
|
||||
Bus::fake();
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
@ -72,15 +67,13 @@ public function test_add_new_ssh_key()
|
||||
|
||||
$this->assertDatabaseHas('server_ssh_keys', [
|
||||
'server_id' => $this->server->id,
|
||||
'status' => SshKeyStatus::ADDING,
|
||||
'status' => SshKeyStatus::ADDED,
|
||||
]);
|
||||
|
||||
Bus::assertDispatched(DeploySshKeyToServer::class);
|
||||
}
|
||||
|
||||
public function test_add_existing_key()
|
||||
{
|
||||
Bus::fake();
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
@ -96,9 +89,7 @@ public function test_add_existing_key()
|
||||
|
||||
$this->assertDatabaseHas('server_ssh_keys', [
|
||||
'server_id' => $this->server->id,
|
||||
'status' => SshKeyStatus::ADDING,
|
||||
'status' => SshKeyStatus::ADDED,
|
||||
]);
|
||||
|
||||
Bus::assertDispatched(DeploySshKeyToServer::class);
|
||||
}
|
||||
}
|
||||
|
@ -5,16 +5,12 @@
|
||||
use App\Enums\ServerProvider;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use JsonException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ServerProvidersTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_connect_hetzner(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
@ -25,7 +21,7 @@ public function test_connect_hetzner(): void
|
||||
'provider' => ServerProvider::HETZNER,
|
||||
'name' => 'profile',
|
||||
'token' => 'token',
|
||||
])->assertSessionHasNoErrors();
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseHas('server_providers', [
|
||||
'provider' => ServerProvider::HETZNER,
|
||||
@ -45,9 +41,6 @@ public function test_see_providers_list(): void
|
||||
->assertSee($provider->profile);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_delete_provider(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
@ -57,7 +50,7 @@ public function test_delete_provider(): void
|
||||
]);
|
||||
|
||||
$this->delete(route('server-providers.delete', $provider->id))
|
||||
->assertSessionHasNoErrors();
|
||||
->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseMissing('server_providers', [
|
||||
'id' => $provider->id,
|
||||
|
@ -7,11 +7,10 @@
|
||||
use App\Enums\ServerProvider;
|
||||
use App\Enums\ServerStatus;
|
||||
use App\Enums\ServerType;
|
||||
use App\Enums\ServiceStatus;
|
||||
use App\Enums\Webserver;
|
||||
use App\Jobs\Installation\Initialize;
|
||||
use App\Facades\SSH;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use JsonException;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@ -21,14 +20,11 @@ class ServerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_create_custom_server(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Bus::fake();
|
||||
SSH::fake('Active: active'); // fake output for service installations
|
||||
|
||||
$this->post(route('servers.create'), [
|
||||
'type' => ServerType::REGULAR,
|
||||
@ -40,14 +36,57 @@ public function test_create_custom_server(): void
|
||||
'webserver' => Webserver::NGINX,
|
||||
'database' => Database::MYSQL80,
|
||||
'php' => '8.2',
|
||||
])->assertSessionHasNoErrors();
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseHas('servers', [
|
||||
'name' => 'test',
|
||||
'ip' => '1.1.1.1',
|
||||
'status' => ServerStatus::INSTALLING,
|
||||
'status' => ServerStatus::READY,
|
||||
]);
|
||||
|
||||
Bus::assertDispatched(Initialize::class);
|
||||
$this->assertDatabaseHas('services', [
|
||||
'server_id' => 1,
|
||||
'type' => 'php',
|
||||
'version' => '8.2',
|
||||
'status' => ServiceStatus::READY,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('services', [
|
||||
'server_id' => 1,
|
||||
'type' => 'webserver',
|
||||
'name' => 'nginx',
|
||||
'version' => 'latest',
|
||||
'status' => ServiceStatus::READY,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('services', [
|
||||
'server_id' => 1,
|
||||
'type' => 'database',
|
||||
'name' => 'mysql',
|
||||
'version' => '8.0',
|
||||
'status' => ServiceStatus::READY,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('services', [
|
||||
'server_id' => 1,
|
||||
'type' => 'firewall',
|
||||
'name' => 'ufw',
|
||||
'version' => 'latest',
|
||||
'status' => ServiceStatus::READY,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_delete_server(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
SSH::fake();
|
||||
|
||||
$this->delete(route('servers.delete', $this->server))
|
||||
->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseMissing('servers', [
|
||||
'id' => $this->server->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,8 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Enums\ServiceStatus;
|
||||
use App\Jobs\Installation\InstallPHPMyAdmin as InstallationInstallPHPMyAdmin;
|
||||
use App\Jobs\Installation\UninstallPHPMyAdmin;
|
||||
use App\Jobs\Service\Manage;
|
||||
use App\Models\Service;
|
||||
use App\Facades\SSH;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ServicesTest extends TestCase
|
||||
@ -36,14 +32,16 @@ public function test_restart_service(string $name): void
|
||||
|
||||
$service = $this->server->services()->where('name', $name)->firstOrFail();
|
||||
|
||||
Bus::fake();
|
||||
SSH::fake('Active: active');
|
||||
|
||||
$this->get(route('servers.services.restart', [
|
||||
'server' => $this->server,
|
||||
'service' => $service,
|
||||
]))->assertSessionHasNoErrors();
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
|
||||
Bus::assertDispatched(Manage::class);
|
||||
$service->refresh();
|
||||
|
||||
$this->assertEquals(ServiceStatus::READY, $service->status);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,16 +51,18 @@ public function test_stop_service(string $name): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$service = $this->server->services()->where('name', $name)->first();
|
||||
$service = $this->server->services()->where('name', $name)->firstOrFail();
|
||||
|
||||
Bus::fake();
|
||||
SSH::fake('Active: inactive');
|
||||
|
||||
$this->get(route('servers.services.stop', [
|
||||
'server' => $this->server,
|
||||
'service' => $service,
|
||||
]))->assertSessionHasNoErrors();
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
|
||||
Bus::assertDispatched(Manage::class);
|
||||
$service->refresh();
|
||||
|
||||
$this->assertEquals(ServiceStatus::STOPPED, $service->status);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,52 +72,81 @@ public function test_start_service(string $name): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$service = $this->server->services()->where('name', $name)->first();
|
||||
$service = $this->server->services()->where('name', $name)->firstOrFail();
|
||||
|
||||
$service->status = ServiceStatus::STOPPED;
|
||||
$service->save();
|
||||
|
||||
Bus::fake();
|
||||
SSH::fake('Active: active');
|
||||
|
||||
$this->get(route('servers.services.start', [
|
||||
'server' => $this->server,
|
||||
'service' => $service,
|
||||
]))->assertSessionHasNoErrors();
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
|
||||
Bus::assertDispatched(Manage::class);
|
||||
$service->refresh();
|
||||
|
||||
$this->assertEquals(ServiceStatus::READY, $service->status);
|
||||
}
|
||||
|
||||
public function test_install_phpmyadmin(): void
|
||||
/**
|
||||
* @dataProvider data
|
||||
*/
|
||||
public function test_failed_to_start_service(string $name): void
|
||||
{
|
||||
$this->markTestSkipped('PHPMyAdmin is depricated');
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Bus::fake();
|
||||
$service = $this->server->services()->where('name', $name)->firstOrFail();
|
||||
|
||||
Bus::assertDispatched(InstallationInstallPHPMyAdmin::class);
|
||||
SSH::fake('Active: inactive');
|
||||
|
||||
$this->get(route('servers.services.start', [
|
||||
'server' => $this->server,
|
||||
'service' => $service,
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
|
||||
$service->refresh();
|
||||
|
||||
$this->assertEquals(ServiceStatus::FAILED, $service->status);
|
||||
}
|
||||
|
||||
public function test_uninstall_phpmyadmin(): void
|
||||
/**
|
||||
* @dataProvider data
|
||||
*/
|
||||
public function test_failed_to_restart_service(string $name): void
|
||||
{
|
||||
$this->markTestSkipped('PHPMyAdmin is depricated');
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$service = Service::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
'type' => 'phpmyadmin',
|
||||
'type_data' => [
|
||||
'allowed_ip' => '0.0.0.0',
|
||||
'port' => '5433',
|
||||
'php' => '8.1',
|
||||
],
|
||||
'name' => 'phpmyadmin',
|
||||
'version' => '5.1.2',
|
||||
'status' => ServiceStatus::READY,
|
||||
'is_default' => 1,
|
||||
$service = $this->server->services()->where('name', $name)->firstOrFail();
|
||||
|
||||
]);
|
||||
SSH::fake('Active: inactive');
|
||||
|
||||
Bus::fake();
|
||||
$this->get(route('servers.services.restart', [
|
||||
'server' => $this->server,
|
||||
'service' => $service,
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
|
||||
Bus::assertDispatched(UninstallPHPMyAdmin::class);
|
||||
$service->refresh();
|
||||
|
||||
$this->assertEquals(ServiceStatus::FAILED, $service->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data
|
||||
*/
|
||||
public function test_failed_to_stop_service(string $name): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$service = $this->server->services()->where('name', $name)->firstOrFail();
|
||||
|
||||
SSH::fake('Active: active');
|
||||
|
||||
$this->get(route('servers.services.stop', [
|
||||
'server' => $this->server,
|
||||
'service' => $service,
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
|
||||
$service->refresh();
|
||||
|
||||
$this->assertEquals(ServiceStatus::FAILED, $service->status);
|
||||
}
|
||||
|
||||
public static function data(): array
|
||||
|
@ -6,10 +6,8 @@
|
||||
use App\Enums\SiteType;
|
||||
use App\Enums\SourceControl;
|
||||
use App\Facades\SSH;
|
||||
use App\Jobs\Site\CreateVHost;
|
||||
use App\Models\Site;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
@ -22,9 +20,12 @@ class SitesTest extends TestCase
|
||||
*/
|
||||
public function test_create_site(array $inputs): void
|
||||
{
|
||||
Bus::fake();
|
||||
SSH::fake();
|
||||
|
||||
Http::fake();
|
||||
Http::fake([
|
||||
'https://api.github.com/repos/*' => Http::response([
|
||||
], 201),
|
||||
]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
@ -39,11 +40,9 @@ public function test_create_site(array $inputs): void
|
||||
'server' => $this->server,
|
||||
]), $inputs)->assertSessionDoesntHaveErrors();
|
||||
|
||||
Bus::assertDispatched(CreateVHost::class);
|
||||
|
||||
$this->assertDatabaseHas('sites', [
|
||||
'domain' => 'example.com',
|
||||
'status' => SiteStatus::INSTALLING,
|
||||
'status' => SiteStatus::READY,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -64,7 +63,7 @@ public function test_see_sites_list(): void
|
||||
|
||||
public function test_delete_site(): void
|
||||
{
|
||||
Bus::fake();
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
@ -77,15 +76,15 @@ public function test_delete_site(): void
|
||||
'site' => $site,
|
||||
]))->assertRedirect();
|
||||
|
||||
Bus::assertDispatched(\App\Jobs\Site\DeleteSite::class);
|
||||
|
||||
$site->refresh();
|
||||
|
||||
$this->assertEquals(SiteStatus::DELETING, $site->status);
|
||||
$this->assertDatabaseMissing('sites', [
|
||||
'id' => $site->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_change_php_version(): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$site = Site::factory()->create([
|
||||
@ -117,7 +116,7 @@ public function test_update_v_host(): void
|
||||
$this->get(route('servers.sites.settings.vhost', [
|
||||
'server' => $this->server,
|
||||
'site' => $site,
|
||||
]))->assertSessionHasNoErrors();
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
}
|
||||
|
||||
public static function create_data(): array
|
||||
|
@ -33,7 +33,7 @@ public function test_connect_provider(string $provider, ?string $customUrl): voi
|
||||
$input['url'] = $customUrl;
|
||||
}
|
||||
$this->post(route('source-controls.connect'), $input)
|
||||
->assertSessionHasNoErrors();
|
||||
->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseHas('source_controls', [
|
||||
'provider' => $provider,
|
||||
@ -57,7 +57,7 @@ public function test_delete_provider(string $provider): void
|
||||
]);
|
||||
|
||||
$this->delete(route('source-controls.delete', $sourceControl->id))
|
||||
->assertSessionHasNoErrors();
|
||||
->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseMissing('source_controls', [
|
||||
'id' => $sourceControl->id,
|
||||
|
@ -4,16 +4,12 @@
|
||||
|
||||
use App\Models\SshKey;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use JsonException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SshKeysTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_create_ssh_key(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
@ -21,7 +17,7 @@ public function test_create_ssh_key(): void
|
||||
$this->post(route('ssh-keys.add'), [
|
||||
'name' => 'test',
|
||||
'public_key' => 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIpNLTGK9Tjom/BWDSUGPl+nafzlHDTYW7hdI4yZ5ew18JH4JW9jbhUFrviQzM7xlELEVf4h9lFX5QVkbPppSwg0cda3Pbv7kOdJ/MTyBlWXFCR+HAo3FXRitBqxiX1nKhXpHAZsMciLq8V6RjsNAQwdsdMFvSlVK/7XAt3FaoJoAsncM1Q9x5+3V0Ww68/eIFmb1zuUFljQJKprrX88XypNDvjYNby6vw/Pb0rwert/EnmZ+AW4OZPnTPI89ZPmVMLuayrD2cE86Z/il8b+gw3r3+1nKatmIkjn2so1d01QraTlMqVSsbxNrRFi9wrf+M7Q== test@test.local',
|
||||
])->assertSessionHasNoErrors();
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
}
|
||||
|
||||
public function test_get_public_keys_list(): void
|
||||
@ -36,9 +32,6 @@ public function test_get_public_keys_list(): void
|
||||
->assertSee($key->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_delete_key(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
@ -48,7 +41,7 @@ public function test_delete_key(): void
|
||||
]);
|
||||
|
||||
$this->delete(route('ssh-keys.delete', $key->id))
|
||||
->assertSessionHasNoErrors();
|
||||
->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseMissing('ssh_keys', [
|
||||
'id' => $key->id,
|
||||
|
@ -4,11 +4,9 @@
|
||||
|
||||
use App\Enums\SslStatus;
|
||||
use App\Enums\SslType;
|
||||
use App\Jobs\Ssl\Deploy;
|
||||
use App\Jobs\Ssl\Remove;
|
||||
use App\Facades\SSH;
|
||||
use App\Models\Ssl;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SslTest extends TestCase
|
||||
@ -45,7 +43,7 @@ public function test_see_ssls_list_with_no_ssls()
|
||||
|
||||
public function test_create_ssl()
|
||||
{
|
||||
Bus::fake();
|
||||
SSH::fake('Successfully received certificate');
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
@ -59,15 +57,13 @@ public function test_create_ssl()
|
||||
$this->assertDatabaseHas('ssls', [
|
||||
'site_id' => $this->site->id,
|
||||
'type' => SslType::LETSENCRYPT,
|
||||
'status' => SslStatus::CREATING,
|
||||
'status' => SslStatus::CREATED,
|
||||
]);
|
||||
|
||||
Bus::assertDispatched(Deploy::class);
|
||||
}
|
||||
|
||||
public function test_delete_ssl()
|
||||
{
|
||||
Bus::fake();
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
@ -81,11 +77,8 @@ public function test_delete_ssl()
|
||||
'ssl' => $ssl,
|
||||
]))->assertRedirect();
|
||||
|
||||
$this->assertDatabaseHas('ssls', [
|
||||
$this->assertDatabaseMissing('ssls', [
|
||||
'id' => $ssl->id,
|
||||
'status' => SslStatus::DELETING,
|
||||
]);
|
||||
|
||||
Bus::assertDispatched(Remove::class);
|
||||
}
|
||||
}
|
||||
|
@ -5,16 +5,12 @@
|
||||
use App\Enums\StorageProvider;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use JsonException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class StorageProvidersTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_connect_dropbox(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
@ -25,7 +21,7 @@ public function test_connect_dropbox(): void
|
||||
'provider' => StorageProvider::DROPBOX,
|
||||
'name' => 'profile',
|
||||
'token' => 'token',
|
||||
])->assertSessionHasNoErrors();
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseHas('storage_providers', [
|
||||
'provider' => StorageProvider::DROPBOX,
|
||||
@ -46,9 +42,6 @@ public function test_see_providers_list(): void
|
||||
->assertSee($provider->profile);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_delete_provider(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
@ -58,7 +51,7 @@ public function test_delete_provider(): void
|
||||
]);
|
||||
|
||||
$this->delete(route('storage-providers.delete', $provider->id))
|
||||
->assertSessionHasNoErrors();
|
||||
->assertSessionDoesntHaveErrors();
|
||||
|
||||
$this->assertDatabaseMissing('storage_providers', [
|
||||
'id' => $provider->id,
|
||||
|
@ -26,6 +26,9 @@ public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
config()->set('queue.connections.ssh.driver', 'sync');
|
||||
config()->set('filesystems.disks.key-pairs.root', storage_path('app/key-pairs-test'));
|
||||
|
||||
$this->user = User::factory()->create();
|
||||
|
||||
$this->setupServer();
|
||||
@ -41,6 +44,11 @@ private function setupServer(): void
|
||||
'user_id' => $this->user->id,
|
||||
]);
|
||||
|
||||
$keys = $this->server->sshKey();
|
||||
if (! File::exists($keys['public_key_path']) || ! File::exists($keys['private_key_path'])) {
|
||||
$this->server->provider()->generateKeyPair();
|
||||
}
|
||||
|
||||
$this->server->type()->createServices([
|
||||
'webserver' => Webserver::NGINX,
|
||||
'database' => Database::MYSQL80,
|
||||
@ -57,21 +65,25 @@ private function setupSite(): void
|
||||
/** @var SourceControl $sourceControl */
|
||||
$sourceControl = SourceControl::factory()->github()->create();
|
||||
$this->site = Site::factory()->create([
|
||||
'domain' => 'vito.test',
|
||||
'aliases' => ['www.vito.test'],
|
||||
'server_id' => $this->server->id,
|
||||
'source_control_id' => $sourceControl->id,
|
||||
'repository' => 'organization/repository',
|
||||
'path' => '/home/vito/vito.test',
|
||||
'web_directory' => 'public',
|
||||
'branch' => 'main',
|
||||
]);
|
||||
}
|
||||
|
||||
private function setupKeys(): void
|
||||
{
|
||||
config()->set('core.ssh_public_key_name', 'ssh-public.key');
|
||||
config()->set('core.ssh_private_key_name', 'ssh-private.pem');
|
||||
if (! File::exists(storage_path(config('core.ssh_public_key_name')))) {
|
||||
File::put(storage_path(config('core.ssh_public_key_name')), 'public_key');
|
||||
}
|
||||
if (! File::exists(storage_path(config('core.ssh_private_key_name')))) {
|
||||
File::put(storage_path(config('core.ssh_private_key_name')), 'private_key');
|
||||
config()->set('core.ssh_public_key_name', 'test-key.pub');
|
||||
config()->set('core.ssh_private_key_name', 'test-key');
|
||||
$publicKeypath = storage_path(config('core.ssh_public_key_name'));
|
||||
$privateKeyPath = storage_path(config('core.ssh_private_key_name'));
|
||||
if (! File::exists($publicKeypath) || ! File::exists($privateKeyPath)) {
|
||||
generate_key_pair(storage_path('test-key'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace Tests\Unit\NotificationChannels;
|
||||
|
||||
use App\Mail\NotificationMail;
|
||||
use App\Models\NotificationChannel;
|
||||
use App\NotificationChannels\Email;
|
||||
use App\NotificationChannels\Email\NotificationMail;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\CronJob;
|
||||
|
||||
use App\SSHCommands\CronJob\UpdateCronJobsCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UpdateCronJobsCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new UpdateCronJobsCommand('vito', 'ls -la');
|
||||
|
||||
$this->assertStringContainsString("echo 'ls -la' | sudo -u vito crontab -;", $command->content());
|
||||
|
||||
$this->assertStringContainsString('sudo -u vito crontab -l;', $command->content());
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Database;
|
||||
|
||||
use App\SSHCommands\Database\BackupDatabaseCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BackupDatabaseCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new BackupDatabaseCommand('mysql', 'test', 'test');
|
||||
|
||||
$this->assertStringContainsString('sudo DEBIAN_FRONTEND=noninteractive mysqldump -u root test > test.sql;', $command->content());
|
||||
|
||||
$this->assertStringContainsString('DEBIAN_FRONTEND=noninteractive zip test.zip test.sql;', $command->content());
|
||||
|
||||
$this->assertStringContainsString('rm test.sql;', $command->content());
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Database;
|
||||
|
||||
use App\SSHCommands\Database\CreateCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new CreateCommand('mysql', 'test');
|
||||
|
||||
$this->assertStringContainsString('sudo mysql -e "CREATE DATABASE IF NOT EXISTS test CHARACTER SET utf8 COLLATE utf8_general_ci";', $command->content());
|
||||
|
||||
$this->assertStringContainsString('echo "Command executed"', $command->content());
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Database;
|
||||
|
||||
use App\SSHCommands\Database\CreateUserCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateUserCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new CreateUserCommand('mysql', 'user', 'password', '%');
|
||||
|
||||
$this->assertStringContainsString('sudo mysql -e "CREATE USER IF NOT EXISTS \'user\'@\'%\' IDENTIFIED BY \'password\'";', $command->content());
|
||||
|
||||
$this->assertStringContainsString('sudo mysql -e "FLUSH PRIVILEGES";', $command->content());
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Database;
|
||||
|
||||
use App\SSHCommands\Database\DeleteCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new DeleteCommand('mysql', 'test');
|
||||
|
||||
$this->assertStringContainsString('sudo mysql -e "DROP DATABASE IF EXISTS test";', $command->content());
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Database;
|
||||
|
||||
use App\SSHCommands\Database\DeleteUserCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteUserCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new DeleteUserCommand('mysql', 'user', '%');
|
||||
|
||||
$this->assertStringContainsString('sudo mysql -e "DROP USER IF EXISTS \'user\'@\'%\'";', $command->content());
|
||||
|
||||
$this->assertStringContainsString('sudo mysql -e "FLUSH PRIVILEGES";', $command->content());
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Database;
|
||||
|
||||
use App\SSHCommands\Database\InstallMariadbCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InstallMariadbCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new InstallMariadbCommand();
|
||||
|
||||
$expected = <<<EOD
|
||||
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
|
||||
|
||||
chmod +x mariadb_repo_setup
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive ./mariadb_repo_setup \
|
||||
--mariadb-server-version="mariadb-10.3"
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt update
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt install mariadb-server mariadb-backup -y
|
||||
|
||||
sudo service mysql start
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Database;
|
||||
|
||||
use App\SSHCommands\Database\InstallMysqlCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InstallMysqlCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command_mysql8()
|
||||
{
|
||||
$command = new InstallMysqlCommand('8.0');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive dpkg -i mysql-apt-config_0.8.22-1_all.deb
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt update
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt install mysql-server -y
|
||||
|
||||
sudo service mysql enable
|
||||
|
||||
sudo service mysql start
|
||||
|
||||
if ! sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
|
||||
public function test_generate_command_mysql5()
|
||||
{
|
||||
$command = new InstallMysqlCommand('5.7');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt install mysql-server -y
|
||||
|
||||
sudo service mysql enable
|
||||
|
||||
sudo service mysql start
|
||||
|
||||
if ! sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Database;
|
||||
|
||||
use App\SSHCommands\Database\LinkCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LinkCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new LinkCommand('mysql', 'user', '%', 'test');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! sudo mysql -e "GRANT ALL PRIVILEGES ON test.* TO 'user'@'%'"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "Linking to test finished"
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Database;
|
||||
|
||||
use App\SSHCommands\Database\UnlinkCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UnlinkCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new UnlinkCommand('mysql', 'user', '%');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! sudo mysql -e "REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'user'@'%'"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "Command executed"
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Firewall;
|
||||
|
||||
use App\SSHCommands\Firewall\AddRuleCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AddRuleCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new AddRuleCommand('ufw', 'allow', 'tcp', '1080', '0.0.0.0', '0');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! sudo ufw allow from 0.0.0.0/0 to any proto tcp port 1080; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo ufw reload; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo service ufw restart; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Firewall;
|
||||
|
||||
use App\SSHCommands\Firewall\InstallUfwCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InstallUfwCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new InstallUfwCommand();
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! sudo ufw default deny incoming; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo ufw default allow outgoing; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo ufw allow from 0.0.0.0/0 to any proto tcp port 22; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo ufw allow from 0.0.0.0/0 to any proto tcp port 80; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo ufw allow from 0.0.0.0/0 to any proto tcp port 443; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo ufw --force enable; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo ufw reload; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Firewall;
|
||||
|
||||
use App\SSHCommands\Firewall\RemoveRuleCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RemoveRuleCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new RemoveRuleCommand('ufw', 'allow', 'tcp', '1080', '0.0.0.0', '0');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! sudo ufw delete allow from 0.0.0.0/0 to any proto tcp port 1080; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo ufw reload; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo service ufw restart; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Installation;
|
||||
|
||||
use App\SSHCommands\Installation\InstallNodejsCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InstallNodejsCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new InstallNodejsCommand();
|
||||
|
||||
$expected = <<<'EOD'
|
||||
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -;
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt update
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt install nodejs -y
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Installation;
|
||||
|
||||
use App\SSHCommands\Installation\InstallRedisCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InstallRedisCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new InstallRedisCommand();
|
||||
|
||||
$expected = <<<'EOD'
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt install redis-server -y
|
||||
|
||||
sudo sed -i 's/bind 127.0.0.1 ::1/bind 0.0.0.0/g' /etc/redis/redis.conf
|
||||
|
||||
sudo service redis enable
|
||||
|
||||
sudo service redis start
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Installation;
|
||||
|
||||
use App\SSHCommands\Installation\InstallRequirementsCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InstallRequirementsCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new InstallRequirementsCommand('user@example.com', 'user');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt install -y software-properties-common curl zip unzip git gcc
|
||||
git config --global user.email "user@example.com"
|
||||
git config --global user.name "user"
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Nginx;
|
||||
|
||||
use App\SSHCommands\Nginx\ChangeNginxPHPVersionCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ChangeNginxPHPVersionCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new ChangeNginxPHPVersionCommand('example.com', '7.1', '8.2');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! sudo sed -i 's/php7.1/php8.2/g' /etc/nginx/sites-available/example.com; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo service nginx restart; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "PHP Version Changed to 8.2"
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Nginx;
|
||||
|
||||
use App\SSHCommands\Nginx\CreateNginxVHostCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateNginxVHostCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new CreateNginxVHostCommand('example.com', '/home/vito/example.com', '__the__vhost__');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! rm -rf /home/vito/example.com; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! mkdir /home/vito/example.com; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo chown -R 755 /home/vito/example.com; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! echo '' | sudo tee /etc/nginx/conf.d/example.com_redirects; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! echo '__the__vhost__' | sudo tee /etc/nginx/sites-available/example.com; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo service nginx restart; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Nginx;
|
||||
|
||||
use App\SSHCommands\Nginx\DeleteNginxSiteCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteNginxSiteCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new DeleteNginxSiteCommand('example.com', '/home/vito/example.com');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
rm -rf /home/vito/example.com
|
||||
|
||||
sudo rm /etc/nginx/sites-available/example.com
|
||||
|
||||
sudo rm /etc/nginx/sites-enabled/example.com
|
||||
|
||||
echo "Site deleted"
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,115 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Nginx;
|
||||
|
||||
use App\SSHCommands\Nginx\InstallNginxCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InstallNginxCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new InstallNginxCommand();
|
||||
|
||||
$nginxConfig = <<<'EOD'
|
||||
user vito;
|
||||
worker_processes auto;
|
||||
pid /run/nginx.pid;
|
||||
include /etc/nginx/modules-enabled/*.conf;
|
||||
|
||||
events {
|
||||
worker_connections 768;
|
||||
# multi_accept on;
|
||||
}
|
||||
|
||||
http {
|
||||
|
||||
##
|
||||
# Basic Settings
|
||||
##
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
# server_tokens off;
|
||||
|
||||
# server_names_hash_bucket_size 64;
|
||||
# server_name_in_redirect off;
|
||||
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
##
|
||||
# SSL Settings
|
||||
##
|
||||
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
|
||||
ssl_prefer_server_ciphers on;
|
||||
|
||||
##
|
||||
# Logging Settings
|
||||
##
|
||||
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
|
||||
##
|
||||
# Gzip Settings
|
||||
##
|
||||
|
||||
gzip on;
|
||||
|
||||
# gzip_vary on;
|
||||
# gzip_proxied any;
|
||||
# gzip_comp_level 6;
|
||||
# gzip_buffers 16 8k;
|
||||
# gzip_http_version 1.1;
|
||||
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||
|
||||
##
|
||||
# Virtual Host Configs
|
||||
##
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
include /etc/nginx/sites-enabled/*;
|
||||
}
|
||||
|
||||
|
||||
#mail {
|
||||
# # See sample authentication script at:
|
||||
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
|
||||
#
|
||||
# # auth_http localhost/auth.php;
|
||||
# # pop3_capabilities "TOP" "USER";
|
||||
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
|
||||
#
|
||||
# server {
|
||||
# listen localhost:110;
|
||||
# protocol pop3;
|
||||
# proxy on;
|
||||
# }
|
||||
#
|
||||
# server {
|
||||
# listen localhost:143;
|
||||
# protocol imap;
|
||||
# proxy on;
|
||||
# }
|
||||
#}
|
||||
|
||||
EOD;
|
||||
|
||||
$expected = <<<EOD
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt install nginx -y
|
||||
|
||||
if ! echo '$nginxConfig' | sudo tee /etc/nginx/nginx.conf; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
sudo service nginx start
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Nginx;
|
||||
|
||||
use App\SSHCommands\Nginx\UpdateNginxRedirectsCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UpdateNginxRedirectsCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new UpdateNginxRedirectsCommand('example.com', '__redirects__');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! echo '__redirects__' | sudo tee /etc/nginx/conf.d/example.com_redirects; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo service nginx restart; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Nginx;
|
||||
|
||||
use App\SSHCommands\Nginx\UpdateNginxVHostCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UpdateNginxVHostCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new UpdateNginxVHostCommand('example.com', '/home/vito/example.com', '__vhost__');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! echo '__vhost__' | sudo tee /etc/nginx/sites-available/example.com; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo service nginx restart; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\PHP;
|
||||
|
||||
use App\SSHCommands\PHP\ChangeDefaultPHPCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ChangeDefaultPHPCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new ChangeDefaultPHPCommand('8.2');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! sudo rm /usr/bin/php; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo ln -s /usr/bin/php8.2 /usr/bin/php; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "Default php is: "
|
||||
|
||||
php -v
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\PHP;
|
||||
|
||||
use App\SSHCommands\PHP\GetPHPIniCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class GetPHPIniCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new GetPHPIniCommand('8.2');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
cat /etc/php/8.2/cli/php.ini
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\PHP;
|
||||
|
||||
use App\SSHCommands\PHP\InstallComposerCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InstallComposerCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new InstallComposerCommand();
|
||||
|
||||
$expected = <<<'EOD'
|
||||
cd ~
|
||||
|
||||
curl -sS https://getcomposer.org/installer -o composer-setup.php
|
||||
|
||||
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
|
||||
|
||||
composer
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\PHP;
|
||||
|
||||
use App\SSHCommands\PHP\InstallPHPCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InstallPHPCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new InstallPHPCommand('8.1');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
sudo add-apt-repository ppa:ondrej/php -y
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt update
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt install -y php8.1 php8.1-fpm php8.1-mbstring php8.1-mysql php8.1-mcrypt php8.1-gd php8.1-xml php8.1-curl php8.1-gettext php8.1-zip php8.1-bcmath php8.1-soap php8.1-redis
|
||||
|
||||
if ! sudo sed -i 's/www-data/vito/g' /etc/php/8.1/fpm/pool.d/www.conf; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
sudo service php8.1-fpm enable
|
||||
|
||||
sudo service php8.1-fpm start
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\PHP;
|
||||
|
||||
use App\SSHCommands\PHP\InstallPHPExtensionCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InstallPHPExtensionCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new InstallPHPExtensionCommand('8.1', 'imagick');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
sudo apt install -y php8.1-imagick
|
||||
|
||||
sudo service php8.1-fpm restart
|
||||
|
||||
php8.1 -m
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\PHP;
|
||||
|
||||
use App\SSHCommands\PHP\UninstallPHPCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UninstallPHPCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new UninstallPHPCommand('8.1');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
sudo service php8.1-fpm stop
|
||||
|
||||
if ! sudo DEBIAN_FRONTEND=noninteractive apt remove -y php8.1 php8.1-fpm php8.1-mbstring php8.1-mysql php8.1-mcrypt php8.1-gd php8.1-xml php8.1-curl php8.1-gettext php8.1-zip php8.1-bcmath php8.1-soap php8.1-redis; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\PHPMyAdmin;
|
||||
|
||||
use App\SSHCommands\PHPMyAdmin\CreateNginxPHPMyAdminVHostCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateNginxPHPMyAdminVHostCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new CreateNginxPHPMyAdminVHostCommand('__vhost__');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! sudo chown -R 755 /home/vito/phpmyadmin; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! echo '__vhost__' | sudo tee /etc/nginx/sites-available/phpmyadmin; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo ln -s /etc/nginx/sites-available/phpmyadmin /etc/nginx/sites-enabled/; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo service nginx restart; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "PHPMyAdmin vhost created"
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\PHPMyAdmin;
|
||||
|
||||
use App\SSHCommands\PHPMyAdmin\DeleteNginxPHPMyAdminVHostCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteNginxPHPMyAdminVHostCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new DeleteNginxPHPMyAdminVHostCommand('/home/vito/phpmyadmin');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
sudo rm -rf /home/vito/phpmyadmin
|
||||
|
||||
sudo rm /etc/nginx/sites-available/phpmyadmin
|
||||
|
||||
sudo rm /etc/nginx/sites-enabled/phpmyadmin
|
||||
|
||||
if ! sudo service nginx restart; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "PHPMyAdmin deleted"
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\PHPMyAdmin;
|
||||
|
||||
use App\SSHCommands\PHPMyAdmin\DownloadPHPMyAdminCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DownloadPHPMyAdminCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new DownloadPHPMyAdminCommand();
|
||||
|
||||
$expected = <<<'EOD'
|
||||
sudo rm -rf phpmyadmin
|
||||
|
||||
if ! wget https://files.phpmyadmin.net/phpMyAdmin/5.1.2/phpMyAdmin-5.1.2-all-languages.zip; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! unzip phpMyAdmin-5.1.2-all-languages.zip; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! rm -rf phpMyAdmin-5.1.2-all-languages.zip; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! mv phpMyAdmin-5.1.2-all-languages phpmyadmin; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! mv phpmyadmin/config.sample.inc.php phpmyadmin/config.inc.php; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\SSL;
|
||||
|
||||
use App\SSHCommands\SSL\CreateCustomSSLCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateCustomSSLCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new CreateCustomSSLCommand('/home/vito/example.com', 'cert', 'pk', '/etc/cert', '/etc/pk');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! sudo mkdir /home/vito/example.com; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! echo cert | sudo tee /etc/cert; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! echo pk | sudo tee /etc/pk; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "Successfully received certificate."
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\SSL;
|
||||
|
||||
use App\SSHCommands\SSL\CreateLetsencryptSSLCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateLetsencryptSSLCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new CreateLetsencryptSSLCommand('info@example.com', 'example.com', 'public');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! sudo certbot certonly --force-renewal --nginx --noninteractive --agree-tos --cert-name example.com -m info@example.com -d example.com --verbose; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\SSL;
|
||||
|
||||
use App\SSHCommands\SSL\InstallCertbotCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InstallCertbotCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new InstallCertbotCommand();
|
||||
|
||||
$expected = <<<'EOD'
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt install certbot python3-certbot-nginx -y
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\SSL;
|
||||
|
||||
use App\SSHCommands\SSL\RemoveSSLCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RemoveSSLCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new RemoveSSLCommand('/etc/letsencrypt/');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
sudo rm -rf /etc/letsencrypt/*
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Service;
|
||||
|
||||
use App\SSHCommands\Service\RestartServiceCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RestartServiceCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new RestartServiceCommand('nginx');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
sudo service nginx restart
|
||||
|
||||
sudo service nginx status | cat
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Service;
|
||||
|
||||
use App\SSHCommands\Service\ServiceStatusCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ServiceStatusCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new ServiceStatusCommand('nginx');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
sudo service nginx status | cat
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Service;
|
||||
|
||||
use App\SSHCommands\Service\StartServiceCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class StartServiceCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new StartServiceCommand('nginx');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
sudo service nginx start
|
||||
|
||||
sudo service nginx status | cat
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Service;
|
||||
|
||||
use App\SSHCommands\Service\StopServiceCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class StopServiceCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new StopServiceCommand('nginx');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
sudo service nginx stop
|
||||
|
||||
sudo service nginx status | cat
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Storage;
|
||||
|
||||
use App\SSHCommands\Storage\DownloadFromDropboxCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DownloadFromDropboxCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new DownloadFromDropboxCommand('src', 'dest', 'token');
|
||||
|
||||
$expected = <<<EOD
|
||||
curl -o dest --location --request POST 'https://content.dropboxapi.com/2/files/download' \
|
||||
--header 'Accept: application/json' \
|
||||
--header 'Dropbox-API-Arg: {"path":"src"}' \
|
||||
--header 'Authorization: Bearer token'
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Storage;
|
||||
|
||||
use App\SSHCommands\Storage\DownloadFromFTPCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DownloadFromFTPCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new DownloadFromFTPCommand(
|
||||
'src',
|
||||
'dest',
|
||||
'1.1.1.1',
|
||||
'21',
|
||||
'username',
|
||||
'password',
|
||||
false,
|
||||
true,
|
||||
);
|
||||
|
||||
$expected = <<<'EOD'
|
||||
curl --ftp-pasv -u "username:password" ftp://1.1.1.1:21/src -o "dest"
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Storage;
|
||||
|
||||
use App\SSHCommands\Storage\UploadToDropboxCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UploadToDropboxCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new UploadToDropboxCommand('src', 'dest', 'token');
|
||||
|
||||
$expected = <<<EOD
|
||||
curl -sb --location --request POST 'https://content.dropboxapi.com/2/files/upload' \
|
||||
--header 'Accept: application/json' \
|
||||
--header 'Dropbox-API-Arg: {"path":"dest"}' \
|
||||
--header 'Content-Type: text/plain; charset=dropbox-cors-hack' \
|
||||
--header 'Authorization: Bearer token' \
|
||||
--data-binary '@src'
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Storage;
|
||||
|
||||
use App\SSHCommands\Storage\UploadToFTPCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UploadToFTPCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new UploadToFTPCommand(
|
||||
'src',
|
||||
'dest',
|
||||
'1.1.1.1',
|
||||
'21',
|
||||
'username',
|
||||
'password',
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$expected = <<<'EOD'
|
||||
curl --ftp-pasv -T "src" -u "username:password" ftps://1.1.1.1:21/dest
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Supervisor;
|
||||
|
||||
use App\SSHCommands\Supervisor\CreateWorkerCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateWorkerCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new CreateWorkerCommand('1', 'config');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
mkdir -p ~/.logs
|
||||
|
||||
mkdir -p ~/.logs/workers
|
||||
|
||||
touch ~/.logs/workers/1.log
|
||||
|
||||
if ! echo 'config' | sudo tee /etc/supervisor/conf.d/1.conf; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo supervisorctl reread; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo supervisorctl update; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo supervisorctl start 1:*; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Supervisor;
|
||||
|
||||
use App\SSHCommands\Supervisor\DeleteWorkerCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteWorkerCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new DeleteWorkerCommand('1');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! sudo supervisorctl stop 1:*; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo rm -rf ~/.logs/workers/1.log; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo rm -rf /etc/supervisor/conf.d/1.conf; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo supervisorctl reread; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! sudo supervisorctl update; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Supervisor;
|
||||
|
||||
use App\SSHCommands\Supervisor\InstallSupervisorCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InstallSupervisorCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new InstallSupervisorCommand();
|
||||
|
||||
$expected = <<<'EOD'
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get install supervisor -y
|
||||
|
||||
sudo service supervisor enable
|
||||
|
||||
sudo service supervisor start
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Supervisor;
|
||||
|
||||
use App\SSHCommands\Supervisor\RestartWorkerCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RestartWorkerCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new RestartWorkerCommand('1');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! sudo supervisorctl restart 1:*; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Supervisor;
|
||||
|
||||
use App\SSHCommands\Supervisor\StartWorkerCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class StartWorkerCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new StartWorkerCommand('1');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! sudo supervisorctl start 1:*; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Supervisor;
|
||||
|
||||
use App\SSHCommands\Supervisor\StopWorkerCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class StopWorkerCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new StopWorkerCommand('1');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! sudo supervisorctl stop 1:*; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\System;
|
||||
|
||||
use App\SSHCommands\System\CreateUserCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateUserCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new CreateUserCommand('vito', 'password', 'key');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
echo "key" | sudo tee -a /home/root/.ssh/authorized_keys
|
||||
sudo useradd -p $(openssl passwd -1 password) vito
|
||||
sudo usermod -aG sudo vito
|
||||
echo "vito ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers
|
||||
sudo mkdir /home/vito
|
||||
sudo mkdir /home/vito/.ssh
|
||||
echo "key" | sudo tee -a /home/vito/.ssh/authorized_keys
|
||||
sudo chown -R vito:vito /home/vito
|
||||
sudo chsh -s /bin/bash vito
|
||||
sudo su - vito -c "ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa" <<< y
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\System;
|
||||
|
||||
use App\SSHCommands\System\DeleteSshKeyCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteSshKeyCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new DeleteSshKeyCommand('key');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
sudo sed -i 's/key//g' ~/.ssh/authorized_keys
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\System;
|
||||
|
||||
use App\SSHCommands\System\DeploySshKeyCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeploySshKeyCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new DeploySshKeyCommand('key');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! echo 'key' | sudo tee -a ~/.ssh/authorized_keys; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\System;
|
||||
|
||||
use App\SSHCommands\System\EditFileCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EditFileCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new EditFileCommand('/path/to/file', 'content');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! echo "content" | tee /path/to/file; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\System;
|
||||
|
||||
use App\SSHCommands\System\GenerateSshKeyCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class GenerateSshKeyCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new GenerateSshKeyCommand('key');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/key
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\System;
|
||||
|
||||
use App\SSHCommands\System\GetPublicKeyCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class GetPublicKeyCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new GetPublicKeyCommand();
|
||||
|
||||
$expected = <<<'EOD'
|
||||
cat ~/.ssh/id_rsa.pub
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\System;
|
||||
|
||||
use App\SSHCommands\System\ReadFileCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ReadFileCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new ReadFileCommand('/path');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
cat /path;
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\System;
|
||||
|
||||
use App\SSHCommands\System\ReadSshKeyCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ReadSshKeyCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new ReadSshKeyCommand('name');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
cat ~/.ssh/name.pub
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\System;
|
||||
|
||||
use App\SSHCommands\System\RebootCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RebootCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new RebootCommand();
|
||||
|
||||
$expected = <<<'EOD'
|
||||
echo "Rebooting..."
|
||||
|
||||
sudo reboot
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\System;
|
||||
|
||||
use App\SSHCommands\System\RunScriptCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RunScriptCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new RunScriptCommand('/path', 'script');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! cd /path; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
script
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\System;
|
||||
|
||||
use App\SSHCommands\System\UpgradeCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UpgradeCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new UpgradeCommand();
|
||||
|
||||
$expected = <<<'EOD'
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt clean
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt update
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt upgrade -y
|
||||
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt autoremove -y
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Website;
|
||||
|
||||
use App\SSHCommands\Website\CloneRepositoryCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CloneRepositoryCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new CloneRepositoryCommand('git@github.com-key:vitodeploy/vito.git', 'path', 'main', 'pk_path');
|
||||
|
||||
$expected = <<<EOD
|
||||
echo "Host github.com-pk_path
|
||||
Hostname github.com
|
||||
IdentityFile=~/.ssh/pk_path" >> ~/.ssh/config
|
||||
|
||||
ssh-keyscan -H github.com >> ~/.ssh/known_hosts
|
||||
|
||||
rm -rf path
|
||||
|
||||
if ! git config --global core.fileMode false; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! git clone -b main git@github.com-key:vitodeploy/vito.git path; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! find path -type d -exec chmod 755 {} \;; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! find path -type f -exec chmod 644 {} \;; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! cd path && git config core.fileMode false; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Website;
|
||||
|
||||
use App\SSHCommands\Website\ComposerInstallCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ComposerInstallCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new ComposerInstallCommand('path');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! cd path; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\SSHCommands\Website;
|
||||
|
||||
use App\SSHCommands\Website\UpdateBranchCommand;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UpdateBranchCommandTest extends TestCase
|
||||
{
|
||||
public function test_generate_command()
|
||||
{
|
||||
$command = new UpdateBranchCommand('path', 'main');
|
||||
|
||||
$expected = <<<'EOD'
|
||||
if ! cd path; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! git checkout -f main; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user