|
| 1 | +<?php |
| 2 | +/* (c) Anton Medvedev <anton@medv.io> |
| 3 | + * |
| 4 | + * For the full copyright and license information, please view the LICENSE |
| 5 | + * file that was distributed with this source code. |
| 6 | + */ |
| 7 | + |
| 8 | +namespace Deployer; |
| 9 | + |
| 10 | +use spec\SpecTest; |
| 11 | +use Symfony\Component\Console\Output\Output; |
| 12 | + |
| 13 | +class LocalArchiveTest extends SpecTest |
| 14 | +{ |
| 15 | + public const RECIPE = __DIR__ . '/recipe/local_archive.php'; |
| 16 | + |
| 17 | + public static function setUpBeforeClass(): void |
| 18 | + { |
| 19 | + parent::setUpBeforeClass(); |
| 20 | + putenv('DEPLOYER_LOCAL_WORKER=false'); |
| 21 | + } |
| 22 | + |
| 23 | + public static function tearDownAfterClass(): void |
| 24 | + { |
| 25 | + putenv('DEPLOYER_LOCAL_WORKER=true'); |
| 26 | + parent::tearDownAfterClass(); |
| 27 | + } |
| 28 | + |
| 29 | + public function testParallelLocalArchiveDeploy() |
| 30 | + { |
| 31 | + $this->init(self::RECIPE); |
| 32 | + $this->tester->run([ |
| 33 | + 'deploy', |
| 34 | + 'selector' => 'all', |
| 35 | + '-f' => self::RECIPE, |
| 36 | + ], [ |
| 37 | + 'verbosity' => Output::VERBOSITY_VERBOSE, |
| 38 | + ]); |
| 39 | + |
| 40 | + $display = $this->tester->getDisplay(); |
| 41 | + self::assertEquals(0, $this->tester->getStatusCode(), $display); |
| 42 | + |
| 43 | + // Every host must end up with the archived code, not just the worker |
| 44 | + // that won the race for the shared archive file. |
| 45 | + foreach ($this->deployer->hosts as $host) { |
| 46 | + $deployPath = $host->get('deploy_path'); |
| 47 | + self::assertFileExists($deployPath . '/current/README.md', $display); |
| 48 | + } |
| 49 | + |
| 50 | + // The fix builds the archive in a unique temp file and cleans it up, |
| 51 | + // so nothing is left behind in the local git root. |
| 52 | + $gitRoot = trim((string) shell_exec('git rev-parse --show-toplevel')); |
| 53 | + self::assertFileDoesNotExist($gitRoot . '/archive.tar'); |
| 54 | + } |
| 55 | +} |
0 commit comments