Search in sources :

Example 16 with RecordsProcessCallDestination

use of com.google.copybara.testing.RecordsProcessCallDestination in project copybara by google.

the class GitOriginTest method branchCommitLogsOnlyCoverIncludedOriginFileRoots.

@SuppressWarnings("unchecked")
@Test
public void branchCommitLogsOnlyCoverIncludedOriginFileRoots() throws Exception {
    String excludedMessage = "i hope this IS NOT included in the migrated message!";
    // Make two commits on 'the-branch' branch, one being in an excluded directory, the other
    // included.
    git("checkout", "-b", "the-branch");
    Files.write(remote.resolve("branch-file.txt"), new byte[0]);
    git("add", "branch-file.txt");
    git("commit", "-m", excludedMessage);
    Files.createDirectories(remote.resolve("include"));
    Files.write(remote.resolve("include/branch-file.txt"), new byte[0]);
    git("add", "include/branch-file.txt");
    git("commit", "-m", "i hope this is included@@@");
    git("checkout", defaultBranch);
    // Make a commit on mainline so that Git doesn't turn this into a fast-forward.
    Files.createDirectories(remote.resolve("include"));
    Files.write(remote.resolve("include/mainline-file.txt"), new byte[0]);
    git("add", "include/mainline-file.txt");
    git("commit", "-m", "mainline message!");
    git("merge", "the-branch");
    options.setForce(true);
    RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
    options.testingOptions.destination = destination;
    options.setLastRevision(firstCommitRef);
    Workflow<GitRevision, Revision> wf = (Workflow<GitRevision, Revision>) skylark.loadConfig("" + "core.workflow(\n" + "    name = 'default',\n" + "    origin = git.origin(\n" + "         url = '" + url + "',\n" + "         include_branch_commit_logs = True,\n" + "    ),\n" + "    origin_files = glob(['include/**']),\n" + "    destination = testing.destination(),\n" + "    mode = 'ITERATIVE',\n" + "    authoring = authoring.pass_thru('example <example@example.com>'),\n" + ")\n").getMigration("default");
    wf.run(Files.createTempDirectory("foo"), ImmutableList.of("HEAD"));
    List<ProcessedChange> changes = destination.processed;
    assertThat(changes).hasSize(2);
    assertThat(changes.get(0).getChangesSummary()).contains("mainline message!");
    assertThat(changes.get(1).getChangesSummary()).doesNotContain(excludedMessage);
    assertThat(changes.get(1).getChangesSummary()).contains("i hope this is included@@@");
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) Revision(com.google.copybara.Revision) Workflow(com.google.copybara.Workflow) Test(org.junit.Test)

Example 17 with RecordsProcessCallDestination

use of com.google.copybara.testing.RecordsProcessCallDestination in project copybara by google.

the class LatestVersionSelectorTest method testResolve.

@Test
public void testResolve() throws Exception {
    createTags("1.0.0");
    options.testingOptions.destination = new RecordsProcessCallDestination();
    options.general.setForceForTest(true);
    Path workdir = Files.createTempDirectory("workdir");
    // noinspection unchecked
    String cfg = "" + "core.workflow(" + "   name = 'default'," + "   origin = git.origin(" + "     url = '" + url + "',\n" + "     version_selector = git.latest_version(),\n" + "   )," + "   authoring = authoring.overwrite('Foo <foo@example.com>')," + "   destination = testing.destination()," + ")";
    skylark.loadConfig(cfg).getMigration("default").run(workdir, ImmutableList.of());
    assertThat(options.testingOptions.destination.processed).hasSize(1);
    assertThat(options.testingOptions.destination.processed.get(0).getWorkdir()).containsExactly("test.txt", "some content");
    writeFile(remote, "test.txt", "some content2");
    repo.add().files("test.txt").run();
    git("commit", "-m", "second change", "--date", COMMIT_TIME);
    createTags("foo", "1.1.0");
    options.general.setForceForTest(false);
    skylark.loadConfig(cfg).getMigration("default").run(workdir, ImmutableList.of());
    assertThat(options.testingOptions.destination.processed.get(1).getWorkdir()).containsExactly("test.txt", "some content2");
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) Path(java.nio.file.Path) Test(org.junit.Test)

Example 18 with RecordsProcessCallDestination

use of com.google.copybara.testing.RecordsProcessCallDestination in project copybara by google.

the class MetadataModuleTest method setup.

@Before
public void setup() throws Exception {
    options = new OptionsBuilder();
    authoring = "authoring.overwrite('" + DEFAULT_AUTHOR + "')";
    workdir = Files.createTempDirectory("workdir");
    Files.createDirectories(workdir);
    origin = new DummyOrigin().setAuthor(ORIGINAL_AUTHOR);
    destination = new RecordsProcessCallDestination();
    options.setConsole(new TestingConsole());
    options.testingOptions.origin = origin;
    options.testingOptions.destination = destination;
    skylark = new SkylarkTestExecutor(options);
    origin.addSimpleChange(0, "first commit\n\nExtended text").setAuthor(FOO_BAR).addSimpleChange(1, "second commit\n\nExtended text").setAuthor(FOO_BAZ).addSimpleChange(2, "third commit\n\nExtended text");
    options.setLastRevision("0");
    // We don't care about already migrated code
    options.setForce(true);
    testingConsole = new TestingConsole();
    options.setConsole(testingConsole);
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) DummyOrigin(com.google.copybara.testing.DummyOrigin) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Aggregations

RecordsProcessCallDestination (com.google.copybara.testing.RecordsProcessCallDestination)18 Test (org.junit.Test)11 Workflow (com.google.copybara.Workflow)7 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)7 Revision (com.google.copybara.Revision)6 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)6 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)6 Before (org.junit.Before)6 DummyOrigin (com.google.copybara.testing.DummyOrigin)5 ValidationException (com.google.copybara.exception.ValidationException)4 ProcessedChange (com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange)4 Console (com.google.copybara.util.console.Console)4 Path (java.nio.file.Path)4 ImmutableList (com.google.common.collect.ImmutableList)3 Glob (com.google.copybara.util.Glob)3 ChangeRejectedException (com.google.copybara.exception.ChangeRejectedException)2 RepoException (com.google.copybara.exception.RepoException)2 TestingEventMonitor (com.google.copybara.testing.TestingEventMonitor)2 IOException (java.io.IOException)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)1