diff --git a/src/Commands/Backup/InfoCommand.php b/src/Commands/Backup/InfoCommand.php index 837ba428f..75a83dcc6 100644 --- a/src/Commands/Backup/InfoCommand.php +++ b/src/Commands/Backup/InfoCommand.php @@ -23,6 +23,7 @@ class InfoCommand extends SingleBackupCommand * date: Date * expiry: Expiry * initiator: Initiator + * url: URL * @return PropertyList * * @param string $site_env Site & environment in the format `site-name.env` diff --git a/src/Models/Backup.php b/src/Models/Backup.php index 2803d0824..f940d8755 100755 --- a/src/Models/Backup.php +++ b/src/Models/Backup.php @@ -187,6 +187,7 @@ public function serialize() 'date' => date($date_format, $this->getDate()), 'expiry' => date($date_format, $this->getExpiry()), 'initiator' => $this->getInitiator(), + 'url' => $this->getUrl(), ]; } diff --git a/tests/features/backup-info.feature b/tests/features/backup-info.feature new file mode 100644 index 000000000..ec7fc0285 --- /dev/null +++ b/tests/features/backup-info.feature @@ -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` + """ diff --git a/tests/unit_tests/Models/BackupTest.php b/tests/unit_tests/Models/BackupTest.php index 1a250b7c0..f69c51031 100644 --- a/tests/unit_tests/Models/BackupTest.php +++ b/tests/unit_tests/Models/BackupTest.php @@ -119,15 +119,16 @@ public function testGetSizeInMb() public function testGetUrl() { $expected = '**URL**'; + $folder = 'xyz_manual'; $this->request->expects($this->once()) ->method('request') ->with( - 'sites/abc/environments/dev/backups/catalog/xyz_manual/type/s3token', + "sites/abc/environments/dev/backups/catalog/$folder/type/s3token", ['method' => 'post', 'form_params' => ['method' => 'get',],] ) ->willReturn(['data' => (object)['url' => $expected,],]); - $backup = $this->_getBackup(['folder' => 'xyz_manual',]); + $backup = $this->_getBackup(compact('folder')); $this->assertEquals($expected, $backup->getUrl()); } @@ -191,10 +192,11 @@ public function testRestore() public function testSerialize() { $this->configSet(['date_format' => 'Y-m-d',]); + $folder = 'xyz_automated'; $backup = $this->_getBackup([ 'size' => 4508876, 'finish_time' => 1479742685, - 'folder' => 'xyz_automated', + 'folder' => $folder, 'filename' => 'test.tar.gz', ]); @@ -204,7 +206,17 @@ public function testSerialize() 'date' => '2016-11-21', 'expiry' => '2016-11-21', 'initiator' => 'automated', + 'url' => 'https://url.to/backup.tgz', ]; + + $this->request->expects($this->once()) + ->method('request') + ->with( + "sites/abc/environments/dev/backups/catalog/$folder/type/s3token", + ['method' => 'post', 'form_params' => ['method' => 'get',],] + ) + ->willReturn(['data' => (object)['url' => $expected['url'],],]); + $actual = $backup->serialize(); $this->assertEquals($expected, $actual); }