Search in sources :

Example 11 with DestinationEffect

use of com.google.copybara.effect.DestinationEffect in project copybara by google.

the class GitHubDestinationTest method process.

private void process(Writer<GitRevision> writer, DummyRevision ref) throws ValidationException, RepoException, IOException {
    TransformResult result = TransformResults.of(workdir, ref);
    Changes changes = new Changes(ImmutableList.of(new Change<>(ref, new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "12345")), new Change<>(ref, new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "6789"))), ImmutableList.of());
    result = result.withChanges(changes);
    ImmutableList<DestinationEffect> destinationResult = writer.write(result, destinationFiles, console);
    assertThat(destinationResult).hasSize(1);
    assertThat(destinationResult.get(0).getErrors()).isEmpty();
    assertThat(destinationResult.get(0).getType()).isEqualTo(Type.CREATED);
    assertThat(destinationResult.get(0).getDestinationRef().getType()).isEqualTo("commit");
    assertThat(destinationResult.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");
}
Also used : Changes(com.google.copybara.revision.Changes) TransformResult(com.google.copybara.TransformResult) DestinationEffect(com.google.copybara.effect.DestinationEffect) Author(com.google.copybara.authoring.Author) Change(com.google.copybara.revision.Change)

Example 12 with DestinationEffect

use of com.google.copybara.effect.DestinationEffect in project copybara by google.

the class WorkflowTest method verifyHookForException.

private <T extends Exception> void verifyHookForException(Class<T> expectedExceptionType, Type expectedEffectType, String expectedErrorMsg) throws IOException, ValidationException, RepoException {
    origin.singleFileChange(0, "one commit", "foo.txt", "1");
    String config = "" + "def test(ctx):\n" + "  origin_refs = [ctx.origin.new_origin_ref('1111')]\n" + "  dest_ref = ctx.destination.new_destination_ref(ref = '9999', type = 'some_type')\n" + "  ctx.record_effect('New effect', origin_refs, dest_ref)\n" + "\n" + "core.workflow(\n" + "  name = 'default',\n" + "  origin = testing.origin(),\n" + "  destination = testing.destination(),\n" + "  transformations = [],\n" + "  authoring = " + authoring + ",\n" + "  after_migration = [test]" + ")\n";
    try {
        loadConfig(config).getMigration("default").run(workdir, ImmutableList.of());
        fail();
    } catch (Exception expected) {
        if (!expectedExceptionType.isInstance(expected)) {
            throw expected;
        }
        assertThat(expected).hasMessageThat().contains(expectedErrorMsg);
    }
    assertThat(eventMonitor.changeMigrationFinishedEventCount()).isEqualTo(1);
    ChangeMigrationFinishedEvent event = Iterables.getOnlyElement(eventMonitor.changeMigrationFinishedEvents);
    assertThat(event.getDestinationEffects()).hasSize(2);
    DestinationEffect firstEffect = event.getDestinationEffects().get(0);
    assertThat(firstEffect.getType()).isEqualTo(expectedEffectType);
    assertThat(firstEffect.getSummary()).isEqualTo("Errors happened during the migration");
    assertThat(firstEffect.getErrors()).contains(expectedErrorMsg);
    // Effect from the hook is also created
    DestinationEffect secondEffect = event.getDestinationEffects().get(1);
    assertThat(secondEffect.getSummary()).isEqualTo("New effect");
    assertThat(secondEffect.getType()).isEqualTo(Type.UPDATED);
    assertThat(secondEffect.getOriginRefs().get(0).getRef()).isEqualTo("1111");
    assertThat(secondEffect.getDestinationRef().getId()).isEqualTo("9999");
}
Also used : ChangeMigrationFinishedEvent(com.google.copybara.monitor.EventMonitor.ChangeMigrationFinishedEvent) DestinationEffect(com.google.copybara.effect.DestinationEffect) ChangeRejectedException(com.google.copybara.exception.ChangeRejectedException) CannotResolveRevisionException(com.google.copybara.exception.CannotResolveRevisionException) VoidOperationException(com.google.copybara.exception.VoidOperationException) NotADestinationFileException(com.google.copybara.exception.NotADestinationFileException) RepoException(com.google.copybara.exception.RepoException) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) ValidationException(com.google.copybara.exception.ValidationException) IOException(java.io.IOException)

Example 13 with DestinationEffect

use of com.google.copybara.effect.DestinationEffect in project copybara by google.

the class HgDestinationTest method testWrite.

@Test
public void testWrite() throws Exception {
    Files.write(workdir.resolve("file.txt"), "first write".getBytes(UTF_8));
    Files.write(workdir.resolve("test.txt"), "test".getBytes(UTF_8));
    ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(1496333940000L), ZoneId.of("-04:00"));
    DummyRevision originRef = new DummyRevision("origin_ref").withAuthor(new Author("Copy Bara", "copy@bara.com")).withTimestamp(zonedDateTime);
    TransformResult result = TransformResults.of(workdir, originRef);
    ImmutableList<DestinationEffect> destinationResult = writer.write(result, destinationFiles, console);
    assertThat(destinationResult).hasSize(1);
    assertThat(destinationResult.get(0).getErrors()).isEmpty();
    assertThat(destinationResult.get(0).getType()).isEqualTo(Type.CREATED);
    assertThat(destinationResult.get(0).getDestinationRef().getType()).isEqualTo("commit");
    assertThat(destinationResult.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");
    ImmutableList<HgLogEntry> commits = remoteRepo.log().run();
    assertThat(commits).hasSize(2);
    assertThat(commits.get(0).getDescription()).isEqualTo("" + "test summary\n" + "\n" + "DummyOrigin-RevId: origin_ref");
    assertThat(commits).hasSize(2);
    assertThat(commits.get(0).getZonedDate()).isEqualTo(zonedDateTime);
    assertThat(commits.get(0).getFiles()).hasSize(1);
    assertThat(commits.get(0).getFiles().get(0)).isEqualTo("test.txt");
    assertThat(commits.get(1).getFiles()).hasSize(1);
    assertThat(commits.get(1).getFiles().get(0)).isEqualTo("file.txt");
}
Also used : TransformResult(com.google.copybara.TransformResult) ZonedDateTime(java.time.ZonedDateTime) DestinationEffect(com.google.copybara.effect.DestinationEffect) DummyRevision(com.google.copybara.testing.DummyRevision) Author(com.google.copybara.authoring.Author) HgLogEntry(com.google.copybara.hg.HgRepository.HgLogEntry) Test(org.junit.Test)

Example 14 with DestinationEffect

use of com.google.copybara.effect.DestinationEffect in project copybara by google.

the class ConsoleEventMonitorTest method testEventMonitorPrintsToConsole.

@Test
public void testEventMonitorPrintsToConsole() {
    eventMonitor.onMigrationStarted(new MigrationStartedEvent());
    eventMonitor.onMigrationFinished(new MigrationFinishedEvent(ExitCode.SUCCESS));
    eventMonitor.onChangeMigrationStarted(new ChangeMigrationStartedEvent());
    DestinationEffect destinationEffect = new DestinationEffect(Type.CREATED, "Created revision 1234", ImmutableList.of(new OriginRef("ABCD")), new DestinationRef("1234", "commit", /*url=*/
    null));
    eventMonitor.onChangeMigrationFinished(new ChangeMigrationFinishedEvent(ImmutableList.of(destinationEffect), ImmutableMultimap.of(), ImmutableMultimap.of()));
    MigrationReference<DummyRevision> workflow = MigrationReference.create("workflow", new DummyRevision("1111"), ImmutableList.of(newChange("2222"), newChange("3333")));
    Info<?> info = Info.create(ImmutableMultimap.of("origin", "foo"), ImmutableMultimap.of("dest", "bar"), ImmutableList.of(workflow));
    eventMonitor.onInfoFinished(new InfoFinishedEvent(info, ImmutableMap.of("foo_a", "foo_b")));
    console.assertThat().equalsNext(VERBOSE, "onMigrationStarted(): MigrationStartedEvent").equalsNext(VERBOSE, "onMigrationFinished(): " + "MigrationFinishedEvent{exitCode=SUCCESS, profiler=null}").equalsNext(VERBOSE, "onChangeMigrationStarted(): ChangeMigrationStartedEvent{}").matchesNext(VERBOSE, "onChangeMigrationFinished[(][)]: ChangeMigrationFinishedEvent[{].*[}]").matchesNext(VERBOSE, "onInfoFinished[(][)]: InfoFinishedEvent[{].*(origin).*" + "(foo).*(dest).*(bar).*(foo_a).*(foo_b).*[}]").containsNoMoreMessages();
}
Also used : DestinationRef(com.google.copybara.effect.DestinationEffect.DestinationRef) InfoFinishedEvent(com.google.copybara.monitor.EventMonitor.InfoFinishedEvent) DestinationEffect(com.google.copybara.effect.DestinationEffect) ChangeMigrationFinishedEvent(com.google.copybara.monitor.EventMonitor.ChangeMigrationFinishedEvent) ChangeMigrationStartedEvent(com.google.copybara.monitor.EventMonitor.ChangeMigrationStartedEvent) DummyRevision(com.google.copybara.testing.DummyRevision) MigrationStartedEvent(com.google.copybara.monitor.EventMonitor.MigrationStartedEvent) ChangeMigrationStartedEvent(com.google.copybara.monitor.EventMonitor.ChangeMigrationStartedEvent) MigrationFinishedEvent(com.google.copybara.monitor.EventMonitor.MigrationFinishedEvent) ChangeMigrationFinishedEvent(com.google.copybara.monitor.EventMonitor.ChangeMigrationFinishedEvent) OriginRef(com.google.copybara.revision.OriginRef) Test(org.junit.Test)

Example 15 with DestinationEffect

use of com.google.copybara.effect.DestinationEffect in project copybara by google.

the class FeedbackTest method runAndVerifyDestinationEffects.

private void runAndVerifyDestinationEffects(String actionsCode, ImmutableList<String> expectedErrors, String expectedSummary, String expectedOriginRef, String expectedDestRef, String expectedDestType, @Nullable String expectedDestUrl) throws IOException, ValidationException, RepoException {
    Feedback feedback = feedback(actionsCode, "test_action");
    feedback.run(workdir, ImmutableList.of());
    console.assertThat().equalsNext(MessageType.INFO, "Action 'test_action' returned success");
    assertThat(eventMonitor.changeMigrationStartedEventCount()).isEqualTo(1);
    assertThat(eventMonitor.changeMigrationFinishedEventCount()).isEqualTo(1);
    ChangeMigrationFinishedEvent event = Iterables.getOnlyElement(eventMonitor.changeMigrationFinishedEvents);
    DestinationEffect effect = Iterables.getOnlyElement(event.getDestinationEffects());
    assertThat(effect.getSummary()).isEqualTo(expectedSummary);
    assertThat(effect.getOriginRefs()).hasSize(1);
    assertThat(effect.getOriginRefs().get(0).getRef()).isEqualTo(expectedOriginRef);
    DestinationRef destinationRef = effect.getDestinationRef();
    assertThat(destinationRef.getId()).isEqualTo(expectedDestRef);
    assertThat(destinationRef.getType()).isEqualTo(expectedDestType);
    if (expectedDestUrl == null) {
        assertThat(destinationRef.getUrl()).isNull();
    } else {
        assertThat(destinationRef.getUrl()).isEqualTo(expectedDestUrl);
    }
    assertThat(effect.getErrors()).containsExactlyElementsIn(expectedErrors);
}
Also used : DestinationRef(com.google.copybara.effect.DestinationEffect.DestinationRef) Feedback(com.google.copybara.feedback.Feedback) ChangeMigrationFinishedEvent(com.google.copybara.monitor.EventMonitor.ChangeMigrationFinishedEvent) DestinationEffect(com.google.copybara.effect.DestinationEffect)

Aggregations

DestinationEffect (com.google.copybara.effect.DestinationEffect)39 DummyRevision (com.google.copybara.testing.DummyRevision)26 Test (org.junit.Test)22 WriterContext (com.google.copybara.WriterContext)19 Author (com.google.copybara.authoring.Author)13 Glob (com.google.copybara.util.Glob)13 ImmutableList (com.google.common.collect.ImmutableList)11 Changes (com.google.copybara.revision.Changes)10 Path (java.nio.file.Path)10 ValidationException (com.google.copybara.exception.ValidationException)9 RepoException (com.google.copybara.exception.RepoException)8 IOException (java.io.IOException)8 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)7 ChangeMessage (com.google.copybara.ChangeMessage)7 Writer (com.google.copybara.Destination.Writer)7 Metadata (com.google.copybara.Metadata)7 MigrationInfo (com.google.copybara.MigrationInfo)7 TransformWork (com.google.copybara.TransformWork)7 CheckerException (com.google.copybara.checks.CheckerException)7 LowLevelHttpRequest (com.google.api.client.http.LowLevelHttpRequest)6