Search in sources :

Example 16 with Feedback

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

the class FeedbackTest method testNoopResultThrowsEmptyChangeException.

@Test
public void testNoopResultThrowsEmptyChangeException() throws Exception {
    Feedback feedback = feedback("" + "def test_action_1(ctx):\n" + "    return ctx.noop('No effect 1')\n" + "\n" + "def test_action_2(ctx):\n" + "    return ctx.noop('No effect 2')\n" + "\n", "test_action_1", "test_action_2");
    EmptyChangeException expected = assertThrows(EmptyChangeException.class, () -> feedback.run(workdir, ImmutableList.of()));
    assertThat(expected).hasMessageThat().contains("Feedback migration 'default' was noop. " + "Detailed messages: [No effect 1, No effect 2]");
    console.assertThat().equalsNext(MessageType.INFO, "Action 'test_action_1' returned noop: No effect 1").equalsNext(MessageType.INFO, "Action 'test_action_2' returned noop: No effect 2");
}
Also used : Feedback(com.google.copybara.feedback.Feedback) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Example 17 with Feedback

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

the class FeedbackTest method testRefReturnsNone.

@Test
public void testRefReturnsNone() throws Exception {
    Feedback feedback = feedback("" + "def test_action(ctx):\n" + "    ref = None\n" + "    if len(ctx.refs) > 0:\n" + "      ref = ctx.refs[0]\n" + "    ctx.console.info('Ref: '+ str(ref))\n" + "    return ctx.success()\n" + "\n", "test_action");
    feedback.run(workdir, ImmutableList.of());
    console.assertThat().matchesNext(MessageType.INFO, ".*Ref: None").matchesNext(MessageType.INFO, ".*Action 'test_action' returned success.*").containsNoMoreMessages();
}
Also used : Feedback(com.google.copybara.feedback.Feedback) Test(org.junit.Test)

Example 18 with Feedback

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

the class FeedbackTest method testSuccessResult.

@Test
public void testSuccessResult() throws Exception {
    Feedback feedback = feedback("" + "def test_action(ctx):\n" + "    return ctx.success()\n", "test_action");
    feedback.run(workdir, ImmutableList.of());
    console.assertThat().equalsNext(MessageType.INFO, "Action 'test_action' returned success");
}
Also used : Feedback(com.google.copybara.feedback.Feedback) Test(org.junit.Test)

Example 19 with Feedback

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

the class FeedbackTest method testNoopSuccessReturnsSuccess.

@Test
public void testNoopSuccessReturnsSuccess() throws Exception {
    Feedback feedback = feedback("" + "def test_action_1(ctx):\n" + "    return ctx.noop('No effect')\n" + "\n" + "def test_action_2(ctx):\n" + "    return ctx.success()\n" + "\n", "test_action_1", "test_action_2");
    feedback.run(workdir, ImmutableList.of());
    console.assertThat().equalsNext(MessageType.INFO, "Action 'test_action_1' returned noop: No effect").equalsNext(MessageType.INFO, "Action 'test_action_2' returned success").containsNoMoreMessages();
}
Also used : Feedback(com.google.copybara.feedback.Feedback) Test(org.junit.Test)

Example 20 with Feedback

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

the class FeedbackTest method testNoActionsThrowsEmptyChangeException.

@Test
public void testNoActionsThrowsEmptyChangeException() throws Exception {
    Feedback feedback = feedback("");
    EmptyChangeException expected = assertThrows(EmptyChangeException.class, () -> feedback.run(workdir, ImmutableList.of()));
    assertThat(expected).hasMessageThat().contains("Feedback migration 'default' was noop. Detailed messages: actions field is empty");
}
Also used : Feedback(com.google.copybara.feedback.Feedback) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

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