Search in sources :

Example 86 with ValidationException

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

the class MetadataModuleTest method testScrubberWithPreconditionFailForCustomizeMsg.

@Test
public void testScrubberWithPreconditionFailForCustomizeMsg() throws Exception {
    ValidationException e = assertThrows(ValidationException.class, () -> checkScrubber("this\nis\nvery confidential\nbut this is not public\nnot for public\n", "metadata.scrubber('^(?:\\n|.)*PUBLIC:((?:\\n|.)*)(?:\\n|.)*$', " + "msg_if_no_match = 'This is not confidential.'," + "fail_if_no_match = True," + "replacement = '$1')", /*not used*/
    null));
    assertThat(e).hasMessageThat().contains("If fail_if_no_match is true, msg_if_no_match should be None.");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) NonReversibleValidationException(com.google.copybara.exception.NonReversibleValidationException) Test(org.junit.Test)

Example 87 with ValidationException

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

the class MetadataModuleTest method testMetadataVerifyNoMatchFails.

@Test
public void testMetadataVerifyNoMatchFails() throws Exception {
    options.setLastRevision(origin.resolve("HEAD").asString());
    Workflow<?, ?> wf = createWorkflow(WorkflowMode.ITERATIVE, "metadata.verify_match(\"bar\", verify_no_match = True)");
    origin.addSimpleChange(0, "bar");
    ValidationException e = assertThrows(ValidationException.class, () -> wf.run(workdir, ImmutableList.of("HEAD")));
    assertThat(e).hasMessageThat().contains("'bar' found in the change message");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) NonReversibleValidationException(com.google.copybara.exception.NonReversibleValidationException) Test(org.junit.Test)

Example 88 with ValidationException

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

the class MetadataModuleTest method testMetadataVerifyMatchFails.

@Test
public void testMetadataVerifyMatchFails() throws Exception {
    Workflow<?, ?> wf = createWorkflow(WorkflowMode.ITERATIVE, "metadata.verify_match(\"foobar\")");
    ValidationException e = assertThrows(ValidationException.class, () -> wf.run(workdir, ImmutableList.of("HEAD")));
    assertThat(e).hasMessageThat().contains("Could not find 'foobar' in the change message");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) NonReversibleValidationException(com.google.copybara.exception.NonReversibleValidationException) Test(org.junit.Test)

Example 89 with ValidationException

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

the class MetadataModuleTest method testAddHeaderLabelNotFound.

@Test
public void testAddHeaderLabelNotFound() throws Exception {
    options.setLastRevision(origin.resolve("HEAD").asString());
    Workflow<?, ?> wf = createWorkflow(WorkflowMode.ITERATIVE, "metadata.add_header('[HEADER with ${LABEL}]')");
    origin.addSimpleChange(0, "foo");
    ValidationException thrown = assertThrows(ValidationException.class, () -> wf.run(workdir, ImmutableList.of()));
    assertThat(thrown).hasMessageThat().contains("Cannot find label 'LABEL'");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) NonReversibleValidationException(com.google.copybara.exception.NonReversibleValidationException) Test(org.junit.Test)

Example 90 with ValidationException

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

the class RepositoryUtilTest method testBadUrl.

@Test
public void testBadUrl() {
    ValidationException expected = assertThrows(ValidationException.class, () -> RepositoryUtil.validateNotHttp("http://copybara.com"));
    assertThat(expected).hasMessageThat().contains("URL 'http://copybara.com' is not valid - should be using https");
}
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