use of com.google.copybara.testing.DummyChecker in project copybara by google.
the class GerritTriggerTest method setup.
@Before
public void setup() throws Exception {
TestingConsole console = new TestingConsole();
OptionsBuilder options = new OptionsBuilder();
options.setConsole(console).setOutputRootToTmpDir();
options.testingOptions.checker = new DummyChecker(ImmutableSet.of("badword"));
skylarkTestExecutor = new SkylarkTestExecutor(options);
}
use of com.google.copybara.testing.DummyChecker 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.testing.DummyChecker in project copybara by google.
the class GitDestinationTest method testCheckerDescription_withDefault.
@Test
public void testCheckerDescription_withDefault() throws Exception {
runDescriptionChecker(new DummyChecker(ImmutableSet.of("BAD"), "Message for failures"));
ImmutableList<GitLogEntry> head = repo().log(primaryBranch).withLimit(1).run();
assertThat(head).isNotEmpty();
assertThat(head.get(0).getBody()).isEqualTo("" + "Message for failures\n" + "\n" + "DummyOrigin-RevId: ref2\n");
assertThat(head.get(0).getAuthor()).isEqualTo(new Author("Dont", "rewri@te.me"));
}
use of com.google.copybara.testing.DummyChecker in project copybara by google.
the class GitHubDestinationTest method testCheckerOnPush.
@Test
public void testCheckerOnPush() throws Exception {
options.workflowOptions.initHistory = true;
addFiles(remote, primaryBranch, "first change", ImmutableMap.of("foo.txt", "hello"));
options.testingOptions.checker = new DummyChecker(ImmutableSet.of("BAD"));
GitDestination d = skylark.eval("r", "r = git.github_destination(" + " url = '" + url + "', \n" + " push = '" + primaryBranch + "',\n" + " checker = testing.dummy_checker(),\n" + ")");
WriterContext writerContext = new WriterContext("piper_to_github", "test", false, new DummyRevision("origin_ref1"), Glob.ALL_FILES.roots());
writeFile(this.workdir, "test.txt", "BAD");
Writer<GitRevision> writer = d.newWriter(writerContext);
DummyRevision ref = new DummyRevision("origin_ref1");
Changes changes = new Changes(ImmutableList.of(new Change<>(ref, new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "12345")), new Change<>(ref, new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "6789"))), ImmutableList.of());
TransformResult result = TransformResults.of(workdir, ref).withChanges(changes);
assertThat(assertThrows(CheckerException.class, () -> writer.write(result, destinationFiles, console))).hasMessageThat().contains("Bad word 'bad' found");
}
use of com.google.copybara.testing.DummyChecker in project copybara by google.
the class GitHubPrDestinationTest method testCheckerInDescribe.
@Test
public void testCheckerInDescribe() throws Exception {
options.testingOptions.checker = new DummyChecker(ImmutableSet.of("BAD"));
GitHubPrDestination d = skylark.eval("r", "r = git.github_pr_destination(" + " url = 'http://github.com/foo'," + " checker = testing.dummy_checker()" + ")");
assertThat(d.describe(Glob.ALL_FILES).get("checker")).contains(DummyChecker.class.getName());
}
Aggregations