use of com.google.copybara.testing.git.GitTestUtil.MockRequestAssertion in project copybara by google.
the class GerritDestinationTest method gerritSubmit_plusTwoRestricted.
@Test
public void gerritSubmit_plusTwoRestricted() 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 : \"Iaaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\"," + " status : \"NEW\"" + "}]"));
AtomicBoolean submitCalled = new AtomicBoolean(false);
AtomicBoolean reviewCalled = new AtomicBoolean(false);
gitUtil.mockApi(eq("POST"), matches(BASE_URL + "/changes/.*/revisions/.*/review"), mockResponseWithStatus("Applying label \\\"Code-Review\\\": 2 is restricted\\n\\n", 401));
gitUtil.mockApi(eq("POST"), matches(BASE_URL + "/changes/.*/submit"), mockResponseAndValidateRequest("{" + " change_id : \"Iaaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\"," + " status : \"submitted\"" + "}", new MockRequestAssertion("Always true with side-effect", s -> {
submitCalled.set(true);
return true;
})));
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());
ValidationException validationException = assertThrows(ValidationException.class, () -> destination.newWriter(writerContext).write(TransformResults.of(workdir, originRef).withSummary("Test message").withIdentity(originRef.asString()), glob, console));
assertThat(validationException).hasMessageThat().contains("2 is restricted");
}
use of com.google.copybara.testing.git.GitTestUtil.MockRequestAssertion in project copybara by google.
the class GitHubEndpointTest method testFeedbackDeleteReference.
@Test
public void testFeedbackDeleteReference() throws Exception {
AtomicBoolean called = new AtomicBoolean(false);
gitUtil.mockApi(eq("DELETE"), contains("/git/refs/heads/test"), mockResponseWithStatus("", 202, new MockRequestAssertion("Always true with side-effect", s -> {
called.set(true);
return true;
})));
runFeedback(ImmutableList.of("ctx.destination.delete_reference('refs/heads/test')"));
assertThat(called.get()).isTrue();
}
use of com.google.copybara.testing.git.GitTestUtil.MockRequestAssertion in project copybara by google.
the class GitHubEndpointTest method testFeedbackDeleteReference_masterCheck.
@Test
public void testFeedbackDeleteReference_masterCheck() {
AtomicBoolean called = new AtomicBoolean(false);
gitUtil.mockApi(eq("DELETE"), contains("/git/refs/heads/master"), mockResponseWithStatus("", 202, new MockRequestAssertion("Always true with side-effect", s -> {
called.set(true);
return true;
})));
ValidationException expected = assertThrows(ValidationException.class, () -> runFeedback(ImmutableList.of("ctx.destination.delete_reference('refs/heads/master')")));
assertThat(expected).hasMessageThat().contains("Copybara doesn't allow to delete master");
assertThat(called.get()).isFalse();
}
Aggregations