use of com.google.copybara.exception.ValidationException in project copybara by google.
the class WorkflowTest method nonReversibleButCheckReverseSet.
@Test
public void nonReversibleButCheckReverseSet() throws Exception {
origin.singleFileChange(0, "one commit", "foo.txt", "1").singleFileChange(1, "one commit", "test.txt", "1\nTRANSFORMED42");
Workflow<?, ?> workflow = changeRequestWorkflow("0");
ValidationException e = assertThrows(ValidationException.class, () -> workflow.run(workdir, ImmutableList.of("1")));
assertThat(e).hasMessageThat().isEqualTo("Workflow 'default' is not reversible");
console().assertThat().onceInLog(MessageType.PROGRESS, "Checking that the transformations can be reverted");
}
use of com.google.copybara.exception.ValidationException in project copybara by google.
the class WorkflowTest method changeRequestSmartPrune_manualBaseline.
@Test
public void changeRequestSmartPrune_manualBaseline() throws Exception {
smartPrune = true;
// For now we don't support smart_prune with the flag since the flag refers to the destination
// baseline and for smart_prune we need the origin revision. We might revisit this if it
// if requested by users
options.workflowOptions.changeBaseline = "42";
ValidationException e = assertThrows(ValidationException.class, () -> checkChangeRequestSmartPrune());
assertThat(e).hasMessageThat().contains("smart_prune is not compatible with --change-request-parent");
}
use of com.google.copybara.exception.ValidationException in project copybara by google.
the class WorkflowTest method reversibleCheckSymlinkError.
@Test
public void reversibleCheckSymlinkError() throws Exception {
Path someRoot = Files.createTempDirectory("someRoot");
Path originPath = someRoot.resolve("origin");
Files.createDirectories(originPath);
GitRepository origin = GitRepository.newRepo(/*verbose*/
true, originPath, getGitEnv()).init();
String primaryBranch = origin.getPrimaryBranch();
String config = "core.workflow(\n" + " name = 'default',\n" + String.format(" origin = git.origin( url = 'file://%s', ref = '%s'),\n", origin.getWorkTree(), primaryBranch) + " destination = testing.destination(),\n" + " authoring = " + authoring + ",\n" + " origin_files = glob(['included/**']),\n" + " reversible_check = True,\n" + " mode = '" + WorkflowMode.SQUASH + "',\n" + ")\n";
Migration workflow = loadConfig(config).getMigration("default");
Path included = originPath.resolve("included");
Files.createDirectory(included);
Files.write(originPath.resolve("included/foo.txt"), "a".getBytes(UTF_8));
Path fileOutsideCheckout = someRoot.resolve("file_outside_checkout");
Files.write(fileOutsideCheckout, "THE CONTENT".getBytes(UTF_8));
Files.createSymbolicLink(included.resolve("symlink"), included.relativize(fileOutsideCheckout));
origin.add().files("included/foo.txt").run();
origin.add().files("included/symlink").run();
origin.commit("Foo <foo@bara.com>", ZonedDateTime.now(ZoneId.systemDefault()), "A commit");
ValidationException expected = assertThrows(ValidationException.class, () -> workflow.run(workdir, ImmutableList.of()));
assertThat(expected.getMessage()).matches("" + "Failed to perform reversible check of transformations due to symlink '.*' that " + "points outside the checkout dir. Consider removing this symlink from your " + "origin_files or, alternatively, set reversible_check = False in your " + "workflow.");
}
use of com.google.copybara.exception.ValidationException in project copybara by google.
the class WorkflowTest method verifyHookForException.
private <T extends Exception> void verifyHookForException(Class<T> expectedExceptionType, Type expectedEffectType, String expectedErrorMsg) throws IOException, ValidationException, RepoException {
origin.singleFileChange(0, "one commit", "foo.txt", "1");
String config = "" + "def test(ctx):\n" + " origin_refs = [ctx.origin.new_origin_ref('1111')]\n" + " dest_ref = ctx.destination.new_destination_ref(ref = '9999', type = 'some_type')\n" + " ctx.record_effect('New effect', origin_refs, dest_ref)\n" + "\n" + "core.workflow(\n" + " name = 'default',\n" + " origin = testing.origin(),\n" + " destination = testing.destination(),\n" + " transformations = [],\n" + " authoring = " + authoring + ",\n" + " after_migration = [test]" + ")\n";
try {
loadConfig(config).getMigration("default").run(workdir, ImmutableList.of());
fail();
} catch (Exception expected) {
if (!expectedExceptionType.isInstance(expected)) {
throw expected;
}
assertThat(expected).hasMessageThat().contains(expectedErrorMsg);
}
assertThat(eventMonitor.changeMigrationFinishedEventCount()).isEqualTo(1);
ChangeMigrationFinishedEvent event = Iterables.getOnlyElement(eventMonitor.changeMigrationFinishedEvents);
assertThat(event.getDestinationEffects()).hasSize(2);
DestinationEffect firstEffect = event.getDestinationEffects().get(0);
assertThat(firstEffect.getType()).isEqualTo(expectedEffectType);
assertThat(firstEffect.getSummary()).isEqualTo("Errors happened during the migration");
assertThat(firstEffect.getErrors()).contains(expectedErrorMsg);
// Effect from the hook is also created
DestinationEffect secondEffect = event.getDestinationEffects().get(1);
assertThat(secondEffect.getSummary()).isEqualTo("New effect");
assertThat(secondEffect.getType()).isEqualTo(Type.UPDATED);
assertThat(secondEffect.getOriginRefs().get(0).getRef()).isEqualTo("1111");
assertThat(secondEffect.getDestinationRef().getId()).isEqualTo("9999");
}
use of com.google.copybara.exception.ValidationException in project copybara by google.
the class WorkflowTest method testNonReversibleInsideGit.
@Test
public void testNonReversibleInsideGit() throws IOException, ValidationException, RepoException {
origin.singleFileChange(0, "one commit", "foo.txt", "foo\nbar\n");
GitRepository.newRepo(/*verbose*/
true, workdir, getGitEnv()).init();
Path subdir = Files.createDirectory(workdir.resolve("subdir"));
String config = "" + "core.workflow(\n" + " name = 'default',\n" + " origin = testing.origin(),\n" + " destination = testing.destination(),\n" + " transformations = [core.replace('foo', 'bar')],\n" + " authoring = " + authoring + ",\n" + " reversible_check = True,\n" + ")\n";
Migration workflow = loadConfig(config).getMigration("default");
ValidationException e = assertThrows(ValidationException.class, () -> workflow.run(subdir, ImmutableList.of()));
assertThat(e).hasMessageThat().contains("Cannot use 'reversible_check = True' because Copybara temporary directory");
}
Aggregations