mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 14:06:15 +00:00
fix notification chanels and more tests (#108)
* fix notification chanels and more tests * fix code style
This commit is contained in:
@ -0,0 +1,28 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
46
tests/Unit/SSHCommands/Nginx/CreateNginxVHostCommandTest.php
Normal file
46
tests/Unit/SSHCommands/Nginx/CreateNginxVHostCommandTest.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
26
tests/Unit/SSHCommands/Nginx/DeleteNginxSiteCommandTest.php
Normal file
26
tests/Unit/SSHCommands/Nginx/DeleteNginxSiteCommandTest.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
115
tests/Unit/SSHCommands/Nginx/InstallNginxCommandTest.php
Normal file
115
tests/Unit/SSHCommands/Nginx/InstallNginxCommandTest.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
26
tests/Unit/SSHCommands/Nginx/UpdateNginxVHostCommandTest.php
Normal file
26
tests/Unit/SSHCommands/Nginx/UpdateNginxVHostCommandTest.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user