Skip to content

Commit

Permalink
CLI-1362: [push:db] mysqldump failure not surfaced (#1770)
Browse files Browse the repository at this point in the history
* CLI-1362: [push:db] mysqldump failure not surfaced

* fix tests

* add test case
  • Loading branch information
danepowell committed Jul 19, 2024
1 parent 56d0139 commit 94b1e90
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1692,10 +1692,10 @@ protected function createMySqlDumpOnLocal(string $dbHost, string $dbUser, string
$outputCallback('out', "Dumping MySQL database to $localFilepath on this machine");
}
if ($this->localMachineHelper->commandExists('pv')) {
$command = "MYSQL_PWD={$dbPassword} mysqldump --host={$dbHost} --user={$dbUser} {$dbName} | pv --rate --bytes | gzip -9 > $localFilepath";
$command = "bash -c \"set -o pipefail; MYSQL_PWD={$dbPassword} mysqldump --host={$dbHost} --user={$dbUser} {$dbName} | pv --rate --bytes | gzip -9 > $localFilepath\"";
} else {
$this->io->warning('Install `pv` to see progress bar');
$command = "MYSQL_PWD={$dbPassword} mysqldump --host={$dbHost} --user={$dbUser} {$dbName} | gzip -9 > $localFilepath";
$command = "bash -c \"set -o pipefail; MYSQL_PWD={$dbPassword} mysqldump --host={$dbHost} --user={$dbUser} {$dbName} | gzip -9 > $localFilepath\"";
}

$process = $this->localMachineHelper->executeFromCmd($command, $outputCallback, null, ($this->output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL));
Expand Down
8 changes: 6 additions & 2 deletions tests/phpunit/src/CommandTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,17 @@ protected function mockNotificationResponseFromObject(object $responseWithNotifi
return $this->mockRequest('getNotificationByUuid', $uuid);
}

protected function mockCreateMySqlDumpOnLocal(ObjectProphecy $localMachineHelper, bool $printOutput = true): void
protected function mockCreateMySqlDumpOnLocal(ObjectProphecy $localMachineHelper, bool $printOutput = true, bool $pv = true): void
{
$localMachineHelper->checkRequiredBinariesExist(["mysqldump", "gzip"])
->shouldBeCalled();
$process = $this->mockProcess();
$process->getOutput()->willReturn('');
$command = 'MYSQL_PWD=drupal mysqldump --host=localhost --user=drupal drupal | pv --rate --bytes | gzip -9 > ' . sys_get_temp_dir() . '/acli-mysql-dump-drupal.sql.gz';
if ($pv) {
$command = 'bash -c "set -o pipefail; MYSQL_PWD=drupal mysqldump --host=localhost --user=drupal drupal | pv --rate --bytes | gzip -9 > ' . sys_get_temp_dir() . '/acli-mysql-dump-drupal.sql.gz"';
} else {
$command = 'bash -c "set -o pipefail; MYSQL_PWD=drupal mysqldump --host=localhost --user=drupal drupal | gzip -9 > ' . sys_get_temp_dir() . '/acli-mysql-dump-drupal.sql.gz"';
}
$localMachineHelper->executeFromCmd($command, Argument::type('callable'), null, $printOutput)
->willReturn($process->reveal())
->shouldBeCalled();
Expand Down
10 changes: 5 additions & 5 deletions tests/phpunit/src/Commands/Push/PushDatabaseCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class PushDatabaseCommandTest extends CommandTestBase
public function providerTestPushDatabase(): array
{
return [
[OutputInterface::VERBOSITY_NORMAL, false],
[OutputInterface::VERBOSITY_VERY_VERBOSE, true],
[OutputInterface::VERBOSITY_NORMAL, false, false],
[OutputInterface::VERBOSITY_VERY_VERBOSE, true, true],
];
}

Expand All @@ -51,7 +51,7 @@ public function setUp(): void
/**
* @dataProvider providerTestPushDatabase
*/
public function testPushDatabase(int $verbosity, bool $printOutput): void
public function testPushDatabase(int $verbosity, bool $printOutput, bool $pv): void
{
$applications = $this->mockRequest('getApplications');
$application = $this->mockRequest('getApplicationByUuid', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
Expand All @@ -72,8 +72,8 @@ public function testPushDatabase(int $verbosity, bool $printOutput): void
$this->mockGetAcsfSitesLMH($localMachineHelper);

// Database.
$this->mockExecutePvExists($localMachineHelper);
$this->mockCreateMySqlDumpOnLocal($localMachineHelper, $printOutput);
$this->mockExecutePvExists($localMachineHelper, $pv);
$this->mockCreateMySqlDumpOnLocal($localMachineHelper, $printOutput, $pv);
$this->mockUploadDatabaseDump($localMachineHelper, $process, $printOutput);
$this->mockImportDatabaseDumpOnRemote($localMachineHelper, $process, $printOutput);

Expand Down

0 comments on commit 94b1e90

Please sign in to comment.