Within archiveDumpTest.php there is no test to verify that archive-dump works.

At Drupal Developer Days Barcelona, @jonhattan and me discussed on how to test archive-restore. @jonhattan suggested to do a diff -rq between the original codebase and the restored one to ensure that they are identical.

A patch is attached in the next comment where the resulting file structure is compared with the original one.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

juampynr’s picture

Status: Active » Needs review
FileSize
1.21 KB

Here is the patch.

moshe weitzman’s picture

Status: Needs review » Needs work

The diff command may not be available, especially on Windows. Maybe we should use a hash of the file listing just like the make tests do?

juampynr’s picture

Status: Needs work » Needs review
FileSize
951 bytes

Here is an alternative version of the patch, but this time using drush_dir_md5() of the original and restored codebase and then comparing the md5s. Unfortunately they do not match. Here is an output example:

uampy@juampy-box:~/drush/tests (master)$ phpunit archiveDumpTest
PHPUnit 3.6.7 by Sebastian Bergmann.

Configuration read from /home/juampy/drush/tests/phpunit.xml

Archive saved to /tmp/drush-sandbox/dump.tar.gz                                                                                                                     [ok]
Archive restored to /tmp/drush-sandbox/restore                                                                                                                      [ok]
F
Log: Executing: /home/juampy/local/bin/drush --nocolor pm-download drupal-7 --destination=/tmp/drush-sandbox --drupal-project-rename=web --yes --quiet --cache

Log: Executing: /home/juampy/local/bin/drush --root=/tmp/drush-sandbox/web --nocolor site-install testing --db-url='mysql://root:@localhost/unish_default' --sites-subdir=default --yes --quiet

Log: Executing: /home/juampy/local/bin/drush --root=/tmp/drush-sandbox/web --uri=default --nocolor archive-dump default --yes --destination=dump.tar.gz

Log: Executing: file /tmp/drush-sandbox/dump.tar.gz

Log: Executing: mkdir /tmp/drush-sandbox/untar && cd /tmp/drush-sandbox/untar && tar -xzf /tmp/drush-sandbox/dump.tar.gz

Log: Executing: head /tmp/drush-sandbox/untar/unish_default.sql | grep "MySQL dump"

Log: Executing: /home/juampy/local/bin/drush --nocolor archive-restore /tmp/drush-sandbox/dump.tar.gz --yes --destination=/tmp/drush-sandbox/restore


Time: 49 seconds, Memory: 5.25Mb

There was 1 failure:

1) archiveDumpCase::testArchiveDump
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'a3ed471f8f4e9fb092479f7732bfe46a'
+'27b38966223b61819acfb0bb5ae1e719'

/home/juampy/drush/tests/archiveDumpTest.php:58

FAILURES!
Tests: 1, Assertions: 11, Failures: 1.

juampynr’s picture

archive-dump was not sites/example.sites.php to the archive and that is why the md5 hashes of the original and restored codebases did not match. There was also a missing exclamation mark to negate the condition that checks for the presence of sites/sites.php, which was also fixed.

The attached patch contains two commits: the first one adds the archive-restore test, while the second commit fixes the bug in the logic of archive-dump so the two files mentioned above are added to dump.tar.gz and consequently extracted afterwards, thus making md5 hashes match and the test pass.

juampynr’s picture

Status: Needs review » Needs work
FileSize
0 bytes

After reviewing the patch with @moshe weitzman, I realised that I was not fixing the logic of archive-dump properly and my patch at #4 was adding an empty sites/example.sites.php file.

Below is the updated code within the attached patch. The error was that the path of sites/sites.php was being given along with the $docroot, which finally evaluated as /tmp/drush-sandbox/web/web/sites/sites.php. That is the reason why sites/sites.php was never found and thus not added to the archive.

diff --git a/commands/core/archive.drush.inc b/commands/core/archive.drush.inc
index 7e045d4..f44ef80 100644
--- a/commands/core/archive.drush.inc
+++ b/commands/core/archive.drush.inc
@@ -168,9 +168,12 @@ function drush_archive_dump($sites_subdirs = '@self') {
   drush_shell_cd_and_exec($workdir, "$tar --exclude \"{$docroot}/sites\" {$dereference}-cf %s %s", $destination, $docroot);
   // Add sites/all to the same archive.
   drush_shell_cd_and_exec($workdir, "$tar {$dereference}-rf %s %s", $destination, "{$docroot}/sites/all");
-  // Add sites/sites.php to the same archive.
-  if (file_exists("{$docroot}/sites/sites.php")) {
-    drush_shell_cd_and_exec($workdir, "$tar {$dereference}-rf %s %s", $destination, "{$docroot}/sites/sites.php");
+  // Add sites/sites.php and sites/example.sites.php to the same archive.
+  $files_to_add = array('sites/sites.php', 'sites/example.sites.php');
+  foreach ($files_to_add as $file_to_add) {
+    if (file_exists($file_to_add)) {
+      drush_shell_cd_and_exec($workdir, "$tar {$dereference}-rf %s %s", $destination, $docroot . DIRECTORY_SEPARATOR . $file_to_add);
+    }

Instead I set the $docroot when the tar command is issued so now sites/example.sites.php and sites/sites.php are searched correctly, added to the archive and therefore the test passes.

juampynr’s picture

Doh! Submitted an empty patch. Here it is.

juampynr’s picture

Status: Needs work » Needs review

Changing status to needs review.

moshe weitzman’s picture

Status: Needs review » Fixed

Committed. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Added reasoning authorship.