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");
}
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'.*");
}
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'.*");
}
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);
}
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");
}
Aggregations