Search in sources :

Example 1 with RecordsProcessCallDestination

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

the class ReadConfigFromChangeWorkflowTest method setup.

@Before
public void setup() {
    options = new OptionsBuilder();
    origin = new DummyOrigin();
    destination = new RecordsProcessCallDestination();
    options.testingOptions.origin = origin;
    options.testingOptions.destination = destination;
    options.general.starlarkMode = StarlarkMode.STRICT.name();
    skylark = new SkylarkTestExecutor(options);
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) DummyOrigin(com.google.copybara.testing.DummyOrigin) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 2 with RecordsProcessCallDestination

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

the class WorkflowTest method iterativeWorkflowConfirmationHandlingTest.

@Test
public void iterativeWorkflowConfirmationHandlingTest() throws Exception {
    for (int timestamp = 0; timestamp < 10; timestamp++) {
        origin.addSimpleChange(timestamp);
    }
    console().respondYes().respondNo();
    RecordsProcessCallDestination programmableDestination = new RecordsProcessCallDestination(ImmutableList.of(ImmutableList.of(), ImmutableList.of("some error"), ImmutableList.of("Another error")));
    options.testingOptions.destination = programmableDestination;
    Workflow<?, ?> workflow = iterativeWorkflow(/*previousRef=*/
    "2");
    ChangeRejectedException expected = assertThrows(ChangeRejectedException.class, () -> workflow.run(workdir, ImmutableList.of("9")));
    assertThat(expected.getMessage()).contains("Iterative workflow aborted by user after: Change 3 of 7 (5)");
    assertThat(programmableDestination.processed).hasSize(3);
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) ChangeRejectedException(com.google.copybara.exception.ChangeRejectedException) Test(org.junit.Test)

Example 3 with RecordsProcessCallDestination

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

the class WorkflowTest method testOnFinishHook_temporaryError.

// Validates that the hook is executed when the workflow throws an exception != VE, and that
// the correct effect is populated
@Test
public void testOnFinishHook_temporaryError() throws Exception {
    options.testingOptions.destination = new RecordsProcessCallDestination() {

        @Override
        public Writer<Revision> newWriter(WriterContext writerContext) {
            return new RecordsProcessCallDestination.WriterImpl(false) {

                @Override
                public ImmutableList<DestinationEffect> write(TransformResult transformResult, Glob destinationFiles, Console console) throws RepoException {
                    throw new RepoException("Repo exception!");
                }
            };
        }
    };
    verifyHookForException(RepoException.class, Type.TEMPORARY_ERROR, "Repo exception!");
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) ImmutableList(com.google.common.collect.ImmutableList) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Console(com.google.copybara.util.console.Console) Glob(com.google.copybara.util.Glob) RepoException(com.google.copybara.exception.RepoException) Test(org.junit.Test)

Example 4 with RecordsProcessCallDestination

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

the class GitOriginTest method partialFetch_canFetchRootFile.

@Test
public void partialFetch_canFetchRootFile() throws Exception {
    RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
    options.testingOptions.destination = destination;
    options.setLastRevision(firstCommitRef);
    Files.write(remote.resolve("file.txt"), new byte[0]);
    git("add", "file.txt");
    git("commit", "-m", "message");
    @SuppressWarnings("unchecked") 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" + "         partial_fetch = True,\n" + "    ),\n" + "    origin_files = glob(['directory/**', 'file.txt']),\n" + "    destination = testing.destination(),\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(1);
}
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 5 with RecordsProcessCallDestination

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

the class GitOriginTest method partialFetchAtGitOrigin.

@Test
public void partialFetchAtGitOrigin() throws Exception {
    Files.createDirectories(remote.resolve("include"));
    Files.write(remote.resolve("include/fileA.txt"), new byte[0]);
    git("add", "include/fileA.txt");
    git("commit", "-m", "not include");
    git("checkout", defaultBranch);
    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", "message_a!");
    options.setForce(true);
    RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
    options.testingOptions.destination = destination;
    options.setLastRevision(firstCommitRef);
    @SuppressWarnings("unchecked") 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" + "         partial_fetch = True,\n" + "    ),\n" + "    origin_files = glob(['include/mainline-file.txt']),\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(1);
    assertThat(changes.get(0).getChangesSummary()).contains("message_a!");
}
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)

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