Search in sources :

Example 41 with Transformation

use of com.google.copybara.Transformation in project copybara by google.

the class MetadataModuleTest method checkLabelChange.

private void checkLabelChange(String msg, String transform, String expectedOutput) throws Exception {
    TransformWork tw = TransformWorks.of(workdir, msg, testingConsole).withChanges(new Changes(ImmutableList.of(toChange(new DummyRevision("1").withLabels(ImmutableListMultimap.of("FROM_CHANGE", "from_change_value")), ORIGINAL_AUTHOR)), ImmutableList.of())).withResolvedReference(new DummyRevision("123").withLabels(ImmutableListMultimap.of("SOME", "value")));
    Transformation t = skylark.eval("t", "t = " + transform);
    t.transform(tw);
    assertThat(tw.getMessage()).isEqualTo(expectedOutput);
}
Also used : Changes(com.google.copybara.Changes) Transformation(com.google.copybara.Transformation) TransformWork(com.google.copybara.TransformWork) DummyRevision(com.google.copybara.testing.DummyRevision)

Example 42 with Transformation

use of com.google.copybara.Transformation in project copybara by google.

the class MetadataModuleTest method testMapAuthor_reverseFaiIfNotFound.

@Test
public void testMapAuthor_reverseFaiIfNotFound() throws Exception {
    Transformation m = skylark.eval("m", "m = " + "metadata.map_author({\n" + "    'a <a@example.com>' : 'b <b@example.com>',\n" + "}," + "reversible = True, reverse_fail_if_not_found = True)");
    TransformWork work = TransformWorks.of(workdir, "test", testingConsole);
    work.setAuthor(new Author("x", "x@example.com"));
    // normal workflow works:
    m.transform(work);
    ValidationException thrown = assertThrows(ValidationException.class, () -> m.reverse().transform(work));
    assertThat(thrown).hasMessageThat().contains("Cannot find a mapping for author 'x <x@example.com>'");
}
Also used : Transformation(com.google.copybara.Transformation) ValidationException(com.google.copybara.exception.ValidationException) NonReversibleValidationException(com.google.copybara.exception.NonReversibleValidationException) TransformWork(com.google.copybara.TransformWork) Author(com.google.copybara.authoring.Author) Test(org.junit.Test)

Aggregations

Transformation (com.google.copybara.Transformation)42 Test (org.junit.Test)38 TransformWork (com.google.copybara.TransformWork)23 TransformationStatus (com.google.copybara.TransformationStatus)12 Author (com.google.copybara.authoring.Author)3 DummyRevision (com.google.copybara.testing.DummyRevision)3 Changes (com.google.copybara.Changes)2 Sequence (com.google.copybara.transform.Sequence)2 Transformations.toTransformation (com.google.copybara.transform.Transformations.toTransformation)2 NonReversibleValidationException (com.google.copybara.exception.NonReversibleValidationException)1 ValidationException (com.google.copybara.exception.ValidationException)1 FileSubjects.assertThatPath (com.google.copybara.testing.FileSubjects.assertThatPath)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1