Search in sources :

Example 11 with Feedback

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

the class GerritEndpointTest method testFeedbackGetChange_malformedJson.

@Test
public void testFeedbackGetChange_malformedJson() throws Exception {
    gitUtil.mockApi(anyString(), anyString(), mockResponse("foo   bar"));
    Feedback feedback = notifyChangeToOriginFeedback();
    ValidationException expected = assertThrows(ValidationException.class, () -> feedback.run(workdir, ImmutableList.of("12345")));
    assertThat(expected).hasMessageThat().contains("Error while executing the skylark transformation test_action");
    Throwable cause = expected.getCause();
    assertThat(cause).isInstanceOf(IllegalArgumentException.class);
    assertThat(dummyTrigger.messages).isEmpty();
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Feedback(com.google.copybara.feedback.Feedback) Test(org.junit.Test)

Example 12 with Feedback

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

the class GerritEndpointTest method feedback.

private Feedback feedback(String actionFunction) throws IOException, ValidationException {
    String config = actionFunction + "\n" + "core.feedback(\n" + "    name = 'default',\n" + "    origin = testing.dummy_trigger(),\n" + "    destination = git.gerrit_api(url = '" + url + "'),\n" + "    actions = [test_action,],\n" + ")\n" + "\n";
    System.err.println(config);
    return (Feedback) skylark.loadConfig(config).getMigration("default");
}
Also used : Feedback(com.google.copybara.feedback.Feedback) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 13 with Feedback

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

the class GerritEndpointTest method testFeedbackGetChange.

/**
 * A test that uses feedback.
 *
 * <p>Does not verify all the fields, see {@link #testGetChangeExhaustive()} ()} for that.
 */
@Test
public void testFeedbackGetChange() throws Exception {
    mockForTest();
    Feedback feedback = notifyChangeToOriginFeedback();
    feedback.run(workdir, ImmutableList.of("12345"));
    assertThat(dummyTrigger.messages).containsAtLeastElementsIn(ImmutableList.of("Change number 12345"));
}
Also used : Feedback(com.google.copybara.feedback.Feedback) Test(org.junit.Test)

Example 14 with Feedback

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

the class GitHubEndpointTest method testFeedbackCreateStatus.

/**
 * A test that uses feedback.
 *
 * <p>Does not verify all the fields, see {@link #testCreateStatusExhaustive()} for that.
 */
@Test
public void testFeedbackCreateStatus() throws Exception {
    dummyTrigger.addAll("Foo", "Bar");
    Feedback feedback = feedback("" + "def test_action(ctx):\n" + "    ref = 'None'\n" + "    if len(ctx.refs) > 0:\n" + "      ref = ctx.refs[0]\n" + "    \n" + "    for m in ctx.origin.get_messages:\n" + "      status = ctx.destination.create_status(\n" + "        sha = ref,\n" + "        state = 'success',\n" + "        context = 'test',\n" + "        description = 'Observed ' + m,\n" + "      )\n" + "      ctx.console.info('Created status')\n" + "    return ctx.success()\n" + "\n");
    Iterator<String> createValues = ImmutableList.of("Observed Foo", "Observed Bar").iterator();
    gitUtil.mockApi(eq("POST"), contains("/status"), mockResponseAndValidateRequest("{\n" + "    state : 'success',\n" + "    target_url : 'https://github.com/google/example',\n" + "    description : 'Observed foo',\n" + "    context : 'test'\n" + "}", new MockRequestAssertion(String.format("Requests were expected to cycle through the values of %s", createValues), r -> r.contains(createValues.next()))));
    feedback.run(workdir, ImmutableList.of("e597746de9c1704e648ddc3ffa0d2096b146d600"));
    console.assertThat().timesInLog(2, MessageType.INFO, "Created status");
    verify(gitUtil.httpTransport(), times(2)).buildRequest(eq("POST"), contains("/status"));
}
Also used : MockRequestAssertion(com.google.copybara.testing.git.GitTestUtil.MockRequestAssertion) Feedback(com.google.copybara.feedback.Feedback) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 15 with Feedback

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

the class FeedbackTest method testNullSourceRef.

@Test
public void testNullSourceRef() throws Exception {
    Feedback feedback = loggingFeedback();
    feedback.run(workdir, ImmutableList.of());
    console.assertThat().equalsNext(MessageType.INFO, "Action 'test_action' returned success").containsNoMoreMessages();
}
Also used : 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