mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
code style fix
add command tests
This commit is contained in:
@ -23,7 +23,7 @@ public function test_visit_application()
|
||||
$this->get(
|
||||
route('servers.sites.show', [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site
|
||||
'site' => $this->site,
|
||||
])
|
||||
)
|
||||
->assertOk()
|
||||
@ -44,7 +44,7 @@ public function test_update_deployment_script()
|
||||
|
||||
$this->assertDatabaseHas('deployment_scripts', [
|
||||
'site_id' => $this->site->id,
|
||||
'content' => 'some script'
|
||||
'content' => 'some script',
|
||||
]);
|
||||
|
||||
$this->site->refresh();
|
||||
|
@ -58,7 +58,7 @@ public function test_create_cronjob()
|
||||
'command' => 'ls -la',
|
||||
'user' => 'vito',
|
||||
'frequency' => '* * * * *',
|
||||
'status' => CronjobStatus::CREATING
|
||||
'status' => CronjobStatus::CREATING,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public function test_create_backup(): void
|
||||
|
||||
$storage = StorageProvider::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'provider' => \App\Enums\StorageProvider::DROPBOX
|
||||
'provider' => \App\Enums\StorageProvider::DROPBOX,
|
||||
]);
|
||||
|
||||
Livewire::test(DatabaseBackups::class, ['server' => $this->server])
|
||||
@ -60,7 +60,7 @@ public function test_see_backups_list(): void
|
||||
|
||||
$storage = StorageProvider::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'provider' => \App\Enums\StorageProvider::DROPBOX
|
||||
'provider' => \App\Enums\StorageProvider::DROPBOX,
|
||||
]);
|
||||
|
||||
$backup = Backup::factory()->create([
|
||||
@ -85,7 +85,7 @@ public function test_delete_database(): void
|
||||
|
||||
$storage = StorageProvider::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'provider' => \App\Enums\StorageProvider::DROPBOX
|
||||
'provider' => \App\Enums\StorageProvider::DROPBOX,
|
||||
]);
|
||||
|
||||
$backup = Backup::factory()->create([
|
||||
|
@ -35,7 +35,7 @@ public function test_create_firewall_rule(): void
|
||||
Bus::assertDispatched(AddToServer::class);
|
||||
|
||||
$this->assertDatabaseHas('firewall_rules', [
|
||||
'port' => '1234'
|
||||
'port' => '1234',
|
||||
]);
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ public function test_see_firewall_rules(): void
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$rule = FirewallRule::factory()->create([
|
||||
'server_id' => $this->server->id
|
||||
'server_id' => $this->server->id,
|
||||
]);
|
||||
|
||||
Livewire::test(FirewallRulesList::class, ['server' => $this->server])
|
||||
@ -61,7 +61,7 @@ public function test_delete_firewall_rule(): void
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$rule = FirewallRule::factory()->create([
|
||||
'server_id' => $this->server->id
|
||||
'server_id' => $this->server->id,
|
||||
]);
|
||||
|
||||
Livewire::test(FirewallRulesList::class, ['server' => $this->server])
|
||||
@ -73,7 +73,7 @@ public function test_delete_firewall_rule(): void
|
||||
|
||||
$this->assertDatabaseHas('firewall_rules', [
|
||||
'id' => $rule->id,
|
||||
'status' => FirewallRuleStatus::DELETING
|
||||
'status' => FirewallRuleStatus::DELETING,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public function test_change_default_php_cli(): void
|
||||
],
|
||||
'name' => 'php',
|
||||
'version' => '8.1',
|
||||
'status' => ServiceStatus::READY
|
||||
'status' => ServiceStatus::READY,
|
||||
]);
|
||||
|
||||
Livewire::test(DefaultCli::class, ['server' => $this->server])
|
||||
|
@ -63,7 +63,7 @@ public function test_create_queue()
|
||||
'auto_start' => 1,
|
||||
'auto_restart' => 1,
|
||||
'numprocs' => 1,
|
||||
'status' => QueueStatus::CREATING
|
||||
'status' => QueueStatus::CREATING,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public function test_delete_ssh_key()
|
||||
$this->assertDatabaseHas('server_ssh_keys', [
|
||||
'server_id' => $this->server->id,
|
||||
'ssh_key_id' => $sshKey->id,
|
||||
'status' => SshKeyStatus::DELETING
|
||||
'status' => SshKeyStatus::DELETING,
|
||||
]);
|
||||
|
||||
Bus::assertDispatched(DeleteSshKeyFromServer::class);
|
||||
@ -77,7 +77,7 @@ public function test_add_new_ssh_key()
|
||||
|
||||
$this->assertDatabaseHas('server_ssh_keys', [
|
||||
'server_id' => $this->server->id,
|
||||
'status' => SshKeyStatus::ADDING
|
||||
'status' => SshKeyStatus::ADDING,
|
||||
]);
|
||||
|
||||
Bus::assertDispatched(DeploySshKeyToServer::class);
|
||||
@ -103,7 +103,7 @@ public function test_add_existing_key()
|
||||
|
||||
$this->assertDatabaseHas('server_ssh_keys', [
|
||||
'server_id' => $this->server->id,
|
||||
'status' => SshKeyStatus::ADDING
|
||||
'status' => SshKeyStatus::ADDING,
|
||||
]);
|
||||
|
||||
Bus::assertDispatched(DeploySshKeyToServer::class);
|
||||
|
@ -25,7 +25,7 @@ public function test_see_services_list(): void
|
||||
'supervisor',
|
||||
'redis',
|
||||
'ufw',
|
||||
'php'
|
||||
'php',
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,7 @@
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Http\Livewire\SourceControls\Bitbucket;
|
||||
use App\Http\Livewire\SourceControls\Connect;
|
||||
use App\Http\Livewire\SourceControls\Github;
|
||||
use App\Http\Livewire\SourceControls\Gitlab;
|
||||
use App\Http\Livewire\SourceControls\SourceControlsList;
|
||||
use App\Models\SourceControl;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
@ -48,7 +45,7 @@ public function test_delete_provider(string $provider): void
|
||||
/** @var SourceControl $sourceControl */
|
||||
$sourceControl = SourceControl::factory()->create([
|
||||
'provider' => $provider,
|
||||
'profile' => 'test'
|
||||
'profile' => 'test',
|
||||
]);
|
||||
|
||||
Livewire::test(SourceControlsList::class)
|
||||
|
@ -3,8 +3,8 @@
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Enums\StorageProvider;
|
||||
use App\Http\Livewire\StorageProviders\ProvidersList;
|
||||
use App\Http\Livewire\StorageProviders\ConnectProvider;
|
||||
use App\Http\Livewire\StorageProviders\ProvidersList;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Livewire;
|
||||
@ -39,7 +39,7 @@ public function test_see_providers_list(): void
|
||||
|
||||
$provider = \App\Models\StorageProvider::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'provider' => StorageProvider::DROPBOX
|
||||
'provider' => StorageProvider::DROPBOX,
|
||||
]);
|
||||
|
||||
Livewire::test(ProvidersList::class)
|
||||
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
18
tests/Feature/SSHCommands/Database/CreateCommandTest.php
Normal file
18
tests/Feature/SSHCommands/Database/CreateCommandTest.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
18
tests/Feature/SSHCommands/Database/CreateUserCommandTest.php
Normal file
18
tests/Feature/SSHCommands/Database/CreateUserCommandTest.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
16
tests/Feature/SSHCommands/Database/DeleteCommandTest.php
Normal file
16
tests/Feature/SSHCommands/Database/DeleteCommandTest.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
18
tests/Feature/SSHCommands/Database/DeleteUserCommandTest.php
Normal file
18
tests/Feature/SSHCommands/Database/DeleteUserCommandTest.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
28
tests/Feature/SSHCommands/Database/LinkCommandTest.php
Normal file
28
tests/Feature/SSHCommands/Database/LinkCommandTest.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
24
tests/Feature/SSHCommands/Database/UnlinkCommandTest.php
Normal file
24
tests/Feature/SSHCommands/Database/UnlinkCommandTest.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
30
tests/Feature/SSHCommands/Firewall/AddRuleCommandTest.php
Normal file
30
tests/Feature/SSHCommands/Firewall/AddRuleCommandTest.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
46
tests/Feature/SSHCommands/Firewall/InstallUfwCommandTest.php
Normal file
46
tests/Feature/SSHCommands/Firewall/InstallUfwCommandTest.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
31
tests/Feature/SSHCommands/Firewall/RemoveRuleCommandTest.php
Normal file
31
tests/Feature/SSHCommands/Firewall/RemoveRuleCommandTest.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
115
tests/Feature/SSHCommands/Nginx/InstallNginxCommandTest.php
Normal file
115
tests/Feature/SSHCommands/Nginx/InstallNginxCommandTest.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
20
tests/Feature/SSHCommands/PHP/GetPHPIniCommandTest.php
Normal file
20
tests/Feature/SSHCommands/PHP/GetPHPIniCommandTest.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
26
tests/Feature/SSHCommands/PHP/InstallComposerCommandTest.php
Normal file
26
tests/Feature/SSHCommands/PHP/InstallComposerCommandTest.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
32
tests/Feature/SSHCommands/PHP/InstallPHPCommandTest.php
Normal file
32
tests/Feature/SSHCommands/PHP/InstallPHPCommandTest.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
24
tests/Feature/SSHCommands/PHP/UninstallPHPCommandTest.php
Normal file
24
tests/Feature/SSHCommands/PHP/UninstallPHPCommandTest.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
32
tests/Feature/SSHCommands/SSL/CreateCustomSSLCommandTest.php
Normal file
32
tests/Feature/SSHCommands/SSL/CreateCustomSSLCommandTest.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
20
tests/Feature/SSHCommands/SSL/InstallCertbotCommandTest.php
Normal file
20
tests/Feature/SSHCommands/SSL/InstallCertbotCommandTest.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
20
tests/Feature/SSHCommands/SSL/RemoveSSLCommandTest.php
Normal file
20
tests/Feature/SSHCommands/SSL/RemoveSSLCommandTest.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
22
tests/Feature/SSHCommands/Service/StopServiceCommandTest.php
Normal file
22
tests/Feature/SSHCommands/Service/StopServiceCommandTest.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
30
tests/Feature/SSHCommands/System/CreateUserCommandTest.php
Normal file
30
tests/Feature/SSHCommands/System/CreateUserCommandTest.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
20
tests/Feature/SSHCommands/System/DeleteSshKeyCommandTest.php
Normal file
20
tests/Feature/SSHCommands/System/DeleteSshKeyCommandTest.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
22
tests/Feature/SSHCommands/System/DeploySshKeyCommandTest.php
Normal file
22
tests/Feature/SSHCommands/System/DeploySshKeyCommandTest.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
22
tests/Feature/SSHCommands/System/EditFileCommandTest.php
Normal file
22
tests/Feature/SSHCommands/System/EditFileCommandTest.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
20
tests/Feature/SSHCommands/System/GetPublicKeyCommandTest.php
Normal file
20
tests/Feature/SSHCommands/System/GetPublicKeyCommandTest.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
20
tests/Feature/SSHCommands/System/ReadFileCommandTest.php
Normal file
20
tests/Feature/SSHCommands/System/ReadFileCommandTest.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
20
tests/Feature/SSHCommands/System/ReadSshKeyCommandTest.php
Normal file
20
tests/Feature/SSHCommands/System/ReadSshKeyCommandTest.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
22
tests/Feature/SSHCommands/System/RebootCommandTest.php
Normal file
22
tests/Feature/SSHCommands/System/RebootCommandTest.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
26
tests/Feature/SSHCommands/System/RunScriptCommandTest.php
Normal file
26
tests/Feature/SSHCommands/System/RunScriptCommandTest.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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
|
||||
|
||||
if ! script; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
EOD;
|
||||
|
||||
$this->assertStringContainsString($expected, $command->content());
|
||||
}
|
||||
}
|
26
tests/Feature/SSHCommands/System/UpgradeCommandTest.php
Normal file
26
tests/Feature/SSHCommands/System/UpgradeCommandTest.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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());
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\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