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:
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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user