-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AL-885, AL-911 - Added backup:info command, expiry to backup:list (#1676
) * Added backup:info command, expiry to backup:list * Covered new material with unit tests * Added functional test
- Loading branch information
1 parent
d585e40
commit fe6abd6
Showing
12 changed files
with
280 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Pantheon\Terminus\Commands\Backup; | ||
|
||
use Consolidation\OutputFormatters\StructuredData\PropertyList; | ||
|
||
/** | ||
* Class InfoCommand | ||
* @package Pantheon\Terminus\Commands\Backup | ||
*/ | ||
class InfoCommand extends SingleBackupCommand | ||
{ | ||
/** | ||
* Displays information about a specific backup or the latest backup. | ||
* | ||
* @authorize | ||
* | ||
* @command backup:info | ||
* | ||
* @field-labels | ||
* file: Filename | ||
* size: Size | ||
* date: Date | ||
* expiry: Expiry | ||
* initiator: Initiator | ||
* url: URL | ||
* @return PropertyList | ||
* | ||
* @param string $site_env Site & environment in the format `site-name.env` | ||
* @option string $file [filename.tgz] Name of backup file | ||
* @option string $element [all|code|files|database|db] Backup element to retrieve | ||
* | ||
* @usage <site>.<env> Displays information about the most recent backup of any type in <site>'s <env> environment. | ||
* @usage <site>.<env> --file=<file_name> Displays information about the backup with the file name <file_name> in <site>'s <env> environment. | ||
* @usage <site>.<env> --element=<element> Displays information about the most recent <element> backup in <site>'s <env> environment. | ||
*/ | ||
public function info($site_env, array $options = ['file' => null, 'element' => 'all',]) | ||
{ | ||
$backup = $this->getBackup($site_env, $options); | ||
return new PropertyList(array_merge($backup->serialize(), ['url' => $backup->getUrl(),])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Pantheon\Terminus\Commands\Backup; | ||
|
||
use Pantheon\Terminus\Exceptions\TerminusNotFoundException; | ||
|
||
abstract class SingleBackupCommand extends BackupCommand | ||
{ | ||
|
||
/** | ||
* @param $site_env | ||
* @param array $options | ||
* @return Backup | ||
* @throws TerminusNotFoundException | ||
*/ | ||
protected function getBackup($site_env, array $options = ['file' => null, 'element' => 'all',]) | ||
{ | ||
list($site, $env) = $this->getSiteEnv($site_env); | ||
|
||
if (isset($options['file']) && !is_null($file_name = $options['file'])) { | ||
$backup = $env->getBackups()->getBackupByFileName($file_name); | ||
} else { | ||
$element = isset($options['element']) ? $this->getElement($options['element']) : null; | ||
$backups = $env->getBackups()->getFinishedBackups($element); | ||
if (empty($backups)) { | ||
throw new TerminusNotFoundException( | ||
'No backups available. Create one with `terminus backup:create {site}.{env}`', | ||
['site' => $site->get('name'), 'env' => $env->id,] | ||
); | ||
} | ||
$backup = array_shift($backups); | ||
} | ||
return $backup; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Feature: Get a particular backup for a site | ||
In order to secure my site against failures | ||
As a user | ||
I need to be able to get information about a backup that has been made | ||
|
||
Background: I am authenticated and have a site named [[test_site_name]] | ||
Given I am authenticated | ||
And a site named "[[test_site_name]]" | ||
|
||
@vcr backup-get-file.yml | ||
Scenario: Gets information about the latest code backup made | ||
When I run "terminus backup:info [[test_site_name]].dev --element=code" | ||
Then I should get: "----------- -----------------------------------------------------" | ||
And I should get: "Filename [[test_site_name]]_dev_2016-08-18T23-16-20_UTC_code.tar.gz" | ||
And I should get: "Size 31.8MB" | ||
And I should get: "Date 2016-08-18 23:16:30" | ||
And I should get: "Expiry 2017-08-19 05:02:06" | ||
And I should get: "Initiator manual" | ||
And I should get: "----------- -----------------------------------------------------" | ||
|
||
@vcr backup-get-file.yml | ||
Scenario: Gets informtion about a backup selected by filename | ||
When I run "terminus backup:info [[test_site_name]].dev --file=[[test_site_name]]_dev_2016-08-18T23-16-20_UTC_code.tar.gz" | ||
Then I should get: "----------- -----------------------------------------------------" | ||
And I should get: "Filename [[test_site_name]]_dev_2016-08-18T23-16-20_UTC_code.tar.gz" | ||
And I should get: "Size 31.8MB" | ||
And I should get: "Date 2016-08-18 23:16:30" | ||
And I should get: "Expiry 2017-08-19 05:02:06" | ||
And I should get: "Initiator manual" | ||
And I should get: "----------- -----------------------------------------------------" | ||
|
||
@vcr backup-get-none.yml | ||
Scenario: Failing to find a matching backup | ||
When I run "terminus backup:info [[test_site_name]].test --element=database" | ||
Then I should get: | ||
""" | ||
No backups available. Create one with `terminus backup:create [[test_site_name]].test` | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace Pantheon\Terminus\UnitTests\Commands\Backup; | ||
|
||
use Consolidation\OutputFormatters\StructuredData\PropertyList; | ||
use Pantheon\Terminus\Commands\Backup\InfoCommand; | ||
|
||
/** | ||
* Class InfoCommandTest | ||
* Testing class for Pantheon\Terminus\Commands\Backup\InfoCommand | ||
* @package Pantheon\Terminus\UnitTests\Commands\Backup | ||
*/ | ||
class InfoCommandTest extends BackupCommandTest | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $expected_data; | ||
|
||
/** | ||
* Sets up the fixture, for example, open a network connection. | ||
* This method is called before a test is executed. | ||
*/ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$sample_data = [ | ||
'file' => 'file name', | ||
'size' => 'file size', | ||
'date' => 459880805, | ||
'expiry' => 3615640805, | ||
'initiator' => 'backup initiator', | ||
]; | ||
$url = 'https://url.to/backup.tgz'; | ||
$this->expected_data = array_merge($sample_data, compact('url')); | ||
|
||
$this->backup->method('serialize')->willReturn($sample_data); | ||
$this->backup->method('getUrl')->willReturn($url); | ||
|
||
$this->command = new InfoCommand($this->sites); | ||
$this->command->setLogger($this->logger); | ||
$this->command->setSites($this->sites); | ||
} | ||
|
||
/** | ||
* Tests the backup:info command with file | ||
*/ | ||
public function testInfoBackupWithFile() | ||
{ | ||
$test_filename = 'test.tar.gz'; | ||
|
||
$this->backups->expects($this->once()) | ||
->method('getBackupByFileName') | ||
->with($test_filename) | ||
->willReturn($this->backup); | ||
|
||
$output = $this->command->info('mysite.dev', ['file' => $test_filename,]); | ||
$this->assertInstanceOf(PropertyList::class, $output); | ||
$this->assertEquals($this->expected_data, $output->getArrayCopy()); | ||
} | ||
|
||
/** | ||
* Tests the backup:info command with an element | ||
*/ | ||
public function testInfoBackupWithElement() | ||
{ | ||
$this->backups->expects($this->once()) | ||
->method('getFinishedBackups') | ||
->with('database') | ||
->willReturn([$this->backup,]); | ||
|
||
$output = $this->command->info('mysite.dev', ['element' => 'db',]); | ||
$this->assertInstanceOf(PropertyList::class, $output); | ||
$this->assertEquals($this->expected_data, $output->getArrayCopy()); | ||
} | ||
} |
Oops, something went wrong.