Search in sources :

Example 36 with ValidationException

use of com.google.copybara.exception.ValidationException in project copybara by google.

the class WorkflowTest method testShowDiffInOriginFail.

@Test
public void testShowDiffInOriginFail() throws Exception {
    origin.addSimpleChange(/*timestamp*/
    1);
    origin.addSimpleChange(/*timestamp*/
    2);
    origin.addSimpleChange(/*timestamp*/
    3);
    options.workflowOptions.lastRevision = "1";
    options.workflowOptions.diffInOrigin = true;
    Workflow<?, ?> workflow = (Workflow<?, ?>) new SkylarkTestExecutor(options).loadConfig("core.workflow(\n" + "    name = 'foo',\n" + "    origin = testing.origin(),\n" + "    destination = testing.destination(),\n" + "    mode = 'ITERATIVE',\n" + "    authoring = " + authoring + ",\n" + "    transformations = [metadata.replace_message(''),],\n" + ")\n").getMigration("foo");
    ValidationException e = assertThrows(ValidationException.class, () -> workflow.run(workdir, ImmutableList.of("HEAD")));
    assertThat(e).hasMessageThat().contains("diff_in_origin is not supported by origin " + origin.getType());
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Test(org.junit.Test)

Example 37 with ValidationException

use of com.google.copybara.exception.ValidationException in project copybara by google.

the class WorkflowTest method smartPruneForDifferentWorkflowMode.

@Test
public void smartPruneForDifferentWorkflowMode() throws Exception {
    smartPrune = true;
    ValidationException e = assertThrows(ValidationException.class, () -> skylarkWorkflow("default", WorkflowMode.SQUASH));
    console().assertThat().onceInLog(MessageType.ERROR, ".*'smart_prune = True' is only supported for CHANGE_REQUEST mode.*");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Example 38 with ValidationException

use of com.google.copybara.exception.ValidationException in project copybara by google.

the class WorkflowTest method changeRequestWithFolderDestinationError.

@Test
public void changeRequestWithFolderDestinationError() throws IOException, ValidationException, RepoException {
    origin.singleFileChange(/*timestamp=*/
    44, "commit 1", "bar.txt", "1");
    ValidationException thrown = assertThrows(ValidationException.class, () -> loadConfig("core.workflow(\n" + "    name = 'foo',\n" + "    origin = testing.origin(),\n" + "    destination = folder.destination(),\n" + "    authoring = " + authoring + ",\n" + "    mode = 'CHANGE_REQUEST',\n" + ")\n").getMigration("foo").run(workdir, ImmutableList.of()));
    assertThat(thrown).hasMessageThat().contains("'CHANGE_REQUEST' is incompatible with destinations that don't support" + " history");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Example 39 with ValidationException

use of com.google.copybara.exception.ValidationException in project copybara by google.

the class WorkflowTest method invalidExcludedOriginPath.

@Test
public void invalidExcludedOriginPath() throws Exception {
    prepareOriginExcludes("a");
    String outsideFolder = "../../file";
    Path file = workdir.resolve(outsideFolder);
    Files.createDirectories(file.getParent());
    Files.write(file, new byte[] {});
    originFiles = "glob(['" + outsideFolder + "'])";
    ValidationException e = assertThrows(ValidationException.class, () -> workflow().run(workdir, ImmutableList.of(HEAD)));
    console().assertThat().onceInLog(MessageType.ERROR, "(\n|.)*path has unexpected [.] or [.][.] components(\n|.)*");
    assertThatPath(workdir).containsFiles(outsideFolder);
}
Also used : Path(java.nio.file.Path) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Example 40 with ValidationException

use of com.google.copybara.exception.ValidationException in project copybara by google.

the class WorkflowTest method changeRequest_customRevIdLabelWithSetRevId.

@Test
public void changeRequest_customRevIdLabelWithSetRevId() throws Exception {
    extraWorkflowFields = ImmutableList.of("experimental_custom_rev_id = \"CUSTOM_REV_ID\"");
    setRevId = true;
    ValidationException e = assertThrows(ValidationException.class, () -> changeRequestWorkflow(null));
    assertThat(e.getMessage()).containsMatch("experimental_custom_rev_id is not allowed to be used in CHANGE_REQUEST mode if " + "set_rev_id is set to true. experimental_custom_rev_id is used");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Aggregations

ValidationException (com.google.copybara.exception.ValidationException)178 Test (org.junit.Test)125 Path (java.nio.file.Path)33 RepoException (com.google.copybara.exception.RepoException)29 NonReversibleValidationException (com.google.copybara.exception.NonReversibleValidationException)26 ImmutableList (com.google.common.collect.ImmutableList)21 IOException (java.io.IOException)19 Console (com.google.copybara.util.console.Console)16 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)14 DummyRevision (com.google.copybara.testing.DummyRevision)14 Glob (com.google.copybara.util.Glob)14 ProfilerTask (com.google.copybara.profiler.Profiler.ProfilerTask)13 Nullable (javax.annotation.Nullable)13 Migration (com.google.copybara.config.Migration)11 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)11 Iterables (com.google.common.collect.Iterables)10 Change (com.google.copybara.Change)10 CannotResolveRevisionException (com.google.copybara.exception.CannotResolveRevisionException)10 Collectors (java.util.stream.Collectors)10 WriterContext (com.google.copybara.WriterContext)9