deployer/tests/joy/ParallelTest.php

115 lines
3.6 KiB
PHP
Raw Normal View History

2020-09-29 22:56:26 +02:00
<?php
/* (c) Anton Medvedev <anton@medv.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Deployer;
use Symfony\Component\Console\Output\Output;
2020-10-09 00:15:28 +02:00
class ParallelTest extends AbstractTest
2020-09-29 22:56:26 +02:00
{
2020-10-09 00:15:28 +02:00
const RECIPE = __DIR__ . '/recipe/parallel.php';
2020-09-29 22:56:26 +02:00
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
putenv('DEPLOYER_LOCAL_WORKER=false'); // Allow to start workers. Don't forget to disable it later.
}
public static function tearDownAfterClass(): void
{
putenv('DEPLOYER_LOCAL_WORKER=true');
parent::tearDownAfterClass();
}
public function testWorker()
{
2020-10-09 00:15:28 +02:00
$this->init(self::RECIPE);
2020-09-29 22:56:26 +02:00
$this->tester->run([
'echo',
2020-10-09 00:15:28 +02:00
'-f' => self::RECIPE,
2020-10-07 22:13:50 +02:00
'selector' => 'all'
2020-09-29 22:56:26 +02:00
], [
'verbosity' => Output::VERBOSITY_NORMAL,
]);
self::assertEquals(0, $this->tester->getStatusCode(), $this->tester->getDisplay());
}
public function testServer()
{
2020-10-09 00:15:28 +02:00
$this->init(self::RECIPE);
2020-09-29 22:56:26 +02:00
$this->tester->setInputs(['prod', 'Black bear']);
$this->tester->run([
'ask',
2020-10-09 00:15:28 +02:00
'-f' => self::RECIPE,
2020-09-29 22:56:26 +02:00
], [
'verbosity' => Output::VERBOSITY_NORMAL,
'interactive' => true,
]);
$display = $this->tester->getDisplay();
self::assertEquals(0, $this->tester->getStatusCode(), $display);
self::assertStringContainsString('[prod] Question: What kind of bear is best?', $display);
self::assertStringContainsString('[prod] Black bear', $display);
}
public function testOption()
{
2020-10-09 00:15:28 +02:00
$this->init(self::RECIPE);
2020-09-29 22:56:26 +02:00
$this->tester->run(
[
'echo',
2020-10-07 22:13:50 +02:00
'selector' => 'all',
2020-09-29 22:56:26 +02:00
'-o' => ['greet=Hello'],
2020-10-09 00:15:28 +02:00
'-f' => self::RECIPE,
2020-09-29 22:56:26 +02:00
//'-l' => 1,
],
[
'verbosity' => Output::VERBOSITY_DEBUG,
'interactive' => false,
]
);
$display = $this->tester->getDisplay();
self::assertEquals(0, $this->tester->getStatusCode(), $display);
self::assertStringContainsString('[prod] Hello, prod!', $display);
self::assertStringContainsString('[beta] Hello, beta!', $display);
}
public function testCachedHostConfig()
{
2020-10-09 00:15:28 +02:00
$this->init(self::RECIPE);
2020-09-29 22:56:26 +02:00
$this->tester->run([
'cache_config_test',
2020-10-09 00:15:28 +02:00
'-f' => self::RECIPE,
2020-10-07 22:13:50 +02:00
'selector' => 'all'
2020-09-29 22:56:26 +02:00
], [
'verbosity' => Output::VERBOSITY_NORMAL,
]);
$display = $this->tester->getDisplay();
self::assertEquals(0, $this->tester->getStatusCode(), $display);
2020-10-08 01:04:25 +02:00
self::assertTrue(substr_count($display, 'worker on prod') == 1, $display);
self::assertTrue(substr_count($display, 'worker on beta') == 1, $display);
2020-09-29 22:56:26 +02:00
}
public function testHostConfigFromCallback()
{
$this->init(self::RECIPE);
$this->tester->run([
'host_config_from_callback',
'-f' => self::RECIPE,
'selector' => 'all'
], [
'verbosity' => Output::VERBOSITY_NORMAL,
]);
$display = $this->tester->getDisplay();
self::assertEquals(0, $this->tester->getStatusCode(), $display);
self::assertTrue(substr_count($display, '[prod] config value is from global') == 1, $display);
self::assertTrue(substr_count($display, '[beta] config value is from callback') == 1, $display);
}
2020-09-29 22:56:26 +02:00
}