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();
}
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");
}
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"));
}
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"));
}
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();
}
Aggregations