Search in sources :

Example 41 with ProcessedChange

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

the class WorkflowTest method testMessageTransformerForChangeRequest.

@Test
public void testMessageTransformerForChangeRequest() throws Exception {
    options.workflowOptions.changeBaseline = "1";
    runWorkflowForMessageTransform(WorkflowMode.CHANGE_REQUEST, /*thirdTransform=*/
    null);
    ProcessedChange change = Iterables.getOnlyElement(destination.processed);
    assertThat(change.getChangesSummary()).isEqualTo("" + "CHANGE: third commit (2) by Foo Baz\n" + "\n" + "BAR = foo\n");
    assertThat(change.getAuthor().toString()).isEqualTo("Someone <someone@somewhere.com>");
}
Also used : ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) Test(org.junit.Test)

Example 42 with ProcessedChange

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

the class WorkflowTest method iterativeWorkflowTestRecordContextReference.

@Test
public void iterativeWorkflowTestRecordContextReference() throws Exception {
    for (int timestamp = 0; timestamp < 10; timestamp++) {
        origin.addSimpleChange(timestamp);
    }
    Workflow<?, ?> workflow = iterativeWorkflow("0");
    // First change is migrated without context reference. Then we run again with
    // context ("HEAD").
    workflow.run(workdir, ImmutableList.of("1"));
    workflow = iterativeWorkflow(/*previousRef=*/
    null);
    workflow.run(workdir, ImmutableList.of("HEAD"));
    for (ProcessedChange change : destination.processed) {
        assertThat(change.getRequestedRevision().contextReference()).isEqualTo(change.getOriginRef().asString().equals("1") ? null : "HEAD");
    }
}
Also used : ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) Test(org.junit.Test)

Example 43 with ProcessedChange

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

the class WorkflowTest method checkChangeRequest_sot_ahead_sot.

private void checkChangeRequest_sot_ahead_sot() throws IOException, ValidationException, RepoException {
    options.workflowOptions.changeRequestFromSotLimit = 1;
    origin.addSimpleChange(0, "Base Change").addSimpleChange(1, "First Change").addSimpleChange(2, "Second Change").addSimpleChange(3, "Third Change");
    Workflow<?, ?> workflow = iterativeWorkflow("0");
    workflow.run(workdir, ImmutableList.of("1"));
    ProcessedChange change = destination.processed.get(0);
    assertThat(change.getBaseline()).isNull();
    assertThat(change.getChangesSummary()).isEqualTo("First Change");
    Workflow<?, ?> w = skylarkWorkflow("default", WorkflowMode.CHANGE_REQUEST_FROM_SOT);
    try {
        w.run(workdir, ImmutableList.of("3"));
        fail();
    } catch (ValidationException e) {
        assertThat(e).hasMessageThat().contains("Make sure to sync the submitted changes");
    }
}
Also used : ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) ValidationException(com.google.copybara.exception.ValidationException)

Example 44 with ProcessedChange

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

the class WorkflowTest method iterativeWorkflowTest_defaultAuthoring.

@Test
public void iterativeWorkflowTest_defaultAuthoring() throws Exception {
    for (int timestamp = 0; timestamp < 61; timestamp++) {
        origin.addSimpleChange(timestamp);
    }
    Workflow<?, ?> workflow = iterativeWorkflow(/*previousRef=*/
    "42");
    workflow.run(workdir, ImmutableList.of("50"));
    assertThat(destination.processed).hasSize(8);
    int nextChange = 43;
    for (ProcessedChange change : destination.processed) {
        assertThat(change.getChangesSummary()).isEqualTo(nextChange + " change");
        String asString = Integer.toString(nextChange);
        assertThat(change.getOriginRef().asString()).isEqualTo(asString);
        assertThat(change.numFiles()).isEqualTo(1);
        assertThat(change.getContent("file.txt")).isEqualTo(PREFIX + asString);
        assertThat(change.getAuthor()).isEqualTo(DEFAULT_AUTHOR);
        nextChange++;
    }
    workflow = iterativeWorkflow(null);
    workflow.run(workdir, ImmutableList.of("60"));
    assertThat(destination.processed).hasSize(18);
}
Also used : ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) Test(org.junit.Test)

Example 45 with ProcessedChange

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

the class WorkflowTest method changeRequest_sot_no_origin_files_match.

@Test
public void changeRequest_sot_no_origin_files_match() throws Exception {
    options.workflowOptions.changeRequestFromSotLimit = 1;
    origin.addSimpleChange(0, "Base Change").addSimpleChange(1, "First Change").addSimpleChange(2, "Second Change");
    Workflow<?, ?> workflow = iterativeWorkflow("0");
    workflow.run(workdir, ImmutableList.of("1"));
    ProcessedChange change = destination.processed.get(0);
    assertThat(change.getBaseline()).isNull();
    assertThat(change.getChangesSummary()).isEqualTo("First Change");
    origin.singleFileChange(3, "pending", "I_dont_exist/file.txt", "content");
    originFiles = "glob(['I_dont_exist/**'])";
    Workflow<?, ?> w = skylarkWorkflow("default", WorkflowMode.CHANGE_REQUEST_FROM_SOT);
    ValidationException e = assertThrows(ValidationException.class, () -> w.run(workdir, ImmutableList.of("3")));
    assertThat(e).hasMessageThat().contains("Couldn't find any parent change for 3" + " and origin_files = glob(include = [\"I_dont_exist/**\"])");
}
Also used : ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Aggregations

ProcessedChange (com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange)59 Test (org.junit.Test)57 Author (com.google.copybara.authoring.Author)11 Revision (com.google.copybara.Revision)4 Workflow (com.google.copybara.Workflow)4 RecordsProcessCallDestination (com.google.copybara.testing.RecordsProcessCallDestination)4 ValidationException (com.google.copybara.exception.ValidationException)2 DummyRevision (com.google.copybara.testing.DummyRevision)2 TemporalAccessor (java.time.temporal.TemporalAccessor)1 HashSet (java.util.HashSet)1