mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 09:00:18 +01:00 
			
		
		
		
	Add tests
This commit is contained in:
		
							parent
							
								
									0d3c595b18
								
							
						
					
					
						commit
						c14e3bc710
					
				@ -2,6 +2,7 @@ CHANGELOG for 3.X
 | 
				
			|||||||
=================
 | 
					=================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* 3.2.0 (2017-04-xx)
 | 
					* 3.2.0 (2017-04-xx)
 | 
				
			||||||
 | 
					 * [PR#365] New option "from" to define deployment start point
 | 
				
			||||||
 * Allow to define excludes in the global scope.
 | 
					 * Allow to define excludes in the global scope.
 | 
				
			||||||
 * Improve code quality, remove duplications on Symfony Tasks.
 | 
					 * Improve code quality, remove duplications on Symfony Tasks.
 | 
				
			||||||
 * Improve code quality, remove duplications on Composer Tasks.
 | 
					 * Improve code quality, remove duplications on Composer Tasks.
 | 
				
			||||||
 | 
				
			|||||||
@ -68,6 +68,56 @@ class DeployCommandWithReleasesTest extends TestCase
 | 
				
			|||||||
        $this->assertEquals(0, $tester->getStatusCode());
 | 
					        $this->assertEquals(0, $tester->getStatusCode());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testDeploymentWithReleasesWithFromCommands()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-with-from.yml');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $application->getRuntime()->setReleaseId('20170101015120');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /** @var AbstractCommand $command */
 | 
				
			||||||
 | 
					        $command = $application->find('deploy');
 | 
				
			||||||
 | 
					        $this->assertTrue($command instanceof DeployCommand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $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 cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./dist',
 | 
				
			||||||
 | 
					            6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "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 "cd /var/www/test/releases/1234567890 && tar xfzop mageXYZ"',
 | 
				
			||||||
 | 
					            9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
 | 
				
			||||||
 | 
					            10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "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 "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 "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 "cd /var/www/test && ln -snf releases/1234567890 current"',
 | 
				
			||||||
 | 
					            14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
 | 
				
			||||||
 | 
					            15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
 | 
				
			||||||
 | 
					            16 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015111"',
 | 
				
			||||||
 | 
					            17 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015112"',
 | 
				
			||||||
 | 
					            18 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015113"',
 | 
				
			||||||
 | 
					            19 => 'rm /tmp/mageXYZ',
 | 
				
			||||||
 | 
					            20 => 'git checkout master',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 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->assertEquals(0, $tester->getStatusCode());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function testDeploymentWithoutReleasesTarPrepare()
 | 
					    public function testDeploymentWithoutReleasesTarPrepare()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-force-tar1.yml');
 | 
					        $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-force-tar1.yml');
 | 
				
			||||||
 | 
				
			|||||||
@ -55,6 +55,43 @@ class DeployCommandWithoutReleasesTest extends TestCase
 | 
				
			|||||||
        $this->assertEquals(0, $tester->getStatusCode());
 | 
					        $this->assertEquals(0, $tester->getStatusCode());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testDeploymentWithoutReleasesWithFromCommands()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-without-releases-with-from.yml');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /** @var AbstractCommand $command */
 | 
				
			||||||
 | 
					        $command = $application->find('deploy');
 | 
				
			||||||
 | 
					        $this->assertTrue($command instanceof DeployCommand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $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 ./dist tester@testhost:/var/www/test',
 | 
				
			||||||
 | 
					            6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:warmup --env=dev"',
 | 
				
			||||||
 | 
					            7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assets:install web --env=dev --symlink --relative"',
 | 
				
			||||||
 | 
					            8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assetic:dump --env=dev"',
 | 
				
			||||||
 | 
					            9 => 'git checkout master',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 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->assertEquals(0, $tester->getStatusCode());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function testDeploymentFailMidway()
 | 
					    public function testDeploymentFailMidway()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-without-releases.yml');
 | 
					        $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-without-releases.yml');
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										28
									
								
								tests/Resources/testhost-with-from.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								tests/Resources/testhost-with-from.yml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					magephp:
 | 
				
			||||||
 | 
					    log_dir: /tmp
 | 
				
			||||||
 | 
					    environments:
 | 
				
			||||||
 | 
					        test:
 | 
				
			||||||
 | 
					            user: tester
 | 
				
			||||||
 | 
					            branch: test
 | 
				
			||||||
 | 
					            from: ./dist
 | 
				
			||||||
 | 
					            host_path: /var/www/test
 | 
				
			||||||
 | 
					            releases: 4
 | 
				
			||||||
 | 
					            exclude:
 | 
				
			||||||
 | 
					                - ./var/cache/*
 | 
				
			||||||
 | 
					                - ./var/log/*
 | 
				
			||||||
 | 
					                - ./web/app_dev.php
 | 
				
			||||||
 | 
					                -
 | 
				
			||||||
 | 
					                -
 | 
				
			||||||
 | 
					            hosts:
 | 
				
			||||||
 | 
					                - testhost
 | 
				
			||||||
 | 
					            pre-deploy:
 | 
				
			||||||
 | 
					                - git/update
 | 
				
			||||||
 | 
					                - composer/install
 | 
				
			||||||
 | 
					                - composer/dump-autoload
 | 
				
			||||||
 | 
					            on-deploy:
 | 
				
			||||||
 | 
					                - symfony/cache-warmup: { env: 'dev' }
 | 
				
			||||||
 | 
					                - symfony/assets-install: { env: 'dev' }
 | 
				
			||||||
 | 
					                - symfony/assetic-dump: { env: 'dev' }
 | 
				
			||||||
 | 
					            on-release:
 | 
				
			||||||
 | 
					            post-release:
 | 
				
			||||||
 | 
					            post-deploy:
 | 
				
			||||||
							
								
								
									
										25
									
								
								tests/Resources/testhost-without-releases-with-from.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								tests/Resources/testhost-without-releases-with-from.yml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					magephp:
 | 
				
			||||||
 | 
					    log_dir: /tmp
 | 
				
			||||||
 | 
					    environments:
 | 
				
			||||||
 | 
					        test:
 | 
				
			||||||
 | 
					            user: tester
 | 
				
			||||||
 | 
					            branch: test
 | 
				
			||||||
 | 
					            from: ./dist
 | 
				
			||||||
 | 
					            host_path: /var/www/test
 | 
				
			||||||
 | 
					            exclude:
 | 
				
			||||||
 | 
					                - ./var/cache/*
 | 
				
			||||||
 | 
					                - ./var/log/*
 | 
				
			||||||
 | 
					                - ./web/app_dev.php
 | 
				
			||||||
 | 
					            hosts:
 | 
				
			||||||
 | 
					                - testhost
 | 
				
			||||||
 | 
					            pre-deploy:
 | 
				
			||||||
 | 
					                - git/update
 | 
				
			||||||
 | 
					                - composer/install
 | 
				
			||||||
 | 
					                - composer/dump-autoload
 | 
				
			||||||
 | 
					            on-deploy:
 | 
				
			||||||
 | 
					                - symfony/cache-warmup: { env: 'dev' }
 | 
				
			||||||
 | 
					                - symfony/assets-install: { env: 'dev' }
 | 
				
			||||||
 | 
					                - symfony/assetic-dump: { env: 'dev' }
 | 
				
			||||||
 | 
					            on-release:
 | 
				
			||||||
 | 
					            post-release:
 | 
				
			||||||
 | 
					            post-deploy:
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user