Search in sources :

Example 81 with ValidationException

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

the class RemoveTest method testBareRemoveNotAllowed.

@Test
public void testBareRemoveNotAllowed() throws Exception {
    Remove t = skylark.eval("m", "m = core.remove(glob(['bar']))");
    ValidationException thrown = assertThrows(ValidationException.class, () -> transform(t));
    assertThat(thrown).hasMessageThat().contains("core.remove() is only mean to be used inside core.transform");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Example 82 with ValidationException

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

the class VerifyMatchTest method testSimpleMatchFails.

@Test
public void testSimpleMatchFails() throws Exception {
    VerifyMatch transformation = eval("core.verify_match(\n" + "  regex = 'foo',\n" + ")");
    Path file1 = checkoutDir.resolve("file1.txt");
    writeFile(file1, "bar");
    ValidationException e = assertThrows(ValidationException.class, () -> transform(transformation));
    assertThat(e).hasMessageThat().contains("1 file(s) failed the validation of Verify match 'foo'");
    console.assertThat().onceInLog(MessageType.ERROR, "File 'file1.txt' failed validation 'Verify match 'foo'.*");
}
Also used : Path(java.nio.file.Path) ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Example 83 with ValidationException

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

the class VerifyMatchTest method testSimpleReversalMatchFails.

@Test
public void testSimpleReversalMatchFails() throws Exception {
    VerifyMatch transformation = eval("core.verify_match(\n" + "  regex = 'foo',\n" + "  also_on_reversal = True,\n" + ")");
    Path file1 = checkoutDir.resolve("file1.txt");
    writeFile(file1, "bar");
    ValidationException e = assertThrows(ValidationException.class, () -> transform(transformation.reverse()));
    assertThat(e).hasMessageThat().contains("1 file(s) failed the validation of Verify match 'foo'");
    console.assertThat().onceInLog(MessageType.ERROR, "File 'file1.txt' failed validation 'Verify match 'foo'.*");
}
Also used : Path(java.nio.file.Path) ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Example 84 with ValidationException

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

the class GithubArchiveTest method repoExceptionOnDownloadFailure.

@Test
public void repoExceptionOnDownloadFailure() throws Exception {
    httpTransport = new MockHttpTransport() {

        @Override
        public LowLevelHttpRequest buildRequest(String method, String url) {
            MockLowLevelHttpRequest request = new MockLowLevelHttpRequest() {

                public LowLevelHttpResponse execute() throws IOException {
                    throw new IOException("OH NOES!");
                }
            };
            return request;
        }
    };
    RemoteFileOptions options = new RemoteFileOptions();
    options.transport = () -> new GclientHttpStreamFactory(httpTransport, Duration.ofSeconds(20));
    Console console = new TestingConsole();
    OptionsBuilder optionsBuilder = new OptionsBuilder().setConsole(console);
    optionsBuilder.remoteFile = options;
    skylark = new SkylarkTestExecutor(optionsBuilder);
    ValidationException e = assertThrows(ValidationException.class, () -> skylark.eval("sha256", "sha256 = remotefiles.github_archive(" + "project = 'google/copybara'," + "revision='674ac754f91e64a0efb8087e59a176484bd534d1').sha256()"));
    assertThat(e).hasCauseThat().hasCauseThat().hasCauseThat().isInstanceOf(RepoException.class);
}
Also used : MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) ValidationException(com.google.copybara.exception.ValidationException) LowLevelHttpRequest(com.google.api.client.http.LowLevelHttpRequest) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) IOException(java.io.IOException) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) MockLowLevelHttpResponse(com.google.api.client.testing.http.MockLowLevelHttpResponse) LowLevelHttpResponse(com.google.api.client.http.LowLevelHttpResponse) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Console(com.google.copybara.util.console.Console) Test(org.junit.Test)

Example 85 with ValidationException

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

the class TodoReplaceTest method testMapOrFail.

@Test
public void testMapOrFail() throws Exception {
    TodoReplace replace = todoReplace("mapping = { 'aaa': 'foo'}", "mode = 'MAP_OR_FAIL'");
    write("one.txt", "// TODO(aaa): Example\n");
    run(replace);
    assertThatPath(checkoutDir).containsFile("one.txt", "// TODO(foo): Example\n").containsNoMoreFiles();
    write("one.txt", "// TODO(bbb): Example\n");
    ValidationException notFound = assertThrows(ValidationException.class, () -> run(replace));
    assertThat(notFound).hasMessageThat().contains("Cannot find a mapping 'bbb' in 'TODO(bbb)' (/one.txt)");
    // Does not conform the pattern for users
    write("one.txt", "// TODO(aaa foo/1234): Example\n");
    ValidationException noMatch = assertThrows(ValidationException.class, () -> run(replace));
    assertThat(noMatch).hasMessageThat().contains("Unexpected 'aaa foo/1234' doesn't match expected format");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) NonReversibleValidationException(com.google.copybara.exception.NonReversibleValidationException) 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