Search in sources :

Example 36 with TransformWork

use of com.google.copybara.TransformWork 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 37 with TransformWork

use of com.google.copybara.TransformWork 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)

Example 38 with TransformWork

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

the class RevisionMigratorTest method testOldReferenceGetsNotUpdated.

@Test
public void testOldReferenceGetsNotUpdated() throws Exception {
    String desc = "This is an awesome change, building on http://internalReviews.com/110";
    TransformWork work = getTransformWork(desc);
    referenceMigrator.transform(work);
    assertThat(work.getMessage()).isEqualTo("This is an awesome change, building on http://internalReviews.com/110");
}
Also used : TransformWork(com.google.copybara.TransformWork) Test(org.junit.Test)

Example 39 with TransformWork

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

the class RevisionMigratorTest method testReferenceGetsUpdated.

@Test
public void testReferenceGetsUpdated() throws Exception {
    String desc = "This is an awesome change, building on http://internalReviews.com/123";
    TransformWork work = getTransformWork(desc);
    referenceMigrator.transform(work);
    assertThat(work.getMessage()).isEqualTo("This is an awesome change, building on http://externalreviews.com/view?7b");
}
Also used : TransformWork(com.google.copybara.TransformWork) Test(org.junit.Test)

Example 40 with TransformWork

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

the class RevisionMigratorTest method testLegacyLabel.

@Test
public void testLegacyLabel() throws Exception {
    referenceMigrator = ReferenceMigrator.create("http://internalReviews.com/${reference}", "http://externalreviews.com/view?${reference}", Pattern.compile("[0-9]+"), Pattern.compile("[0-9a-f]+"), ImmutableList.of("LegacyImporter"), location);
    String desc = "This is an awesome change, building on http://internalReviews.com/123";
    TransformWork work = getTransformWork(desc);
    referenceMigrator.transform(work);
    assertThat(work.getMessage()).isEqualTo("This is an awesome change, building on http://externalreviews.com/view?7b");
}
Also used : TransformWork(com.google.copybara.TransformWork) Test(org.junit.Test)

Aggregations

TransformWork (com.google.copybara.TransformWork)41 Test (org.junit.Test)33 Transformation (com.google.copybara.Transformation)23 TransformationStatus (com.google.copybara.TransformationStatus)9 DummyRevision (com.google.copybara.testing.DummyRevision)6 Changes (com.google.copybara.Changes)5 Author (com.google.copybara.authoring.Author)5 ValidationException (com.google.copybara.exception.ValidationException)4 Change (com.google.copybara.Change)3 ProcessedChange (com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange)3 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)2 NonReversibleValidationException (com.google.copybara.exception.NonReversibleValidationException)2 RepoException (com.google.copybara.exception.RepoException)2 TransformWorks.toChange (com.google.copybara.testing.TransformWorks.toChange)2 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1