mirror of
https://github.com/hauke68/Magallanes.git
synced 2026-08-29 18:48:56 +02:00
[Nostromo] Improve Tests and Coverage
This commit is contained in:
@@ -89,11 +89,15 @@ class ListCommand extends AbstractCommand
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runRemoteCommand($cmdListReleases, false);
|
||||
if (!$process->isSuccessful()) {
|
||||
throw new RuntimeException(sprintf('Unable to retrieve releases from host %s', $host), 80);
|
||||
throw new RuntimeException(sprintf('Unable to retrieve releases from host "%s"', $host), 80);
|
||||
}
|
||||
|
||||
$releases = explode(PHP_EOL, trim($process->getOutput()));
|
||||
rsort($releases);
|
||||
if (trim($process->getOutput()) != '') {
|
||||
$releases = explode(PHP_EOL, trim($process->getOutput()));
|
||||
rsort($releases);
|
||||
} else {
|
||||
$releases = [];
|
||||
}
|
||||
|
||||
if (count($releases) == 0) {
|
||||
$output->writeln(sprintf(' No releases available on host <fg=black;options=bold>%s</>:', $host));
|
||||
@@ -104,7 +108,7 @@ class ListCommand extends AbstractCommand
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runRemoteCommand($cmdCurrentRelease, false);
|
||||
if (!$process->isSuccessful()) {
|
||||
throw new RuntimeException(sprintf('Unable to retrieve current release from host %s', $host), 85);
|
||||
throw new RuntimeException(sprintf('Unable to retrieve current release from host "%s"', $host), 85);
|
||||
}
|
||||
|
||||
$currentReleaseId = explode('/', trim($process->getOutput()));
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace Mage\Tests\Command\BuiltIn\Releases;
|
||||
|
||||
use Mage\Command\BuiltIn\Releases\ListCommand;
|
||||
use Mage\Runtime\Exception\DeploymentException;
|
||||
use Mage\Runtime\Exception\RuntimeException;
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
@@ -82,4 +83,72 @@ class ListCommandTest extends TestCase
|
||||
$this->assertEquals('Releases are not enabled', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testFailToGetCurrentRelease()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/testhost-fail-get-current.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('releases:list');
|
||||
$this->assertTrue($command instanceof ListCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
try {
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
} catch (Exception $exception) {
|
||||
$this->assertTrue($exception instanceof RuntimeException);
|
||||
$this->assertEquals('Unable to retrieve current release from host "host1"', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testNoReleasesAvailable()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/testhost-no-releases.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('releases:list');
|
||||
$this->assertTrue($command instanceof ListCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
$this->assertContains('No releases available on host host2', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testFailGetReleases()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/testhost-fail-get-releases.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('releases:list');
|
||||
$this->assertTrue($command instanceof ListCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
try {
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
} catch (Exception $exception) {
|
||||
$this->assertTrue($exception instanceof RuntimeException);
|
||||
$this->assertEquals('Unable to retrieve releases from host "host3"', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testNoHosts()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/testhost-no-hosts.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('releases:list');
|
||||
$this->assertTrue($command instanceof ListCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
$this->assertContains('No hosts defined', $tester->getDisplay());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
magephp:
|
||||
log_dir: /tmp
|
||||
environments:
|
||||
test:
|
||||
user: tester
|
||||
branch: test
|
||||
host_path: /var/www/test
|
||||
releases: 4
|
||||
exclude:
|
||||
- ./var/cache/*
|
||||
- ./var/log/*
|
||||
- ./web/app_dev.php
|
||||
hosts:
|
||||
- host1
|
||||
@@ -0,0 +1,14 @@
|
||||
magephp:
|
||||
log_dir: /tmp
|
||||
environments:
|
||||
test:
|
||||
user: tester
|
||||
branch: test
|
||||
host_path: /var/www/test
|
||||
releases: 4
|
||||
exclude:
|
||||
- ./var/cache/*
|
||||
- ./var/log/*
|
||||
- ./web/app_dev.php
|
||||
hosts:
|
||||
- host3
|
||||
@@ -0,0 +1,12 @@
|
||||
magephp:
|
||||
log_dir: /tmp
|
||||
environments:
|
||||
test:
|
||||
user: tester
|
||||
branch: test
|
||||
host_path: /var/www/test
|
||||
releases: 4
|
||||
exclude:
|
||||
- ./var/cache/*
|
||||
- ./var/log/*
|
||||
- ./web/app_dev.php
|
||||
@@ -0,0 +1,14 @@
|
||||
magephp:
|
||||
log_dir: /tmp
|
||||
environments:
|
||||
test:
|
||||
user: tester
|
||||
branch: test
|
||||
host_path: /var/www/test
|
||||
releases: 4
|
||||
exclude:
|
||||
- ./var/cache/*
|
||||
- ./var/log/*
|
||||
- ./web/app_dev.php
|
||||
hosts:
|
||||
- host2
|
||||
@@ -16,6 +16,7 @@ class ProcessMockup extends Process
|
||||
{
|
||||
protected $commandline;
|
||||
protected $timeout;
|
||||
protected $success = true;
|
||||
|
||||
public function __construct($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array())
|
||||
{
|
||||
@@ -29,11 +30,18 @@ class ProcessMockup extends Process
|
||||
|
||||
public function run($callback = null)
|
||||
{
|
||||
if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@host1 sh -c \"readlink -f /var/www/test/current\"') {
|
||||
$this->success = false;
|
||||
}
|
||||
|
||||
if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@host3 sh -c \"ls -1 /var/www/test/releases\"') {
|
||||
$this->success = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function isSuccessful()
|
||||
{
|
||||
return true;
|
||||
return $this->success;
|
||||
}
|
||||
|
||||
public function getErrorOutput()
|
||||
@@ -52,7 +60,15 @@ class ProcessMockup extends Process
|
||||
}
|
||||
|
||||
if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \"readlink -f /var/www/test/current\"') {
|
||||
return '/var/www/test/releases/20170101015120';
|
||||
return '/var/www/test/releases/20170101015117';
|
||||
}
|
||||
|
||||
if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@host1 sh -c \"ls -1 /var/www/test/releases\"') {
|
||||
return implode(PHP_EOL, ['20170101015110', '20170101015111', '20170101015112', '20170101015113', '20170101015114', '20170101015115', '20170101015116', '20170101015117']);
|
||||
}
|
||||
|
||||
if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@host2 sh -c \"ls -1 /var/www/test/releases\"') {
|
||||
return '';
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
Reference in New Issue
Block a user