Search in sources :

Example 26 with Feedback

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

the class GerritEndpointTest method testCheckerIsHonored.

@Test
public void testCheckerIsHonored() throws Exception {
    String config = "" + "def test_action(ctx):\n" + "  ctx.destination.get_change('12_badword_34', include_results = ['LABELS'])\n" + "  return ctx.success()\n" + "\n" + "core.feedback(\n" + "    name = 'default',\n" + "    origin = testing.dummy_trigger(),\n" + "    destination = git.gerrit_api(" + "        url = 'https://test.googlesource.com/example',\n" + "        checker = testing.dummy_checker(),\n" + "    ),\n" + "    actions = [test_action,],\n" + ")\n" + "\n";
    Feedback feedback = (Feedback) skylark.loadConfig(config).getMigration("default");
    ValidationException expected = assertThrows(ValidationException.class, () -> feedback.run(workdir, ImmutableList.of("12345")));
    assertThat(expected).hasMessageThat().contains("Bad word 'badword' found: field 'path'.");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Feedback(com.google.copybara.feedback.Feedback) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 27 with Feedback

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

the class GitHubEndpointTest 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.github_api(\n" + "      url = 'https://github.com/google/example',\n" + "    ),\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 28 with Feedback

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

the class GitHubEndpointTest method testCheckerIsHonored.

@Test
public void testCheckerIsHonored() throws Exception {
    String config = "" + "def test_action(ctx):\n" + "  ctx.destination.update_reference(\n" + "      'e597746de9c1704e648ddc3ffa0d2096b146d600', 'foo_badword_bar', True)\n" + "  return ctx.success()\n" + "\n" + "core.feedback(\n" + "    name = 'default',\n" + "    origin = testing.dummy_trigger(),\n" + "    destination = git.github_api(" + "        url = 'https://github.com/google/example',\n" + "        checker = testing.dummy_checker(),\n" + "    ),\n" + "    actions = [test_action,],\n" + ")\n" + "\n";
    Feedback feedback = (Feedback) skylark.loadConfig(config).getMigration("default");
    assertThat(feedback.getDestinationDescription().get("url")).containsExactly("https://github.com/google/example");
    ValidationException expected = assertThrows(ValidationException.class, () -> feedback.run(workdir, ImmutableList.of("12345")));
    assertThat(expected).hasMessageThat().contains("Bad word 'badword' found: field 'path'.");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Feedback(com.google.copybara.feedback.Feedback) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 29 with Feedback

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

the class GitHubEndpointTest 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