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 bd18054
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 deletions.
4 changes: 3 additions & 1 deletion 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 All @@ -35,6 +36,7 @@ class InfoCommand extends SingleBackupCommand
*/
public function info($site_env, array $options = ['file' => null, 'element' => 'all',])
{
return new PropertyList($this->getBackup($site_env, $options)->serialize());
$backup = $this->getBackup($site_env, $options);
return new PropertyList(array_merge($backup->serialize(), ['url' => $backup->getUrl(),]));
}
}
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`
"""
17 changes: 12 additions & 5 deletions tests/unit_tests/Commands/Backup/InfoCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Consolidation\OutputFormatters\StructuredData\PropertyList;
use Pantheon\Terminus\Commands\Backup\InfoCommand;
use Pantheon\Terminus\Exceptions\TerminusNotFoundException;

/**
* Class InfoCommandTest
Expand All @@ -13,6 +12,10 @@
*/
class InfoCommandTest extends BackupCommandTest
{
/**
* @var array
*/
protected $expected_data;

/**
* Sets up the fixture, for example, open a network connection.
Expand All @@ -22,14 +25,18 @@ protected function setUp()
{
parent::setUp();

$this->sample_data = [
$sample_data = [
'file' => 'file name',
'size' => 'file size',
'date' => 459880805,
'expiry' => 3615640805,
'initiator' => 'backup initiator',
];
$this->backup->method('serialize')->willReturn($this->sample_data);
$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);
Expand All @@ -50,7 +57,7 @@ public function testInfoBackupWithFile()

$output = $this->command->info('mysite.dev', ['file' => $test_filename,]);
$this->assertInstanceOf(PropertyList::class, $output);
$this->assertEquals($this->sample_data, $output->getArrayCopy());
$this->assertEquals($this->expected_data, $output->getArrayCopy());
}

/**
Expand All @@ -65,6 +72,6 @@ public function testInfoBackupWithElement()

$output = $this->command->info('mysite.dev', ['element' => 'db',]);
$this->assertInstanceOf(PropertyList::class, $output);
$this->assertEquals($this->sample_data, $output->getArrayCopy());
$this->assertEquals($this->expected_data, $output->getArrayCopy());
}
}
9 changes: 6 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 @@ -205,6 +207,7 @@ public function testSerialize()
'expiry' => '2016-11-21',
'initiator' => 'automated',
];

$actual = $backup->serialize();
$this->assertEquals($expected, $actual);
}
Expand Down

0 comments on commit bd18054

Please sign in to comment.