mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 09:00:18 +01:00 
			
		
		
		
	[Nostromo] Improve tests and coverage
This commit is contained in:
		
							parent
							
								
									962c33259d
								
							
						
					
					
						commit
						6e130b0285
					
				@ -148,4 +148,98 @@ class DeployCommandWithReleasesTest extends TestCase
 | 
				
			|||||||
        $this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
 | 
					        $this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
 | 
				
			||||||
        $this->assertNotEquals(0, $tester->getStatusCode());
 | 
					        $this->assertNotEquals(0, $tester->getStatusCode());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testDeploymentFailToCopy()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $application = new MageApplicationMockup();
 | 
				
			||||||
 | 
					        $application->configure(__DIR__ . '/../../Resources/testhost.yml');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $application->getRuntime()->setReleaseId('20170101015120');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /** @var AbstractCommand $command */
 | 
				
			||||||
 | 
					        $command = $application->find('deploy');
 | 
				
			||||||
 | 
					        $this->assertTrue($command instanceof DeployCommand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $application->getRuntime()->forceFail('scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $tester = new CommandTester($command);
 | 
				
			||||||
 | 
					        $tester->execute(['command' => $command->getName(), 'environment' => 'test']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $application->getRuntime()->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'git branch | grep "*"',
 | 
				
			||||||
 | 
					            1 => 'git checkout test',
 | 
				
			||||||
 | 
					            2 => 'git pull',
 | 
				
			||||||
 | 
					            3 => 'composer install --optimize-autoloader',
 | 
				
			||||||
 | 
					            4 => 'composer dump-autoload --optimize',
 | 
				
			||||||
 | 
					            5 => 'tar cfz /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./',
 | 
				
			||||||
 | 
					            6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"mkdir -p /var/www/test/releases/1234567890\\"',
 | 
				
			||||||
 | 
					            7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('Running [Deploy] Copying files with TarGZ ... FAIL', $tester->getDisplay());
 | 
				
			||||||
 | 
					        $this->assertNotEquals(0, $tester->getStatusCode());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testDeploymentFailCleanup()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $application = new MageApplicationMockup();
 | 
				
			||||||
 | 
					        $application->configure(__DIR__ . '/../../Resources/testhost.yml');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $application->getRuntime()->setReleaseId('20170101015120');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /** @var AbstractCommand $command */
 | 
				
			||||||
 | 
					        $command = $application->find('deploy');
 | 
				
			||||||
 | 
					        $this->assertTrue($command instanceof DeployCommand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $application->getRuntime()->forceFail('rm /tmp/mageXYZ');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $tester = new CommandTester($command);
 | 
				
			||||||
 | 
					        $tester->execute(['command' => $command->getName(), 'environment' => 'test']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $application->getRuntime()->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'git branch | grep "*"',
 | 
				
			||||||
 | 
					            1 => 'git checkout test',
 | 
				
			||||||
 | 
					            2 => 'git pull',
 | 
				
			||||||
 | 
					            3 => 'composer install --optimize-autoloader',
 | 
				
			||||||
 | 
					            4 => 'composer dump-autoload --optimize',
 | 
				
			||||||
 | 
					            5 => 'tar cfz /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./',
 | 
				
			||||||
 | 
					            6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"mkdir -p /var/www/test/releases/1234567890\\"',
 | 
				
			||||||
 | 
					            7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
 | 
				
			||||||
 | 
					            8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& tar xfz mageXYZ\\"',
 | 
				
			||||||
 | 
					            9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"rm /var/www/test/releases/1234567890/mageXYZ\\"',
 | 
				
			||||||
 | 
					            10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& bin/console cache:warmup --env=dev\\"',
 | 
				
			||||||
 | 
					            11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& bin/console assets:install web --env=dev --symlink --relative\\"',
 | 
				
			||||||
 | 
					            12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& bin/console assetic:dump --env=dev\\"',
 | 
				
			||||||
 | 
					            13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& ln -snf releases/1234567890 current\\"',
 | 
				
			||||||
 | 
					            14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"ls -1 /var/www/test/releases\\"',
 | 
				
			||||||
 | 
					            15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"rm -rf /var/www/test/releases/20170101015110\\"',
 | 
				
			||||||
 | 
					            16 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"rm -rf /var/www/test/releases/20170101015111\\"',
 | 
				
			||||||
 | 
					            17 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"rm -rf /var/www/test/releases/20170101015112\\"',
 | 
				
			||||||
 | 
					            18 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"rm -rf /var/www/test/releases/20170101015113\\"',
 | 
				
			||||||
 | 
					            19 => 'rm /tmp/mageXYZ',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('Running [Deploy] Cleanup TarGZ file ... FAIL', $tester->getDisplay());
 | 
				
			||||||
 | 
					        $this->assertNotEquals(0, $tester->getStatusCode());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -55,4 +55,41 @@ class DeployCommandWithoutReleasesTest extends TestCase
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        $this->assertEquals(0, $tester->getStatusCode());
 | 
					        $this->assertEquals(0, $tester->getStatusCode());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testDeploymentFailMidway()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $application = new MageApplicationMockup();
 | 
				
			||||||
 | 
					        $application->configure(__DIR__ . '/../../Resources/testhost-without-releases.yml');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /** @var AbstractCommand $command */
 | 
				
			||||||
 | 
					        $command = $application->find('deploy');
 | 
				
			||||||
 | 
					        $this->assertTrue($command instanceof DeployCommand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $application->getRuntime()->forceFail('rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $tester = new CommandTester($command);
 | 
				
			||||||
 | 
					        $tester->execute(['command' => $command->getName(), 'environment' => 'test']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $application->getRuntime()->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'git branch | grep "*"',
 | 
				
			||||||
 | 
					            1 => 'git checkout test',
 | 
				
			||||||
 | 
					            2 => 'git pull',
 | 
				
			||||||
 | 
					            3 => 'composer install --optimize-autoloader',
 | 
				
			||||||
 | 
					            4 => 'composer dump-autoload --optimize',
 | 
				
			||||||
 | 
					            5 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('Stage "On Deploy" did not finished successfully, halting command.', $tester->getDisplay());
 | 
				
			||||||
 | 
					        $this->assertNotEquals(0, $tester->getStatusCode());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user