[Nostromo] Add tests

This commit is contained in:
Andrés Montañez
2017-01-01 01:28:58 -03:00
parent 74c60f55ef
commit 196f84ceb1
16 changed files with 1957 additions and 17 deletions
+52
View File
@@ -0,0 +1,52 @@
<?php
namespace Mage\Tests\Runtime;
use Symfony\Component\Process\Process;
class ProcessMockup extends Process
{
protected $commandline;
protected $timeout;
public function __construct($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array())
{
$this->commandline = $commandline;
}
public function setTimeout($timeout)
{
$this->timeout = $timeout;
}
public function run($callback = null)
{
}
public function isSuccessful()
{
return true;
}
public function getErrorOutput()
{
return '';
}
public function getOutput()
{
if ($this->commandline == 'git branch | grep "*"') {
return '* master';
}
if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost 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@testhost sh -c \"readlink -f /var/www/test/current\"') {
return '/var/www/test/releases/20170101015120';
}
return '';
}
}
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace Mage\Tests\Runtime;
use Mage\Runtime\Runtime;
use Mage\Runtime\RuntimeInterface;
use Symfony\Component\Process\Process;
class RuntimeMockup extends Runtime
{
protected $ranCommands = [];
public function getRanCommands()
{
return $this->ranCommands;
}
/**
* Generate the Release ID
*
* @return RuntimeInterface
*/
public function generateReleaseId()
{
$this->setReleaseId('1234567890');
return $this;
}
/**
* Execute a command locally
*
* @param string $cmd Command to execute
* @param int $timeout Seconds to wait
* @return Process
*/
public function runLocalCommand($cmd, $timeout = 120)
{
$this->ranCommands[] = $cmd;
$process = new ProcessMockup($cmd);
$process->setTimeout($timeout);
$process->run();
return $process;
}
/**
* Gets a Temporal File name
*
* @return string
*/
public function getTempFile()
{
return '/tmp/mageXYZ';
}
}