Skip to content

Commit

Permalink
Merge pull request #13 from ufundo/standalone-specific-snapshots
Browse files Browse the repository at this point in the history
Standalone specific snapshots
  • Loading branch information
totten authored Sep 20, 2024
2 parents 61f7b60 + 5aef239 commit ba10edc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@ mysqldump my_civi_db | bzip2 > databases/4.2.3-my_civi_db.sql.bz2

This is not strictly required. If you want to create private test-cases,
you can store them anywhere and follow your own naming convention.

### Standalone Test Cases

The standard test snapshots do not work on Standalone, as they do not
contain the required DB state for a Standalone system.

As such, a separate library of Standalone specific snapshots has been
created in "databases_standalone" directory. This will be used automatically
by civicrm-upgrade-test when running against a Standalone build.
22 changes: 17 additions & 5 deletions bin/civicrm-upgrade-examples
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function help($error = NULL) {
if ($error) {
fwrite(STDERR, $error);
}
echo "usage: $prog <fileExpr> ...\n";
echo "usage: $prog (--snapshot-library <folder>) <fileExpr> ...\n";
echo "\n";
echo "<fileExpr> examples:\n";
echo " /var/foo.sql.gz A specific file\n";
Expand All @@ -46,12 +46,18 @@ function main($args) {
return 1;
}

$files = array();
$examples = UpgradeExamples::instance();
$files = [];
$searchArgs = [];
// default value. may be overridden by a --snapshot-library arg
$snapshotLibrary = 'databases';

while (!empty($args)) {
$arg = array_shift($args);

if ($arg[0] === '-') {
if ($arg === '--snapshot-library') {
$snapshotLibrary = array_shift($args);
}
elseif ($arg[0] === '-') {
help("Unrecognized option: $arg\n");
return 2;
}
Expand All @@ -62,14 +68,20 @@ function main($args) {
$files[] = $arg;
}
elseif ($arg[0] === '@' || strpos($arg, '*')) {
$files = array_merge($files, $examples->find($arg));
$searchArgs[] = $arg;
}
else {
help("Unrecognized argument or missing file: $arg\n");
exit(3);
}
}

$examples = UpgradeExamples::instance($snapshotLibrary);

foreach ($searchArgs as $searchArg) {
$files = array_merge($files, $examples->find($searchArg));
}

$files = $examples->sortFilesByVer(array_unique($files));
foreach ($files as $file) {
echo "$file\n";
Expand Down
9 changes: 8 additions & 1 deletion bin/civicrm-upgrade-test
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,15 @@ while [ -n "$1" ]; do
esac
done

CIVICRM_UF=$( cv --cwd="$WEB_ROOT" ev 'echo CIVICRM_UF;' )

echo "Identify files: [$DATABASE_EXPRS]"
DATABASE_FILES=$(eval php "$SCRIPT_DIR/civicrm-upgrade-examples" $DATABASE_EXPRS)
if [[ "$CIVICRM_UF" == "Standalone" ]]; then
echo "Using 'databases_standalone' snapshot library for Standalone"
DATABASE_FILES=$(eval php "$SCRIPT_DIR/civicrm-upgrade-examples" --snapshot-library databases_standalone $DATABASE_EXPRS)
else
DATABASE_FILES=$(eval php "$SCRIPT_DIR/civicrm-upgrade-examples" $DATABASE_EXPRS)
fi
if [ $? -ne 0 ]; then
echo "Failed to evaluate expression \"$1\" => $DATABASE_FILES" >> /dev/stderr
exit 1
Expand Down
Binary file added databases_standalone/5.77.0-standalone.mysql.bz2
Binary file not shown.
6 changes: 2 additions & 4 deletions src/UpgradeExamples.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ class UpgradeExamples {
*
* @return \Civi\UpgradeTest\UpgradeExamples
*/
public static function instance(): UpgradeExamples {
static $instance;
$instance = $instance ?: new UpgradeExamples(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'databases');
return $instance;
public static function instance(string $basePath = 'databases'): UpgradeExamples {
return new UpgradeExamples(dirname(__DIR__) . DIRECTORY_SEPARATOR . $basePath);
}

/**
Expand Down

0 comments on commit ba10edc

Please sign in to comment.