use of com.google.copybara.checks.CheckerException in project copybara by google.
the class GitDestinationTest method testChecker.
@Test
public void testChecker() throws Exception {
Writer<GitRevision> writer = firstCommitWriter();
Files.write(workdir.resolve("existing"), "BAD".getBytes(UTF_8));
ImmutableList<DestinationEffect> result = writer.write(TransformResults.of(workdir, new DummyRevision("ref1")), destinationFiles, console);
assertThat(result).hasSize(1);
assertThat(result.get(0).getType()).isEqualTo(Type.CREATED);
options.testingOptions.checker = new DummyChecker(ImmutableSet.of("BAD"));
checker = "testing.dummy_checker()";
final Writer<GitRevision> writer2 = newWriter();
Files.write(workdir.resolve("new_file"), "ok".getBytes(UTF_8));
result = writer2.write(TransformResults.of(workdir, new DummyRevision("ref2")), destinationFiles, console);
assertThat(result).hasSize(1);
assertThat(result.get(0).getErrors()).isEmpty();
assertThat(result.get(0).getType()).isEqualTo(Type.CREATED);
Files.write(workdir.resolve("new_file"), "BAD".getBytes(UTF_8));
CheckerException ex = assertThrows(CheckerException.class, () -> writer2.write(TransformResults.of(workdir, new DummyRevision("ref3")), destinationFiles, console));
assertThat(ex).hasMessageThat().containsMatch("Bad word 'bad' found:.*/new_file:1");
assertThat(ex).hasMessageThat().doesNotContainMatch("Bad word 'bad' found:.*/existing:1");
}
use of com.google.copybara.checks.CheckerException in project copybara by google.
the class GerritApiTransportWithCheckerTest method testGetThrowsException.
@Test
public void testGetThrowsException() throws Exception {
doThrow(new CheckerException("Error!")).when(checker).doCheck(ArgumentMatchers.<ImmutableMap<String, String>>any(), eq(console));
assertThrows(ValidationException.class, () -> transport.get("path/foo", String.class));
verifyNoMoreInteractions(delegate);
}
use of com.google.copybara.checks.CheckerException in project copybara by google.
the class GerritApiTransportWithCheckerTest method testPostThrowsException.
@Test
public void testPostThrowsException() throws Exception {
doThrow(new CheckerException("Error!")).when(checker).doCheck(ArgumentMatchers.<ImmutableMap<String, String>>any(), eq(console));
assertThrows(ValidationException.class, () -> transport.post("path/foo", "request_content", String.class));
verifyNoMoreInteractions(delegate);
}
use of com.google.copybara.checks.CheckerException in project copybara by google.
the class GitHubApiTransportWithCheckerTest method testPostThrowsException.
@Test
public void testPostThrowsException() throws Exception {
doThrow(new CheckerException("Error!")).when(checker).check(any(), any(), any(), any(), any(), any());
assertThrows(ValidationException.class, () -> transport.post("path/foo", "request_content", String.class));
verifyNoMoreInteractions(delegate);
}
use of com.google.copybara.checks.CheckerException in project copybara by google.
the class GitHubApiTransportWithCheckerTest method testGetThrowsException.
@Test
public void testGetThrowsException() throws Exception {
doThrow(new CheckerException("Error!")).when(checker).check(any(), any(), any(), any());
assertThrows(ValidationException.class, () -> transport.get("path/foo", String.class));
verifyNoMoreInteractions(delegate);
}
Aggregations