use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GerritDestinationTest method process.
private void process(DummyRevision originRef, GerritDestination destination) throws ValidationException, RepoException, IOException {
WriterContext writerContext = new WriterContext("GerritDestination", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
Writer<GitRevision> gitRevisionWriter = destination.newWriter(writerContext);
// This is largely unused, except for the label finder.
TransformWork work = new TransformWork(workdir, new Metadata("Desc", new Author("foo", "foo@foo.com"), ImmutableSetMultimap.of()), Changes.EMPTY, console, new MigrationInfo(DummyOrigin.LABEL_NAME, null), originRef, console -> new DummyEndpoint(), console -> gitRevisionWriter.getFeedbackEndPoint(console), () -> gitRevisionWriter.getDestinationReader(console, null, workdir));
ImmutableList<DestinationEffect> result = gitRevisionWriter.write(TransformResults.of(workdir, originRef).withLabelFinder(work::getAllLabels).withIdentity(originRef.asString()), Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths), console);
assertThat(result).hasSize(1);
assertThat(result.get(0).getErrors()).isEmpty();
assertThat(result.get(0).getType()).isEqualTo(Type.CREATED);
assertThat(result.get(0).getDestinationRef().getType()).isEqualTo("commit");
assertThat(result.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GerritDestinationTest method gerritChangeIdChangesBetweenCommits.
@Test
public void gerritChangeIdChangesBetweenCommits() throws Exception {
fetch = "master";
gitUtil.mockApi(eq("GET"), eq("https://localhost:33333/changes/?q=" + "hashtag:%22copybara_id_origin_ref_commiter@email%22%20AND" + "%20project:foo/bar%20AND%20status:NEW"), mockResponse("[]"));
gitUtil.mockApi(eq("GET"), eq("https://localhost:33333/changes/?q=" + "hashtag:%22copybara_id_origin_ref2_commiter@email%22%20AND" + "%20project:foo/bar%20AND%20status:NEW"), mockResponse("[]"));
writeFile(workdir, "file", "some content");
options.setForce(true);
process(new DummyRevision("origin_ref"));
String firstChangeIdLine = lastCommitChangeIdLine("origin_ref", repo());
writeFile(workdir, "file2", "some more content");
git("branch", "master", getGerritRef(repo(), "refs/for/master"));
options.setForce(false);
process(new DummyRevision("origin_ref2"));
assertThat(firstChangeIdLine).isNotEqualTo(lastCommitChangeIdLine("origin_ref2", repo()));
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GerritDestinationTest method testEmptyReviewersField.
@Test
public void testEmptyReviewersField() throws Exception {
pushToRefsFor = "master";
writeFile(workdir, "file", "some content");
fetch = "master";
options.gerrit.gerritTopic = "testTopic";
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()), glob, console);
assertThat(result).hasSize(1);
assertThat(result.get(0).getErrors()).isEmpty();
assertPushRef("refs/for/master%topic=testTopic");
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GerritDestinationTest method runForDefaults.
private String runForDefaults() throws IOException, ValidationException, RepoException {
fakeOneCommitInDestination();
git("branch", "foo");
writeFile(workdir, "file", "some content");
String changeId = "Iaaaaaaaaaabbbbbbbbbbccccccccccdddddddddd";
options.gerrit.gerritChangeId = changeId;
process(new DummyRevision("origin_ref"));
return GerritDestination.CHANGE_ID_LABEL + ": " + changeId;
}
use of com.google.copybara.testing.DummyRevision 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");
}
Aggregations