Search in sources :

Example 1 with DummyChecker

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);
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) DummyChecker(com.google.copybara.testing.DummyChecker) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 2 with DummyChecker

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");
}
Also used : DestinationEffect(com.google.copybara.DestinationEffect) CheckerException(com.google.copybara.checks.CheckerException) DummyRevision(com.google.copybara.testing.DummyRevision) DummyChecker(com.google.copybara.testing.DummyChecker) Test(org.junit.Test)

Example 3 with DummyChecker

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"));
}
Also used : Author(com.google.copybara.authoring.Author) DummyChecker(com.google.copybara.testing.DummyChecker) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) Test(org.junit.Test)

Example 4 with DummyChecker

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");
}
Also used : Changes(com.google.copybara.Changes) WriterContext(com.google.copybara.WriterContext) TransformResult(com.google.copybara.TransformResult) CheckerException(com.google.copybara.checks.CheckerException) DummyRevision(com.google.copybara.testing.DummyRevision) Author(com.google.copybara.authoring.Author) Change(com.google.copybara.Change) DummyChecker(com.google.copybara.testing.DummyChecker) Test(org.junit.Test)

Example 5 with DummyChecker

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());
}
Also used : DummyChecker(com.google.copybara.testing.DummyChecker) Test(org.junit.Test)

Aggregations

DummyChecker (com.google.copybara.testing.DummyChecker)11 Test (org.junit.Test)6 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)5 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)5 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)5 Before (org.junit.Before)5 Author (com.google.copybara.authoring.Author)3 CheckerException (com.google.copybara.checks.CheckerException)3 DummyRevision (com.google.copybara.testing.DummyRevision)3 GitTestUtil (com.google.copybara.testing.git.GitTestUtil)3 Path (java.nio.file.Path)3 WriterContext (com.google.copybara.WriterContext)2 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)2 DummyTrigger (com.google.copybara.testing.DummyTrigger)2 Change (com.google.copybara.Change)1 Changes (com.google.copybara.Changes)1 DestinationEffect (com.google.copybara.DestinationEffect)1 TransformResult (com.google.copybara.TransformResult)1 CompleteRefValidator (com.google.copybara.testing.git.GitTestUtil.CompleteRefValidator)1 Validator (com.google.copybara.testing.git.GitTestUtil.Validator)1