From 14736858bfd5dc580fa8a162fba0ac3285a57d33 Mon Sep 17 00:00:00 2001 From: Sean Dietrich Date: Fri, 31 Mar 2017 02:10:31 -0700 Subject: [PATCH 1/7] Rewrite of command to not use the new command but to take advantage of existing data. --- src/Commands/SitePushUpdateCommand.php | 79 ++++++++++++++++---------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/src/Commands/SitePushUpdateCommand.php b/src/Commands/SitePushUpdateCommand.php index 3dd45ef..6e8b04a 100644 --- a/src/Commands/SitePushUpdateCommand.php +++ b/src/Commands/SitePushUpdateCommand.php @@ -7,10 +7,7 @@ use Pantheon\Terminus\Site\SiteAwareTrait; use Pantheon\Terminus\Exceptions\TerminusException; use Pantheon\Terminus\Exceptions\TerminusProcessException; -use Pantheon\Terminus\Commands\Backup; -use Pantheon\Terminus\Commands\Upstream; -use Pantheon\Terminus\Commands\Env; -use Pantheon\Terminus\Commands\Remote\DrushCommand; +use Symfony\Component\Console\Helper\ProgressBar; /** * Class SitePushUpdateCommand @@ -51,48 +48,43 @@ public function pushUpdate($site_id, $options = [ $start = time(); $site = $this->sites->get($site_id); $data = $site->serialize(); - $envs = $site->getEnvironments()->serialize(); $git_location = '/tmp/'.$data['name']; $id = $data['id']; - $drush = new DrushCommand($this->sites); - $drush->setLogger($this->logger); - $drush->setSites($this->sites); - - $backup = new Backup\CreateCommand($this->sites); - $backup->setLogger($this->logger); - $backup->setSites($this->sites); - - $deploy = new Env\DeployCommand($this->sites); - $deploy->setLogger($this->logger); - $deploy->setSites($this->sites); - - $upstream = new Upstream\Updates\ApplyCommand($this->sites); - $upstream->setLogger($this->logger); - $upstream->setSites($this->sites); - $list_envs = ['dev', 'test', 'live']; + $output = $this->output; foreach($list_envs AS $current_env) { - if ($envs[$current_env]['initialized']) { + if ($site->getEnvironments()->get($current_env)->isInitialized()) { if (!$options['skip_backups']) { $this->log()->notice( '{site}: {env} creating backup', ['site' => $data['label'] ,'env' => $current_env] ); - $backup->create($site_id . '.' . $current_env); + $workflow = $site->getEnvironments()->get($current_env)->getBackups()->create(); + + $progress = new ProgressBar($output); + $progress->setFormat('[%bar%] %elapsed:6s% %memory:6s%'); + $progress->start(); + while (!$workflow->checkProgress()) { + $progress->advance(); + } + $progress->finish(); + + $this->log()->notice( + '{site}: {env} backup created', + ['site' => $data['label'] ,'env' => $current_env] + ); } if($current_env == 'dev') { - //Following should only run for the dev environment if ($options['use_git']) { $this->passthru("git clone ssh://codeserver.dev.{$id}@codeserver.dev.{$id}.drush.in:2222/~/repository.git {$git_location}"); $repo = $options['repo']; if(is_null($repo)){ - $upstream_info = explode(':', $data['upstream']); - $upstream_data = $this->session()->getUser()->getUpstreams()->get($upstream_info[0])->serialize(); - $repo = $upstream_data['upstream']; + $upstream_data = $site->getUpstream(); + $repo = $upstream_data->get('url'); } $branch = $options['branch']; @@ -100,7 +92,29 @@ public function pushUpdate($site_id, $options = [ $this->passthru("git --git-dir='{$git_location}/.git' push origin master"); $this->passthru('rm -rf ' . $git_location); }else{ - $upstream->applyUpstreamUpdates($site_id.'.dev', ['accept-upstream' => true]); + $env = $site->getEnvironments()->get('dev'); + $updates = $env->getUpstreamStatus()->getUpdates(); + $count = count($updates); + if ($count) { + $this->log()->notice( + 'Applying {count} upstream update(s) to the {env} environment of {site_id}...', + ['count' => $count, 'env' => $env->id, 'site_id' => $site->get('name'),] + ); + + $workflow = $env->applyUpstreamUpdates(false, true); + + $progress = new ProgressBar($output); + $progress->setFormat('[%bar%] %elapsed:6s% %memory:6s%'); + $progress->start(); + while (!$workflow->checkProgress()) { + $progress->advance(); + } + $progress->finish(); + + $this->log()->notice($workflow->getMessage()); + } else { + $this->log()->warning('There are no available updates for this site.'); + } } }else { //Following command does not run for dev environment @@ -108,8 +122,11 @@ public function pushUpdate($site_id, $options = [ '{site}: {env} deploying updates', ['site' => $data['label'], 'env' => $current_env] ); - $deploy->deploy($site_id . '.' . $current_env, [ - 'note' => $options['message'], + + $site->getEnvironments()->get($current_env)->deploy([ + 'updatedb' => 0, + 'clear_cache' => 0, + 'annotation' => $options['message'] ]); } @@ -124,7 +141,7 @@ public function pushUpdate($site_id, $options = [ $command['message'], ['site' => $data['label'], 'env' => $current_env] ); - $drush->drushCommand($site_id . '.' . $current_env, $command['commands']); + $site->getEnvironments()->get($current_env)->sendCommandViaSsh('drush ' . implode(' ', $command['commands'])); }catch(TerminusProcessException $e){ $this->log()->error( $command['message'], From 48fee30bfae0fadfcabd4dab9bb3048f1e18b533 Mon Sep 17 00:00:00 2001 From: Sean Dietrich Date: Fri, 31 Mar 2017 13:17:32 -0700 Subject: [PATCH 2/7] Updated file to start using conatinered methods and data instead of using new classes --- src/Commands/SitePushUpdateCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Commands/SitePushUpdateCommand.php b/src/Commands/SitePushUpdateCommand.php index 6e8b04a..4abbdca 100644 --- a/src/Commands/SitePushUpdateCommand.php +++ b/src/Commands/SitePushUpdateCommand.php @@ -117,7 +117,6 @@ public function pushUpdate($site_id, $options = [ } } }else { - //Following command does not run for dev environment $this->log()->notice( '{site}: {env} deploying updates', ['site' => $data['label'], 'env' => $current_env] From 80d15f0f569fcbba43d4778ead548c0c4b509b1f Mon Sep 17 00:00:00 2001 From: Sean Dietrich Date: Fri, 31 Mar 2017 14:57:50 -0700 Subject: [PATCH 3/7] CI Integration Added CircleCI build script and added terminus testing script --- circle.yml | 24 ++++++++++++++++++++++++ composer.json | 11 +++++++++++ 2 files changed, 35 insertions(+) create mode 100644 circle.yml diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..89738b4 --- /dev/null +++ b/circle.yml @@ -0,0 +1,24 @@ +# +# Test the Terminus Composer Plugin +# +machine: + timezone: + America/Chicago + php: + version: 7.0.11 + environment: + PATH: $PATH:~/.composer/vendor/bin:~/.config/composer/vendor/bin:$HOME/bin + +dependencies: + cache_directories: + - ~/.composer/cache + override: + - composer install --prefer-dist -n + - composer install-bats + - composer global require -n "consolidation/cgr" + - cgr "pantheon-systems/terminus:dev-master" + post: + - terminus auth:login --machine-token=$TERMINUS_TOKEN +test: + override: + - composer test \ No newline at end of file diff --git a/composer.json b/composer.json index 48614d7..51c969f 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,17 @@ "backup", "deployment" ], + "scripts": { + "install-bats": "if [ ! -f bin/bats ] ; then git clone https://github.com/sstephenson/bats.git; mkdir -p bin; bats/install.sh .; fi", + "bats": "TERMINUS_PLUGINS_DIR=.. bin/bats tests", + "cs": "phpcs --standard=PSR2 -n src", + "cbf": "phpcbf --standard=PSR2 -n src", + "test": [ + "@install-bats", + "@bats", + "@cs" + ] + }, "require": { "php": ">=5.4" }, From 3525c56cb320f2aef0a234324de337ab8a67c216 Mon Sep 17 00:00:00 2001 From: Sean Dietrich Date: Fri, 31 Mar 2017 15:19:50 -0700 Subject: [PATCH 4/7] CI Integration Added test scripts as well as made some code sniffer modifications. --- .gitignore | 6 +- README.md | 1 + composer.json | 3 + composer.lock | 85 +++++++- src/Commands/SitePushUpdateCommand.php | 277 +++++++++++++------------ tests/confirm-install.bats | 17 ++ tests/test-default-no-args.bats | 13 ++ 7 files changed, 262 insertions(+), 140 deletions(-) create mode 100644 tests/confirm-install.bats create mode 100644 tests/test-default-no-args.bats diff --git a/.gitignore b/.gitignore index ccef056..7f10fec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ /vendor/ -.idea \ No newline at end of file +/bats/ +/bin/ +/libexec/ +/share/ +/.idea/ \ No newline at end of file diff --git a/README.md b/README.md index cc804a0..9bd01ee 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Terminus Upstream Deployment Plugin +[![CircleCI](https://circleci.com/gh/terminus-plugin-project/terminus-upstream-deployment-plugin/tree/1.x.svg?style=svg)](https://circleci.com/gh/terminus-plugin-project/terminus-upstream-deployment-plugin/tree/1.x) [![Terminus v1.x Compatible](https://img.shields.io/badge/terminus-v1.x-green.svg)](https://github.com/terminus-plugin-project/terminus-upstream-deployment-plugin/tree/1.x) Terminus plugin to automate the process of updating a site through the upstream. This performs a backup before applying upstream updates. diff --git a/composer.json b/composer.json index 51c969f..4206dc9 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,9 @@ "require": { "php": ">=5.4" }, + "require-dev": { + "squizlabs/php_codesniffer": "^2.7" + }, "support": { "issues": "https://github.com/terminus-plugin-project/terminus-upstream-deployment-plugin/issues" }, diff --git a/composer.lock b/composer.lock index 466cbae..0a71009 100644 --- a/composer.lock +++ b/composer.lock @@ -4,10 +4,89 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "a04edff35581b84b62649aa17e2be784", - "content-hash": "c16657caa9cfab8a08452ae648dec918", + "hash": "a250c12245365f122d492275c8b8dc74", + "content-hash": "ec92c80a2ea4a87dc0c75d7c46c4f7d5", "packages": [], - "packages-dev": [], + "packages-dev": [ + { + "name": "squizlabs/php_codesniffer", + "version": "2.8.1", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "d7cf0d894e8aa4c73712ee4a331cc1eaa37cdc7d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/d7cf0d894e8aa4c73712ee4a331cc1eaa37cdc7d", + "reference": "d7cf0d894e8aa4c73712ee4a331cc1eaa37cdc7d", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "bin": [ + "scripts/phpcs", + "scripts/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + } + }, + "autoload": { + "classmap": [ + "CodeSniffer.php", + "CodeSniffer/CLI.php", + "CodeSniffer/Exception.php", + "CodeSniffer/File.php", + "CodeSniffer/Fixer.php", + "CodeSniffer/Report.php", + "CodeSniffer/Reporting.php", + "CodeSniffer/Sniff.php", + "CodeSniffer/Tokens.php", + "CodeSniffer/Reports/", + "CodeSniffer/Tokenizers/", + "CodeSniffer/DocGenerators/", + "CodeSniffer/Standards/AbstractPatternSniff.php", + "CodeSniffer/Standards/AbstractScopeSniff.php", + "CodeSniffer/Standards/AbstractVariableSniff.php", + "CodeSniffer/Standards/IncorrectPatternException.php", + "CodeSniffer/Standards/Generic/Sniffs/", + "CodeSniffer/Standards/MySource/Sniffs/", + "CodeSniffer/Standards/PEAR/Sniffs/", + "CodeSniffer/Standards/PSR1/Sniffs/", + "CodeSniffer/Standards/PSR2/Sniffs/", + "CodeSniffer/Standards/Squiz/Sniffs/", + "CodeSniffer/Standards/Zend/Sniffs/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "http://www.squizlabs.com/php-codesniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2017-03-01 22:17:45" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], diff --git a/src/Commands/SitePushUpdateCommand.php b/src/Commands/SitePushUpdateCommand.php index 4abbdca..4ecda79 100644 --- a/src/Commands/SitePushUpdateCommand.php +++ b/src/Commands/SitePushUpdateCommand.php @@ -15,13 +15,13 @@ */ class SitePushUpdateCommand extends TerminusCommand implements SiteAwareInterface { - use SiteAwareTrait; + use SiteAwareTrait; /** * Pushed updates from upstream to highest environment * * @authorize - * + * * @command site:update * @aliases update * @@ -38,151 +38,156 @@ class SitePushUpdateCommand extends TerminusCommand implements SiteAwareInterfac * @usage terminus site:update --message="" --use_git --repo="" * @usage terminus site:update --message="" --use_git --repo="" --branch="" */ - public function pushUpdate($site_id, $options = [ + public function pushUpdate($site_id, $options = [ 'message' => '', - 'skip_backups' => FALSE, - 'use_git' => FALSE, - 'repo' => NULL, + 'skip_backups' => false, + 'use_git' => false, + 'repo' => null, 'branch' => 'master' - ]){ - $start = time(); - $site = $this->sites->get($site_id); - $data = $site->serialize(); - $git_location = '/tmp/'.$data['name']; - - $id = $data['id']; - - $list_envs = ['dev', 'test', 'live']; - $output = $this->output; - - foreach($list_envs AS $current_env) { - if ($site->getEnvironments()->get($current_env)->isInitialized()) { - if (!$options['skip_backups']) { - $this->log()->notice( - '{site}: {env} creating backup', - ['site' => $data['label'] ,'env' => $current_env] - ); - $workflow = $site->getEnvironments()->get($current_env)->getBackups()->create(); - - $progress = new ProgressBar($output); - $progress->setFormat('[%bar%] %elapsed:6s% %memory:6s%'); - $progress->start(); - while (!$workflow->checkProgress()) { - $progress->advance(); - } - $progress->finish(); - - $this->log()->notice( - '{site}: {env} backup created', - ['site' => $data['label'] ,'env' => $current_env] - ); - } - - if($current_env == 'dev') { - if ($options['use_git']) { - $this->passthru("git clone ssh://codeserver.dev.{$id}@codeserver.dev.{$id}.drush.in:2222/~/repository.git {$git_location}"); - $repo = $options['repo']; - if(is_null($repo)){ - $upstream_data = $site->getUpstream(); - $repo = $upstream_data->get('url'); - } - $branch = $options['branch']; - - $this->passthru("git --git-dir='{$git_location}/.git' pull --no-edit --commit -X theirs {$repo} {$branch}" ); - $this->passthru("git --git-dir='{$git_location}/.git' push origin master"); - $this->passthru('rm -rf ' . $git_location); - }else{ - $env = $site->getEnvironments()->get('dev'); - $updates = $env->getUpstreamStatus()->getUpdates(); - $count = count($updates); - if ($count) { - $this->log()->notice( - 'Applying {count} upstream update(s) to the {env} environment of {site_id}...', - ['count' => $count, 'env' => $env->id, 'site_id' => $site->get('name'),] - ); - - $workflow = $env->applyUpstreamUpdates(false, true); - - $progress = new ProgressBar($output); - $progress->setFormat('[%bar%] %elapsed:6s% %memory:6s%'); - $progress->start(); - while (!$workflow->checkProgress()) { - $progress->advance(); - } - $progress->finish(); - - $this->log()->notice($workflow->getMessage()); - } else { - $this->log()->warning('There are no available updates for this site.'); + ]) + { + $start = time(); + $site = $this->sites->get($site_id); + $data = $site->serialize(); + $git_location = '/tmp/'.$data['name']; + + $id = $data['id']; + + $list_envs = ['dev', 'test', 'live']; + $output = $this->output; + + $this->log()->notice('{site} Starting', ['site' => $data['label']]); + + foreach ($list_envs as $current_env) { + if ($site->getEnvironments()->get($current_env)->isInitialized()) { + if (!$options['skip_backups']) { + $this->log()->notice( + '{site}: {env} creating backup', + ['site' => $data['label'] ,'env' => $current_env] + ); + $workflow = $site->getEnvironments()->get($current_env)->getBackups()->create(); + + $progress = new ProgressBar($output); + $progress->setFormat('[%bar%] %elapsed:6s% %memory:6s%'); + $progress->start(); + while (!$workflow->checkProgress()) { + $progress->advance(); + } + $progress->finish(); + + $this->log()->notice( + '{site}: {env} backup created', + ['site' => $data['label'] ,'env' => $current_env] + ); + } + + if ($current_env == 'dev') { + if ($options['use_git']) { + $this->passthru("git clone ssh://codeserver.dev.{$id}@codeserver.dev.{$id}.drush.in:2222/~/repository.git {$git_location}"); + $repo = $options['repo']; + if (is_null($repo)) { + $upstream_data = $site->getUpstream(); + $repo = $upstream_data->get('url'); + } + $branch = $options['branch']; + + $this->passthru("git --git-dir='{$git_location}/.git' pull --no-edit --commit -X theirs {$repo} {$branch}"); + $this->passthru("git --git-dir='{$git_location}/.git' push origin master"); + $this->passthru('rm -rf ' . $git_location); + } else { + $env = $site->getEnvironments()->get('dev'); + $updates = $env->getUpstreamStatus()->getUpdates(); + $count = count($updates); + if ($count) { + $this->log()->notice( + 'Applying {count} upstream update(s) to the {env} environment of {site_id}...', + ['count' => $count, 'env' => $env->id, 'site_id' => $site->get('name'),] + ); + + $workflow = $env->applyUpstreamUpdates(false, true); + + $progress = new ProgressBar($output); + $progress->setFormat('[%bar%] %elapsed:6s% %memory:6s%'); + $progress->start(); + while (!$workflow->checkProgress()) { + $progress->advance(); + } + $progress->finish(); + + $this->log()->notice($workflow->getMessage()); + } else { + $this->log()->warning('There are no available updates for this site.'); + } + } + } else { + $this->log()->notice( + '{site}: {env} deploying updates', + ['site' => $data['label'], 'env' => $current_env] + ); + + $site->getEnvironments()->get($current_env)->deploy([ + 'updatedb' => 0, + 'clear_cache' => 0, + 'annotation' => $options['message'] + ]); + } + + if ($data['framework'] == 'drupal') { + $commands = [ + ['message' => '{site}: {env} drush updatedb', 'commands' => ['updatedb' ,'-y']], + ['message' => '{site}: {env} drush clear cache', 'commands' => ['cc' ,'all']] + ]; + foreach ($commands as $command) { + try { + $this->log()->notice( + $command['message'], + ['site' => $data['label'], 'env' => $current_env] + ); + $site->getEnvironments()->get($current_env)->sendCommandViaSsh('drush ' . implode(' ', $command['commands'])); + } catch (TerminusProcessException $e) { + $this->log()->error( + $command['message'], + ['site' => $data['label'], 'env' => $current_env] + ); + } + } + } } - } - }else { - $this->log()->notice( - '{site}: {env} deploying updates', - ['site' => $data['label'], 'env' => $current_env] - ); - - $site->getEnvironments()->get($current_env)->deploy([ - 'updatedb' => 0, - 'clear_cache' => 0, - 'annotation' => $options['message'] - ]); } - if ($data['framework'] == 'drupal') { - $commands = [ - ['message' => '{site}: {env} drush updatedb', 'commands' => ['updatedb' ,'-y']], - ['message' => '{site}: {env} drush clear cache', 'commands' => ['cc' ,'all']] - ]; - foreach($commands AS $command) { - try { - $this->log()->notice( - $command['message'], - ['site' => $data['label'], 'env' => $current_env] - ); - $site->getEnvironments()->get($current_env)->sendCommandViaSsh('drush ' . implode(' ', $command['commands'])); - }catch(TerminusProcessException $e){ - $this->log()->error( - $command['message'], - ['site' => $data['label'], 'env' => $current_env] - ); - } - } - } - } + $this->log()->notice( + 'Completed Upstream Update for {site}', + ['site' => $data['label']] + ); + $end = time(); + + $diff = $end - $start; + $this->log()->notice( + "Started: {start}\r\nEnded: {end}\r\nTotal Time: {hours} hours {minutes} minutes {seconds} seconds", + [ + 'start' => date('Y-m-d H:i:s', $start), + 'end' => date('Y-m-d H:i:s', $end), + 'hours' => intval($diff / 3600), + 'minutes' => intval(($diff % 3600) / 60), + 'seconds' => intval($diff % 60) + ] + ); } - $this->log()->notice( - 'Completed Upstream Update for {site}', ['site' => $data['label']] - ); - $end = time(); - - $diff = $end - $start; - $this->log()->notice( - "Started: {start}\r\nEnded: {end}\r\nTotal Time: {hours} hours {minutes} minutes {seconds} seconds", - [ - 'start' => date('Y-m-d H:i:s', $start), - 'end' => date('Y-m-d H:i:s', $end), - 'hours' => intval($diff / 3600), - 'minutes' => intval(($diff % 3600) / 60), - 'seconds' => intval($diff % 60) - ]); - } - /** * Call passthru; throw an exception on failure. * * @param string $command */ - protected function passthru($command, $loggedCommand = '') - { - $result = 0; - $loggedCommand = empty($loggedCommand) ? $command : $loggedCommand; - // TODO: How noisy do we want to be? - $this->log()->notice("Running {cmd}", ['cmd' => $loggedCommand]); - passthru($command, $result); - if ($result != 0) { - throw new TerminusException('Command `{command}` failed with exit code {status}', ['command' => $loggedCommand, 'status' => $result]); + protected function passthru($command, $loggedCommand = '') + { + $result = 0; + $loggedCommand = empty($loggedCommand) ? $command : $loggedCommand; + // TODO: How noisy do we want to be? + $this->log()->notice("Running {cmd}", ['cmd' => $loggedCommand]); + passthru($command, $result); + if ($result != 0) { + throw new TerminusException('Command `{command}` failed with exit code {status}', ['command' => $loggedCommand, 'status' => $result]); + } } - } } diff --git a/tests/confirm-install.bats b/tests/confirm-install.bats new file mode 100644 index 0000000..50b32ed --- /dev/null +++ b/tests/confirm-install.bats @@ -0,0 +1,17 @@ +#!/usr/bin/env bats + +# +# confirm-install.bats +# +# Ensure that Terminus and the Composer plugin have been installed correctly +# + +@test "confirm terminus version" { + terminus --version +} + +@test "get help on plugin command" { + run terminus help site:update + [[ $output == *"Pushed updates from upstream to highest environment"* ]] + [ "$status" -eq 0 ] +} \ No newline at end of file diff --git a/tests/test-default-no-args.bats b/tests/test-default-no-args.bats new file mode 100644 index 0000000..ecc94f5 --- /dev/null +++ b/tests/test-default-no-args.bats @@ -0,0 +1,13 @@ +#!/usr/bin/env bats + +# +# test-default-no-args.bats +# +# Test to check default command with no arguments +# + +@test "output of plugin 'create' command" { + run terminus site:update --name=$TERMINUS_SITE + [[ "$output" == *"${TERMINUS_SITE} Starting"* ]] + [ "$status" -eq 0 ] +} \ No newline at end of file From d25ec7c2ef10ac353dbae75b48791af7acd20199 Mon Sep 17 00:00:00 2001 From: Sean Dietrich Date: Fri, 31 Mar 2017 15:45:50 -0700 Subject: [PATCH 5/7] Automated Testing Integration with BATS (Bash Automated Testing System) and wrote 2 initial tests. --- tests/test-default-no-args.bats | 10 +++++++--- tests/test-default-skip-backups.bats | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 tests/test-default-skip-backups.bats diff --git a/tests/test-default-no-args.bats b/tests/test-default-no-args.bats index ecc94f5..7e0b385 100644 --- a/tests/test-default-no-args.bats +++ b/tests/test-default-no-args.bats @@ -6,8 +6,12 @@ # Test to check default command with no arguments # -@test "output of plugin 'create' command" { - run terminus site:update --name=$TERMINUS_SITE - [[ "$output" == *"${TERMINUS_SITE} Starting"* ]] +@test "output of plugin 'site:update' command with no arguments" { + run terminus site:update $TERMINUS_SITE + [[ "$output" == *"${TERMINUS_SITE_LABEL} Starting"* ]] + [[ "$output" == *"${TERMINUS_SITE_LABEL}: dev creating backup"* ]] + [[ "$output" == *"${TERMINUS_SITE_LABEL}: dev drusn updatedb"* ]] + [[ "$output" == *"${TERMINUS_SITE_LABEL}: dev drush clear cache"* ]] + [[ "$ouptut" == *"Completed Upstream Update for ${TERMINUS_SITE_LABEL}"* ]] [ "$status" -eq 0 ] } \ No newline at end of file diff --git a/tests/test-default-skip-backups.bats b/tests/test-default-skip-backups.bats new file mode 100644 index 0000000..e9a9145 --- /dev/null +++ b/tests/test-default-skip-backups.bats @@ -0,0 +1,17 @@ +#!/usr/bin/env bats + +# +# test-default-skip-backups.bats +# +# Test to check default command with --skip_backups arguments +# + +@test "output of plugin 'site:update' command with --skip_backups" { + run terminus site:update $TERMINUS_SITE --skip_backups + [[ "$output" == *"${TERMINUS_SITE_LABEL} Starting"* ]] + [[ "$output" != *"${TERMINUS_SITE_LABEL}: dev creating backup"* ]] + [[ "$output" == *"${TERMINUS_SITE_LABEL}: dev updatedb"* ]] + [[ "$output" == *"${TERMINUS_SITE_LABEL}: dev drush clear cache"* ]] + [[ "$ouptut" == *"Completed Upstream Update for ${TERMINUS_SITE_LABEL}"* ]] + [ "$status" -eq 0 ] +} \ No newline at end of file From 18d58063ed1865280e56d696a1bae32250649f85 Mon Sep 17 00:00:00 2001 From: Sean Dietrich Date: Fri, 31 Mar 2017 15:55:23 -0700 Subject: [PATCH 6/7] Fixed typo in bash checking --- tests/test-default-no-args.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-default-no-args.bats b/tests/test-default-no-args.bats index 7e0b385..28afc23 100644 --- a/tests/test-default-no-args.bats +++ b/tests/test-default-no-args.bats @@ -10,7 +10,7 @@ run terminus site:update $TERMINUS_SITE [[ "$output" == *"${TERMINUS_SITE_LABEL} Starting"* ]] [[ "$output" == *"${TERMINUS_SITE_LABEL}: dev creating backup"* ]] - [[ "$output" == *"${TERMINUS_SITE_LABEL}: dev drusn updatedb"* ]] + [[ "$output" == *"${TERMINUS_SITE_LABEL}: dev drush updatedb"* ]] [[ "$output" == *"${TERMINUS_SITE_LABEL}: dev drush clear cache"* ]] [[ "$ouptut" == *"Completed Upstream Update for ${TERMINUS_SITE_LABEL}"* ]] [ "$status" -eq 0 ] From affae7e3d3ec01f7fd662a69688cc76a42ce48b8 Mon Sep 17 00:00:00 2001 From: Sean Dietrich Date: Fri, 31 Mar 2017 22:47:46 -0700 Subject: [PATCH 7/7] Automated Testing Fixed testing docs that appear to be working now just seems as though they may be timing out. --- tests/test-default-no-args.bats | 3 ++- tests/test-default-skip-backups.bats | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test-default-no-args.bats b/tests/test-default-no-args.bats index 28afc23..a4dbfcc 100644 --- a/tests/test-default-no-args.bats +++ b/tests/test-default-no-args.bats @@ -10,8 +10,9 @@ run terminus site:update $TERMINUS_SITE [[ "$output" == *"${TERMINUS_SITE_LABEL} Starting"* ]] [[ "$output" == *"${TERMINUS_SITE_LABEL}: dev creating backup"* ]] + [[ "$output" == *"${TERMINUS_SITE_LABEL}: dev backup created"* ]] [[ "$output" == *"${TERMINUS_SITE_LABEL}: dev drush updatedb"* ]] [[ "$output" == *"${TERMINUS_SITE_LABEL}: dev drush clear cache"* ]] - [[ "$ouptut" == *"Completed Upstream Update for ${TERMINUS_SITE_LABEL}"* ]] + [[ "$output" == *"Completed Upstream Update for ${TERMINUS_SITE_LABEL}"* ]] [ "$status" -eq 0 ] } \ No newline at end of file diff --git a/tests/test-default-skip-backups.bats b/tests/test-default-skip-backups.bats index e9a9145..f661c71 100644 --- a/tests/test-default-skip-backups.bats +++ b/tests/test-default-skip-backups.bats @@ -10,8 +10,8 @@ run terminus site:update $TERMINUS_SITE --skip_backups [[ "$output" == *"${TERMINUS_SITE_LABEL} Starting"* ]] [[ "$output" != *"${TERMINUS_SITE_LABEL}: dev creating backup"* ]] - [[ "$output" == *"${TERMINUS_SITE_LABEL}: dev updatedb"* ]] + [[ "$output" == *"${TERMINUS_SITE_LABEL}: dev drush updatedb"* ]] [[ "$output" == *"${TERMINUS_SITE_LABEL}: dev drush clear cache"* ]] - [[ "$ouptut" == *"Completed Upstream Update for ${TERMINUS_SITE_LABEL}"* ]] + [[ "$output" == *"Completed Upstream Update for ${TERMINUS_SITE_LABEL}"* ]] [ "$status" -eq 0 ] } \ No newline at end of file