use of com.google.copybara.testing.DummyRevision 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");
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GerritDestinationTest method testPushToNonMasterDefaultRef.
@Test
public void testPushToNonMasterDefaultRef() throws Exception {
fetch = "fooze";
writeFile(workdir, "test.txt", "some content");
options.setForce(true);
process(new DummyRevision("origin_ref"));
// Make sure commit adds new text
String showResult = git("--git-dir", repoGitDir.toString(), "show", getGerritRef(repo(), "refs/for/fooze"));
assertThat(showResult).contains("some content");
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GerritDestinationTest method testReviewerFieldWithNoTopic.
@Test
public void testReviewerFieldWithNoTopic() throws Exception {
pushToRefsFor = "master";
writeFile(workdir, "file", "some content");
fetch = "master";
options.setForce(true);
url = "https://localhost:33333/foo/bar";
mockNoChangesFound();
DummyRevision originRef = new DummyRevision("origin_ref");
GerritDestination destination = destination("submit = False", "reviewers = [\"${SOME_REVIEWER}\"]");
Glob glob = Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths);
WriterContext writerContext = new WriterContext("GerritDestination", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
List<DestinationEffect> result = destination.newWriter(writerContext).write(TransformResults.of(workdir, originRef).withSummary("Test message").withIdentity(originRef.asString()).withLabelFinder(e -> e.equals("SOME_REVIEWER") ? ImmutableList.of("foo@example.com") : ImmutableList.of()), glob, console);
assertThat(result).hasSize(1);
assertThat(result.get(0).getErrors()).isEmpty();
assertPushRef("refs/for/master%hashtag=copybara_id_origin_ref_commiter@email," + "r=foo@example.com");
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GerritDestinationTest method runAllowEmptyPatchSetFalse.
private void runAllowEmptyPatchSetFalse(String baseline) throws ValidationException, RepoException, IOException {
fetch = repo().getPrimaryBranch();
DummyRevision originRef = new DummyRevision("origin_ref");
WriterContext writerContext = new WriterContext("GerritDestinationTest", "test", false, originRef, Glob.ALL_FILES.roots());
ImmutableList<DestinationEffect> result = destination("allow_empty_diff_patchset = False").newWriter(writerContext).write(TransformResults.of(workdir, originRef).withIdentity(originRef.asString()).withBaseline(baseline), Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths), console);
assertThat(result).hasSize(1);
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GerritDestinationTest method testPushToNonDefaultRef.
@Test
public void testPushToNonDefaultRef() throws Exception {
fetch = "master";
pushToRefsFor = "testPushToRef";
writeFile(workdir, "test.txt", "some content");
options.setForce(true);
process(new DummyRevision("origin_ref"));
GitRepository repo = repo();
// Make sure commit adds new text
String showResult = repo.simpleCommand("show", getGerritRef(repo, "refs/for/testPushToRef")).getStdout();
assertThat(showResult).contains("some content");
}
Aggregations