Search in sources :

Example 1 with ChangeRejectedException

use of com.google.copybara.exception.ChangeRejectedException 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 2 with ChangeRejectedException

use of com.google.copybara.exception.ChangeRejectedException in project copybara by google.

the class WorkflowTest method testTestWorkflowWithDiffInOriginAndRespondNo.

@Test
public void testTestWorkflowWithDiffInOriginAndRespondNo() throws Exception {
    GitRepository remote = GitRepository.newBareRepo(Files.createTempDirectory("gitdir"), getGitEnv(), /*verbose=*/
    true, DEFAULT_TIMEOUT, /*noVerify=*/
    false).withWorkTree(workdir);
    remote.init();
    String primaryBranch = remote.getPrimaryBranch();
    Files.write(workdir.resolve("foo.txt"), new byte[] {});
    remote.add().files("foo.txt").run();
    remote.simpleCommand("commit", "foo.txt", "-m", "message_a");
    GitRevision lastRev = remote.resolveReference(primaryBranch);
    Files.write(workdir.resolve("bar.txt"), "change content".getBytes(UTF_8));
    remote.add().files("bar.txt").run();
    remote.simpleCommand("commit", "bar.txt", "-m", "message_s");
    TestingConsole testingConsole = new TestingConsole().respondNo();
    options.workflowOptions.lastRevision = lastRev.getSha1();
    options.setWorkdirToRealTempDir().setConsole(testingConsole).setHomeDir(StandardSystemProperty.USER_HOME.value());
    Workflow<?, ?> workflow = (Workflow<?, ?>) new SkylarkTestExecutor(options).loadConfig("core.workflow(\n" + "    name = 'foo',\n" + "    origin = git.origin(url='" + remote.getGitDir() + "'),\n" + "    destination = folder.destination(),\n" + "    mode = 'ITERATIVE',\n" + "    authoring = " + authoring + ",\n" + "    transformations = [metadata.replace_message(''),],\n" + ")\n").getMigration("foo");
    workflow.getWorkflowOptions().diffInOrigin = true;
    ChangeRejectedException e = assertThrows(ChangeRejectedException.class, () -> workflow.run(workdir, ImmutableList.of(primaryBranch)));
    assertThat(e.getMessage()).contains("User aborted execution: did not confirm diff in origin changes.");
}
Also used : GitRepository(com.google.copybara.git.GitRepository) ChangeRejectedException(com.google.copybara.exception.ChangeRejectedException) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) GitRevision(com.google.copybara.git.GitRevision) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Test(org.junit.Test)

Aggregations

ChangeRejectedException (com.google.copybara.exception.ChangeRejectedException)2 Test (org.junit.Test)2 GitRepository (com.google.copybara.git.GitRepository)1 GitRevision (com.google.copybara.git.GitRevision)1 RecordsProcessCallDestination (com.google.copybara.testing.RecordsProcessCallDestination)1 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)1 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)1