Search in sources :

Example 6 with Feedback

use of com.google.copybara.feedback.Feedback in project copybara by google.

the class FeedbackTest method testAction.

@Test
public void testAction() throws Exception {
    Feedback feedback = loggingFeedback();
    feedback.run(workdir, ImmutableList.of("12345"));
    console.assertThat().onceInLog(MessageType.INFO, "Ref: 12345");
    console.assertThat().onceInLog(MessageType.INFO, "Feedback name: default");
    console.assertThat().onceInLog(MessageType.INFO, "Action name: test_action");
}
Also used : Feedback(com.google.copybara.feedback.Feedback) Test(org.junit.Test)

Example 7 with Feedback

use of com.google.copybara.feedback.Feedback 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.DestinationEffect.DestinationRef) Feedback(com.google.copybara.feedback.Feedback) ChangeMigrationFinishedEvent(com.google.copybara.monitor.EventMonitor.ChangeMigrationFinishedEvent)

Example 8 with Feedback

use of com.google.copybara.feedback.Feedback in project copybara by google.

the class FeedbackTest method testMultipleSourceRefs.

@Test
public void testMultipleSourceRefs() throws Exception {
    Feedback feedback = loggingFeedback();
    feedback.run(workdir, ImmutableList.of("12345", "67890"));
    console.assertThat().matchesNext(MessageType.INFO, ".*Ref: 12345").matchesNext(MessageType.INFO, ".*Feedback name: default").matchesNext(MessageType.INFO, ".*Action name: test_action").matchesNext(MessageType.INFO, ".*Ref: 67890").matchesNext(MessageType.INFO, ".*Feedback name: default").matchesNext(MessageType.INFO, ".*Action name: test_action").matchesNext(MessageType.INFO, ".*Action 'test_action' returned success.*");
}
Also used : Feedback(com.google.copybara.feedback.Feedback) Test(org.junit.Test)

Example 9 with Feedback

use of com.google.copybara.feedback.Feedback in project copybara by google.

the class FeedbackTest method testDescribeActions.

@Test
public void testDescribeActions() throws Exception {
    Feedback feedback = feedback("" + "def _action1(ctx):\n" + "  return ctx.success()\n" + "\n" + "def _action2(ctx):\n" + "  return ctx.success()\n" + "\n" + "def action1(param1):\n" + "  return core.action(\n" + "      impl = _action1,\n" + "      params = {\n" + "          'param1': param1,\n" + "      },\n" + "  )" + "\n" + "def action2(param1, param2):\n" + "  return core.action(\n" + "      impl = _action2,\n" + "      params = {\n" + "          'param1': param1,\n" + "          'param2': param2,\n" + "      },\n" + "  )" + "\n", "action1(param1 = 'foo')", "action2(param1 = True, param2 = 'Bar')");
    assertThat(feedback.getActionsDescription()).isEqualTo(ImmutableSetMultimap.builder().put("_action1", ImmutableSetMultimap.of("param1", "foo")).put("_action2", ImmutableSetMultimap.of("param1", "true", "param2", "Bar")).build());
}
Also used : Feedback(com.google.copybara.feedback.Feedback) Test(org.junit.Test)

Example 10 with Feedback

use of com.google.copybara.feedback.Feedback in project copybara by google.

the class GerritEndpointTest method runFeedback.

private void runFeedback(ImmutableList<String> funBody) throws Exception {
    Feedback test = feedback("def test_action(ctx):\n" + funBody.stream().map(s -> "  " + s).collect(Collectors.joining("\n")) + "\n  return ctx.success()\n");
    test.run(workdir, ImmutableList.of("e597746de9c1704e648ddc3ffa0d2096b146d600"));
}
Also used : Feedback(com.google.copybara.feedback.Feedback)

Aggregations

Feedback (com.google.copybara.feedback.Feedback)29 Test (org.junit.Test)23 ValidationException (com.google.copybara.exception.ValidationException)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)2 DestinationRef (com.google.copybara.DestinationEffect.DestinationRef)1 Action (com.google.copybara.action.Action)1 StarlarkAction (com.google.copybara.action.StarlarkAction)1 LabelsAwareModule (com.google.copybara.config.LabelsAwareModule)1 UsesFlags (com.google.copybara.doc.annotations.UsesFlags)1 FolderModule (com.google.copybara.folder.FolderModule)1 ChangeMigrationFinishedEvent (com.google.copybara.monitor.EventMonitor.ChangeMigrationFinishedEvent)1 MockRequestAssertion (com.google.copybara.testing.git.GitTestUtil.MockRequestAssertion)1 StarlarkMethod (net.starlark.java.annot.StarlarkMethod)1 Module (net.starlark.java.eval.Module)1