Skip to content

Commit

Permalink
Added functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
tesladethray committed Apr 4, 2017
1 parent 24dc0a3 commit 7cd1a82
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Commands/Backup/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions src/Models/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
}

Expand Down
38 changes: 38 additions & 0 deletions tests/features/backup-info.feature
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`
"""
18 changes: 15 additions & 3 deletions tests/unit_tests/Models/BackupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -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',
]);

Expand All @@ -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);
}
Expand Down

0 comments on commit 7cd1a82

Please sign in to comment.