Skip to content

Commit

Permalink
test: export structure only
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrajodas committed Jun 28, 2021
1 parent 6065bbb commit 7618e97
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 0 deletions.
76 changes: 76 additions & 0 deletions tests/phpunit/FunctionalAbsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Keboola\App\ProjectBackup\Tests;

use Keboola\App\ProjectBackup\Config\Config;
use Keboola\Csv\CsvFile;
use Keboola\StorageApi\Client as StorageApi;
use Keboola\StorageApi\Components;
use Keboola\StorageApi\Options\Components\Configuration;
Expand Down Expand Up @@ -159,6 +160,81 @@ public function testSuccessfulRun(): void
self::assertGreaterThan(0, count($events));
}

public function testSuccessfulRunOnlyStructure(): void
{
$events = $this->sapiClient->listEvents(['runId' => $this->testRunId]);
self::assertCount(0, $events);

$tmp = new Temp();
$tmp->initRunFolder();

$file = $tmp->createFile('testStructureOnly.csv');
file_put_contents($file->getPathname(), 'a,b,c,d,e,f');

$csvFile = new CsvFile($file);

$this->sapiClient->createBucket('test-bucket', 'out');
$this->sapiClient->createTable('out.c-test-bucket', 'test-table', $csvFile);

$fileSystem = new Filesystem();

// create backupId
$fileSystem->dumpFile(
$this->temp->getTmpFolder() . '/config.json',
(string) json_encode([
'action' => 'generate-read-credentials',
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => getenv('TEST_AZURE_ACCOUNT_NAME'),
'#accountKey' => getenv('TEST_AZURE_ACCOUNT_KEY'),
'region' => getenv('TEST_AZURE_REGION'),
],
])
);

$runProcess = $this->createTestProcess();
$runProcess->mustRun();

$this->assertEmpty($runProcess->getErrorOutput());

$output = $runProcess->getOutput();
$outputData = json_decode($output, true);

$this->assertArrayHasKey('backupId', $outputData);

// run backup
$fileSystem->dumpFile(
$this->temp->getTmpFolder() . '/config.json',
(string) json_encode([
'action' => 'run',
'parameters' => [
'backupId' => $outputData['backupId'],
'exportStructureOnly' => true,
],
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => getenv('TEST_AZURE_ACCOUNT_NAME'),
'#accountKey' => getenv('TEST_AZURE_ACCOUNT_KEY'),
'region' => getenv('TEST_AZURE_REGION'),
],
])
);

$runProcess = $this->createTestProcess();
$runProcess->mustRun();

$this->assertEmpty($runProcess->getErrorOutput());

$output = $runProcess->getOutput();
$this->assertContains('Exporting buckets', $output);
$this->assertContains('Exporting tables', $output);
$this->assertContains('Exporting configurations', $output);
$this->assertNotContains('Table ', $output);

$events = $this->sapiClient->listEvents(['runId' => $this->testRunId]);
self::assertGreaterThan(0, count($events));
}

public function testBadBackupIdRun(): void
{
$fileSystem = new Filesystem();
Expand Down
78 changes: 78 additions & 0 deletions tests/phpunit/FunctionalS3Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Aws\S3\S3Client;
use Aws\S3\S3UriParser;
use Keboola\App\ProjectBackup\Config\Config;
use Keboola\Csv\CsvFile;
use Keboola\StorageApi\Client as StorageApi;
use Keboola\StorageApi\Components;
use Keboola\StorageApi\Options\Components\Configuration;
Expand Down Expand Up @@ -201,6 +202,83 @@ public function testSuccessfulRun(): void
self::assertGreaterThan(0, count($events));
}

public function testSuccessfulRunOnlyStructure(): void
{
$events = $this->sapiClient->listEvents(['runId' => $this->testRunId]);
self::assertCount(0, $events);

$tmp = new Temp();
$tmp->initRunFolder();

$file = $tmp->createFile('testStructureOnly.csv');
file_put_contents($file->getPathname(), 'a,b,c,d,e,f');

$csvFile = new CsvFile($file);

$this->sapiClient->createBucket('test-bucket', 'out');
$this->sapiClient->createTable('out.c-test-bucket', 'test-table', $csvFile);

$fileSystem = new Filesystem();

// create backupId
$fileSystem->dumpFile(
$this->temp->getTmpFolder() . '/config.json',
(string) json_encode([
'action' => 'generate-read-credentials',
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_S3,
'access_key_id' => getenv('TEST_AWS_ACCESS_KEY_ID'),
'#secret_access_key' => getenv('TEST_AWS_SECRET_ACCESS_KEY'),
'region' => getenv('TEST_AWS_REGION'),
'#bucket' => getenv('TEST_AWS_S3_BUCKET'),
],
])
);

$runProcess = $this->createTestProcess();
$runProcess->mustRun();

$this->assertEmpty($runProcess->getErrorOutput());

$output = $runProcess->getOutput();
$outputData = \json_decode($output, true);

$this->assertArrayHasKey('backupId', $outputData);

// run backup
$fileSystem->dumpFile(
$this->temp->getTmpFolder() . '/config.json',
(string) json_encode([
'action' => 'run',
'parameters' => [
'backupId' => $outputData['backupId'],
'exportStructureOnly' => true,
],
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_S3,
'access_key_id' => getenv('TEST_AWS_ACCESS_KEY_ID'),
'#secret_access_key' => getenv('TEST_AWS_SECRET_ACCESS_KEY'),
'region' => getenv('TEST_AWS_REGION'),
'#bucket' => getenv('TEST_AWS_S3_BUCKET'),
],
])
);

$runProcess = $this->createTestProcess();
$runProcess->mustRun();

$this->assertEmpty($runProcess->getErrorOutput());

$output = $runProcess->getOutput();
$this->assertContains('Exporting buckets', $output);
$this->assertContains('Exporting tables', $output);
$this->assertContains('Exporting configurations', $output);
$this->assertNotContains('Table ', $output);

$events = $this->sapiClient->listEvents(['runId' => $this->testRunId]);
self::assertGreaterThan(0, count($events));
}

public function testBadBackupIdRun(): void
{
$fileSystem = new Filesystem();
Expand Down

0 comments on commit 7618e97

Please sign in to comment.