Search in sources :

Example 21 with Feedback

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

the class FeedbackTest method testErrorResultEmptyMsg.

@Test
public void testErrorResultEmptyMsg() throws Exception {
    Feedback feedback = feedback("" + "def test_action(ctx):\n" + "    result = ctx.error()\n" + "\n", "test_action");
    ValidationException expected = assertThrows(ValidationException.class, () -> feedback.run(workdir, ImmutableList.of()));
    assertThat(expected).hasMessageThat().contains("missing 1 required positional argument: msg");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Feedback(com.google.copybara.feedback.Feedback) Test(org.junit.Test)

Example 22 with Feedback

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

the class FeedbackTest method testParsing.

@Test
public void testParsing() throws Exception {
    Feedback feedback = loggingFeedback();
    assertThat(feedback.getName()).isEqualTo("default");
    assertThat(feedback.getModeString()).isEqualTo("feedback");
    assertThat(feedback.getMainConfigFile()).isNotNull();
    assertThat(feedback.getOriginDescription()).isEqualTo(dummyTrigger.describe());
    assertThat(feedback.getDestinationDescription()).isEqualTo(dummyTrigger.describe());
    assertThat(feedback.getActionsDescription()).containsEntry("test_action", ImmutableSetMultimap.of());
}
Also used : Feedback(com.google.copybara.feedback.Feedback) Test(org.junit.Test)

Example 23 with Feedback

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

the class FeedbackTest method testErrorResultAbortsExecution.

@Test
public void testErrorResultAbortsExecution() throws Exception {
    Feedback feedback = feedback("" + "def test_action_1(ctx):\n" + "    return ctx.error('This is an error')\n" + "\n" + "def test_action_2(ctx):\n" + "    return ctx.success()\n", "test_action_1", "test_action_2");
    ValidationException expected = assertThrows(ValidationException.class, () -> feedback.run(workdir, ImmutableList.of()));
    assertThat(expected).hasMessageThat().contains("Feedback migration 'default' action 'test_action_1' returned error: " + "This is an error. Aborting execution.");
    console.assertThat().equalsNext(MessageType.ERROR, "Action 'test_action_1' returned error: This is an error").containsNoMoreMessages();
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Feedback(com.google.copybara.feedback.Feedback) Test(org.junit.Test)

Example 24 with Feedback

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

the class FeedbackTest method verifyCliLabels.

@Test
public void verifyCliLabels() throws Exception {
    options.general.setCliLabelsForTest(ImmutableMap.of("foo", "value"));
    Feedback feedback = feedback("" + "def test_action(ctx):\n" + "    foo = ctx.cli_labels['foo']\n" + "    ctx.console.info('foo is: ' + foo)\n" + "    return ctx.success()\n" + "\n", "test_action");
    feedback.run(workdir, ImmutableList.of());
    console.assertThat().matchesNext(MessageType.INFO, ".*foo is: value").matchesNext(MessageType.INFO, ".*Action 'test_action' returned success.*").containsNoMoreMessages();
}
Also used : Feedback(com.google.copybara.feedback.Feedback) Test(org.junit.Test)

Example 25 with Feedback

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

the class FeedbackTest method testEvalExceptionIncludesLocation.

@Test
public void testEvalExceptionIncludesLocation() throws Exception {
    Feedback feedback = feedback("" + "def test_action(ctx):\n" + "    result = ctx.foo()\n" + "\n", "test_action");
    ValidationException ex = assertThrows(ValidationException.class, () -> feedback.run(workdir, ImmutableList.of()));
    assertThat(ex).hasMessageThat().contains("Error while executing the skylark transformation test_action");
    assertThat(ex).hasMessageThat().contains("File \"copy.bara.sky\", line 2, column 17, in test_action");
    assertThat(ex).hasMessageThat().contains("'feedback.context' value has no field or method 'foo'");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Feedback(com.google.copybara.feedback.Feedback) 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