Browse Source

[Nostromo] Improve tests.

pull/1/head
Andrés Montañez 8 years ago
parent
commit
5bff78e1cd
  1. 57
      src/Mage/Tests/Command/BuiltIn/DeployCommandMiscTasksTest.php
  2. 15
      src/Mage/Tests/Resources/broken-git-branch.yml
  3. 5
      src/Mage/Tests/Runtime/ProcessMockup.php
  4. 7
      src/Mage/Tests/Runtime/RuntimeMockup.php

57
src/Mage/Tests/Command/BuiltIn/DeployCommandMiscTasksTest.php

@ -97,4 +97,61 @@ class DeployCommandMiscTasksTest extends TestCase
$this->assertEquals(7, $tester->getStatusCode());
$this->assertContains('Invalid task name "invalid/task"', $tester->getDisplay());
}
public function testBrokenGitBranch()
{
$application = new MageApplicationMockup();
$application->configure(__DIR__ . '/../../Resources/broken-git-branch.yml');
/** @var AbstractCommand $command */
$command = $application->find('deploy');
$this->assertTrue($command instanceof DeployCommand);
$tester = new CommandTester($command);
$application->getRuntime()->forceFail('git branch | grep "*"');
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertContains('Running [Git] Change Branch (broken-test) ... FAIL', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
public function testBrokenGitCheckout()
{
$application = new MageApplicationMockup();
$application->configure(__DIR__ . '/../../Resources/broken-git-branch.yml');
/** @var AbstractCommand $command */
$command = $application->find('deploy');
$this->assertTrue($command instanceof DeployCommand);
$tester = new CommandTester($command);
$application->getRuntime()->forceFail('git checkout broken-test');
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertContains('Running [Git] Change Branch (broken-test) ... FAIL', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
public function testBrokenGitUpdate()
{
$application = new MageApplicationMockup();
$application->configure(__DIR__ . '/../../Resources/broken-git-branch.yml');
/** @var AbstractCommand $command */
$command = $application->find('deploy');
$this->assertTrue($command instanceof DeployCommand);
$tester = new CommandTester($command);
$application->getRuntime()->forceFail('git pull');
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertContains('Running [Git] Update ... FAIL', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
}

15
src/Mage/Tests/Resources/broken-git-branch.yml

@ -0,0 +1,15 @@
magephp:
log_dir: /tmp
environments:
test:
user: tester
branch: broken-test
host_path: /var/www/test
exclude:
- ./var/cache/*
- ./var/log/*
- ./web/app_dev.php
hosts:
- githost1
pre-deploy:
- git/update

5
src/Mage/Tests/Runtime/ProcessMockup.php

@ -14,6 +14,7 @@ use Symfony\Component\Process\Process;
class ProcessMockup extends Process
{
public $forceFail = [];
protected $commandline;
protected $timeout;
protected $success = true;
@ -30,6 +31,10 @@ class ProcessMockup extends Process
public function run($callback = null)
{
if (in_array($this->commandline, $this->forceFail)) {
$this->success = false;
}
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;
}

7
src/Mage/Tests/Runtime/RuntimeMockup.php

@ -16,6 +16,7 @@ use Symfony\Component\Process\Process;
class RuntimeMockup extends Runtime
{
protected $ranCommands = [];
protected $forceFail = [];
public function getRanCommands()
{
@ -45,6 +46,7 @@ class RuntimeMockup extends Runtime
$this->ranCommands[] = $cmd;
$process = new ProcessMockup($cmd);
$process->forceFail = $this->forceFail;
$process->setTimeout($timeout);
$process->run();
@ -72,4 +74,9 @@ class RuntimeMockup extends Runtime
$this->environment = $environment;
return $this;
}
public function forceFail($cmd)
{
$this->forceFail[] = $cmd;
}
}

Loading…
Cancel
Save