use of com.google.copybara.exception.ValidationException in project copybara by google.
the class GerritEndpointTest method testPostLabel_errorCreatesVe.
@Test
public void testPostLabel_errorCreatesVe() throws Exception {
mockForTest();
gitUtil.mockApi(eq("POST"), matches(BASE_URL + "/changes/.*/revisions/.*/review"), mockResponseWithStatus("\n\nApplying label \"Verified\": -1 is restricted.", 403));
ValidationException expected = assertThrows(ValidationException.class, () -> runFeedback(ImmutableList.of("ctx.destination.post_review(" + "'12345', 'sha1', git.review_input({'Code-Review': 1}, 'foooo'))")));
assertThat(expected).hasMessageThat().contains("Permission error calling post_review");
}
use of com.google.copybara.exception.ValidationException in project copybara by google.
the class GerritEndpointTest method testGetChangePaginationNotSupported.
@Test
public void testGetChangePaginationNotSupported() throws IOException {
gitUtil.mockApi(eq("GET"), startsWith(BASE_URL + "/changes/"), mockResponse("{" + " id : '12345'," + " _more_changes : true" + "}"));
ValidationException expected = assertThrows(ValidationException.class, () -> runFeedback(ImmutableList.of("ctx.destination.get_change('12345', include_results = ['LABELS'])")));
assertThat(expected).hasMessageThat().contains("Pagination is not supported yet.");
}
use of com.google.copybara.exception.ValidationException in project copybara by google.
the class GitDestinationIntegrateTest method testGerritFakeMergeNoChangeId.
@Test
public void testGerritFakeMergeNoChangeId() throws ValidationException, IOException, RepoException {
Path workTree = Files.createTempDirectory("test");
GitRepository repo = gitUtil.mockRemoteRepo("example.com/gerrit").withWorkTree(workTree);
String label = new GerritIntegrateLabel(repo, options.general, "https://example.com/gerrit", 1020, 1, /*changeId=*/
null).toString();
assertThat(label).isEqualTo("gerrit https://example.com/gerrit 1020 Patch Set 1");
GitRevision firstChange = singleChange(workTree, repo, "ignore_me", "Feature1 change");
repo.simpleCommand("update-ref", "refs/changes/20/1020/1", firstChange.getSha1());
GitTestUtil.createFakeGerritNodeDbMeta(repo, 1020, CHANGE_ID);
GitDestination destination = destination(FAKE_MERGE);
GitLogEntry previous = createBaseDestinationChange(destination);
migrateOriginChange(destination, "Test change\n" + "\n" + GitModule.DEFAULT_INTEGRATE_LABEL + "=" + label + "\n", "some content");
// Make sure commit adds new text
String showResult = git("--git-dir", repoGitDir.toString(), "show", primaryBranch);
assertThat(showResult).contains("some content");
GitTesting.assertThatCheckout(repo(), primaryBranch).containsFile("test.txt", "some content").containsNoMoreFiles();
GitLogEntry merge = getLastMigratedChange(primaryBranch);
assertThat(merge.getBody()).isEqualTo("Merge Gerrit change 1020 Patch Set 1\n" + "\n" + "DummyOrigin-RevId: test\n");
assertThat(Lists.transform(merge.getParents(), GitRevision::getSha1)).isEqualTo(Lists.newArrayList(previous.getCommit().getSha1(), firstChange.getSha1()));
assertThat(console.getMessages().stream().filter(e -> e.getType() == MessageType.WARNING).findAny()).isEqualTo(Optional.empty());
}
use of com.google.copybara.exception.ValidationException in project copybara by google.
the class GitDestinationIntegrateTest method testGitHubSemiFakeMerge.
@Test
public void testGitHubSemiFakeMerge() throws ValidationException, IOException, RepoException {
Path workTree = Files.createTempDirectory("test");
GitRepository repo = gitUtil.mockRemoteRepo("github.com/example/test_repo").withWorkTree(workTree);
GitRevision firstChange = singleChange(workTree, repo, "ignore_me", "Feature1 change");
GitRevision secondChange = singleChange(workTree, repo, "ignore_me2", "Feature2 change");
repo.simpleCommand("update-ref", "refs/pull/20/head", secondChange.getSha1());
GitDestination destination = destinationWithDefaultIntegrates();
GitLogEntry previous = createBaseDestinationChange(destination);
GitHubPrIntegrateLabel labelObj = new GitHubPrIntegrateLabel(repo, options.general, "example/test_repo", 20, "some_user:1234-foo.bar.baz%3", secondChange.getSha1());
assertThat(labelObj.getProjectId()).isEqualTo("example/test_repo");
assertThat(labelObj.getPrNumber()).isEqualTo(20L);
assertThat(labelObj.getOriginBranch()).isEqualTo("some_user:1234-foo.bar.baz%3");
assertThat(labelObj.mergeMessage(ImmutableList.of())).isEqualTo("Merge pull request #20 from some_user:1234-foo.bar.baz%3\n");
String label = labelObj.toString();
assertThat(label).isEqualTo("https://github.com/example/test_repo/pull/20" + " from some_user:1234-foo.bar.baz%3 " + secondChange.getSha1());
migrateOriginChange(destination, "Test change\n" + "\n" + GitModule.DEFAULT_INTEGRATE_LABEL + "=" + label + "\n", "some content");
// Make sure commit adds new text
String showResult = git("--git-dir", repoGitDir.toString(), "show", primaryBranch);
assertThat(showResult).contains("some content");
GitTesting.assertThatCheckout(repo(), primaryBranch).containsFile("test.txt", "some content").containsFile("ignore_me", "").containsFile("ignore_me2", "").containsNoMoreFiles();
GitLogEntry merge = getLastMigratedChange(primaryBranch);
assertThat(merge.getBody()).isEqualTo("Merge pull request #20 from some_user:1234-foo.bar.baz%3\n" + "\n" + "DummyOrigin-RevId: test\n");
assertThat(Lists.transform(merge.getParents(), GitRevision::getSha1)).isEqualTo(Lists.newArrayList(previous.getCommit().getSha1(), secondChange.getSha1()));
assertThat(console.getMessages().stream().filter(e -> e.getType() == MessageType.WARNING).collect(Collectors.toList())).isEmpty();
label = new GitHubPrIntegrateLabel(repo, options.general, "example/test_repo", 20, "some_user:branch", firstChange.getSha1()).toString();
assertThat(label).isEqualTo("https://github.com/example/test_repo/pull/20" + " from some_user:branch " + firstChange.getSha1());
repo().withWorkTree(workTree).simpleCommand("reset", "--hard", "HEAD~1");
migrateOriginChange(destination, "Test change\n" + "\n" + GitModule.DEFAULT_INTEGRATE_LABEL + "=" + label + "\n", "some content");
assertThat(console.getMessages().stream().filter(e -> e.getType() == MessageType.WARNING).findAny().get().getText()).contains("has more changes after " + firstChange.getSha1());
}
use of com.google.copybara.exception.ValidationException in project copybara by google.
the class GitDestinationIntegrateTest method testBadLabel.
@Test
public void testBadLabel() throws ValidationException, IOException, RepoException {
ValidationException e = assertThrows(ValidationException.class, () -> runBadLabel(/*ignoreErrors=*/
false));
assertThat(e.getMessage()).contains("Error resolving file:///non_existent_repository");
}
Aggregations