mirror of https://github.com/hauke68/Magallanes
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.9 KiB
97 lines
3.9 KiB
8 years ago
|
<?php
|
||
8 years ago
|
/*
|
||
|
* This file is part of the Magallanes package.
|
||
|
*
|
||
|
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||
|
*
|
||
|
* For the full copyright and license information, please view the LICENSE
|
||
|
* file that was distributed with this source code.
|
||
|
*/
|
||
|
|
||
8 years ago
|
namespace Mage\Tests\Command\BuiltIn\Releases;
|
||
|
|
||
|
use Mage\Command\BuiltIn\Releases\RollbackCommand;
|
||
|
use Mage\Command\AbstractCommand;
|
||
8 years ago
|
use Mage\Tests\MageApplicationMockup;
|
||
8 years ago
|
use Symfony\Component\Console\Tester\CommandTester;
|
||
8 years ago
|
use PHPUnit_Framework_TestCase as TestCase;
|
||
8 years ago
|
|
||
|
class RollbackCommandTest extends TestCase
|
||
|
{
|
||
|
public function testRollbackReleaseCommands()
|
||
|
{
|
||
8 years ago
|
$application = new MageApplicationMockup();
|
||
|
$application->configure(__DIR__ . '/../../../Resources/testhost.yml');
|
||
8 years ago
|
|
||
|
/** @var AbstractCommand $command */
|
||
|
$command = $application->find('releases:rollback');
|
||
8 years ago
|
$this->assertTrue($command instanceof RollbackCommand);
|
||
8 years ago
|
|
||
|
$tester = new CommandTester($command);
|
||
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
|
||
|
|
||
8 years ago
|
$ranCommands = $application->getRuntime()->getRanCommands();
|
||
8 years ago
|
|
||
8 years ago
|
$testCase = array(
|
||
8 years ago
|
0 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"ls -1 /var/www/test/releases\\"',
|
||
|
1 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& ln -snf releases/20170101015115 current\\"',
|
||
|
);
|
||
|
|
||
|
// Check total of Executed Commands
|
||
8 years ago
|
$this->assertEquals(count($testCase), count($ranCommands));
|
||
8 years ago
|
|
||
|
// Check Generated Commands
|
||
|
foreach ($testCase as $index => $command) {
|
||
8 years ago
|
$this->assertEquals($command, $ranCommands[$index]);
|
||
8 years ago
|
}
|
||
|
}
|
||
8 years ago
|
|
||
|
public function testRollbackReleaseWithInvalidEnvironment()
|
||
|
{
|
||
|
$application = new MageApplicationMockup();
|
||
|
$application->configure(__DIR__ . '/../../../Resources/testhost.yml');
|
||
|
|
||
|
/** @var AbstractCommand $command */
|
||
|
$command = $application->find('releases:rollback');
|
||
|
$this->assertTrue($command instanceof RollbackCommand);
|
||
|
|
||
|
$tester = new CommandTester($command);
|
||
|
$tester->execute(['command' => $command->getName(), 'environment' => 'developers', 'release' => '20170101015115']);
|
||
|
|
||
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||
|
$this->assertContains('The environment "developers" does not exists.', $tester->getDisplay());
|
||
|
}
|
||
|
|
||
|
public function testRollbackReleaseWithoutReleases()
|
||
|
{
|
||
|
$application = new MageApplicationMockup();
|
||
|
$application->configure(__DIR__ . '/../../../Resources/testhost-without-releases.yml');
|
||
|
|
||
|
/** @var AbstractCommand $command */
|
||
|
$command = $application->find('releases:rollback');
|
||
|
$this->assertTrue($command instanceof RollbackCommand);
|
||
|
|
||
8 years ago
|
$tester = new CommandTester($command);
|
||
|
|
||
8 years ago
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
|
||
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||
|
$this->assertContains('Releases are not enabled', $tester->getDisplay());
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
public function testRollbackReleaseNotAvailable()
|
||
|
{
|
||
|
$application = new MageApplicationMockup();
|
||
|
$application->configure(__DIR__ . '/../../../Resources/testhost-not-have-release.yml');
|
||
|
|
||
|
/** @var AbstractCommand $command */
|
||
|
$command = $application->find('releases:rollback');
|
||
|
$this->assertTrue($command instanceof RollbackCommand);
|
||
|
|
||
|
$tester = new CommandTester($command);
|
||
|
|
||
8 years ago
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
|
||
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||
|
$this->assertContains('Release "20170101015115" is not available on all hosts', $tester->getDisplay());
|
||
8 years ago
|
}
|
||
8 years ago
|
}
|