Search in sources :

Example 1 with GerritApiException

use of com.google.copybara.git.gerritapi.GerritApiException in project copybara by google.

the class GerritDestinationTest method gerritSubmit_fail.

@Test
public void gerritSubmit_fail() throws Exception {
    options.gerrit.gerritChangeId = null;
    fetch = "master";
    writeFile(workdir, "file", "some content");
    url = BASE_URL + "/foo/bar";
    repoGitDir = gitUtil.mockRemoteRepo("user:SECRET@copybara-not-real.com/foo/bar").getGitDir();
    gitUtil.mockApi(eq("GET"), startsWith(BASE_URL + "/changes/"), mockResponse("[" + "{" + "  change_id : \"12345\"," + "  status : \"NEW\"" + "}]"));
    gitUtil.mockApi(eq("POST"), matches(BASE_URL + "/changes/.*/revisions/.*/review"), mockResponse("{\"labels\": { \"Code-Review\": 2}}"));
    gitUtil.mockApi(eq("POST"), matches(BASE_URL + "/changes/.*/submit"), mockResponseWithStatus("Submit failed.", 403));
    options.setForce(true);
    DummyRevision originRef = new DummyRevision("origin_ref");
    GerritDestination destination = destination("submit = True", "gerrit_submit = True");
    Glob glob = Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths);
    WriterContext writerContext = new WriterContext("GerritDestinationTest", "test", false, originRef, Glob.ALL_FILES.roots());
    GerritApiException gerritApiException = assertThrows(GerritApiException.class, () -> destination.newWriter(writerContext).write(TransformResults.of(workdir, originRef).withSummary("Test message").withIdentity(originRef.asString()), glob, console));
    assertThat(gerritApiException).hasMessageThat().contains("Submit failed");
}
Also used : WriterContext(com.google.copybara.WriterContext) DummyRevision(com.google.copybara.testing.DummyRevision) Glob(com.google.copybara.util.Glob) GerritApiException(com.google.copybara.git.gerritapi.GerritApiException) Test(org.junit.Test)

Aggregations

WriterContext (com.google.copybara.WriterContext)1 GerritApiException (com.google.copybara.git.gerritapi.GerritApiException)1 DummyRevision (com.google.copybara.testing.DummyRevision)1 Glob (com.google.copybara.util.Glob)1 Test (org.junit.Test)1