Skip to content

Commit

Permalink
test: add test tools for repair migration e2e tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
SandPod committed Nov 17, 2023
1 parent d2b40d7 commit 438622a
Showing 1 changed file with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ abstract class MigrationTestUtils {
String tag = 'test',
}) async {
for (var protocols in migrationProtocols) {
var exitCode =
await createMigrationFromProtocols(protocols: protocols, tag: tag);

assert(
await createMigrationFromProtocols(protocols: protocols, tag: tag) == 0,
exitCode == 0,
'Failed to create migration.',
);
}
Expand Down Expand Up @@ -50,6 +53,7 @@ abstract class MigrationTestUtils {
'--tag',
suffixedTag,
if (force) '--force',
'--verbose',
],
);
}
Expand Down Expand Up @@ -113,10 +117,79 @@ abstract class MigrationTestUtils {
'maintenance',
'--mode',
'production',
'--logging',
'verbose',
],
);
}

static Future<int> runApplyRepairMigration() async {
return await _runProcess(
'dart',
arguments: [
'run',
'bin/main.dart',
'--apply-repair-migration',
'--role',
'maintenance',
'--mode',
'production',
'--logging',
'verbose',
],
);
}

static Future<int> runApplyBothRepairMigrationAndMigrations() async {
return await _runProcess(
'dart',
arguments: [
'run',
'bin/main.dart',
'--apply-repair-migration',
'--apply-migrations',
'--role',
'maintenance',
'--mode',
'production',
'--logging',
'verbose',
],
);
}

static Future<int> runCreateRepairMigration({
String tag = 'test',
bool force = false,
String? targetVersion,
}) async {
return await _runProcess(
'serverpod',
arguments: [
'create-repair-migration',
'--tag',
tag,
if (targetVersion != null) ...['--version', targetVersion],
if (force) '--force',
'--verbose',
],
);
}

static File? tryLoadRepairMigrationFile() {
var repairMigrationDirectory = _repairMigrationDirectory();
if (!repairMigrationDirectory.existsSync()) {
return null;
}

var repairMigrationFiles = repairMigrationDirectory.listSync();
if (repairMigrationFiles.isEmpty) {
return null;
}

return repairMigrationFiles.first as File;
}

static Directory _migrationProtocolTestDirectory() => Directory(path.join(
Directory.current.path,
'lib',
Expand Down

0 comments on commit 438622a

Please sign in to comment.