use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GerritDestinationTest method writesOriginTimestampToAuthorField.
@Test
public void writesOriginTimestampToAuthorField() throws Exception {
fetch = "master";
writeFile(workdir, "test.txt", "some content");
options.setForce(true);
ZonedDateTime time1 = ZonedDateTime.ofInstant(Instant.ofEpochSecond(355558888), ZoneId.of("-08:00"));
process(new DummyRevision("first_commit").withTimestamp(time1));
GitTesting.assertAuthorTimestamp(repo(), getGerritRef(repo(), "refs/for/master"), time1);
git("branch", "master", getGerritRef(repo(), "refs/for/master"));
writeFile(workdir, "test2.txt", "some more content");
options.setForce(false);
ZonedDateTime time2 = ZonedDateTime.ofInstant(Instant.ofEpochSecond(424242420), ZoneId.of("-08:00"));
process(new DummyRevision("first_commit").withTimestamp(time2));
GitTesting.assertAuthorTimestamp(repo(), getGerritRef(repo(), "refs/for/master"), time2);
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GerritDestinationTest method testFieldWithoutValue.
@Test
public void testFieldWithoutValue() throws Exception {
fetch = "master%wip";
writeFile(workdir, "file", "some content");
options.setForce(true);
String secondChangeId = "I" + Hashing.sha1().newHasher().putString("origin_ref", StandardCharsets.UTF_8).putString(options.gitDestination.committerEmail, StandardCharsets.UTF_8).putInt(1).hash();
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(String.format("[{ change_id : \"%s\", status : \"NEW\"}]", secondChangeId)));
process(new DummyRevision("origin_ref"));
String master = getGerritRef(repo(), "refs/for/master");
assertThat(master).isEqualTo("refs/for/master%wip,hashtag=copybara_id_origin_ref_commiter@email");
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GerritDestinationTest method gerritSubmit_noChange.
@Test
public void gerritSubmit_noChange() 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("[]"));
AtomicBoolean submitCalled = new AtomicBoolean(false);
AtomicBoolean reviewCalled = new AtomicBoolean(false);
gitUtil.mockApi(eq("POST"), matches(BASE_URL + "/changes/.*/revisions/.*/review"), mockResponseWithStatus("", 204, new MockRequestAssertion("Always true with side-effect", s -> {
reviewCalled.set(true);
return true;
})));
gitUtil.mockApi(eq("POST"), matches(BASE_URL + "/changes/.*/submit"), mockResponseWithStatus("", 204, 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());
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();
assertThat(submitCalled.get()).isFalse();
assertThat(reviewCalled.get()).isFalse();
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GerritDestinationTest method testPushToAutoDetectedRef.
@Test
public void testPushToAutoDetectedRef() throws Exception {
Path scratchWorkTree = Files.createTempDirectory("GitDestinationTest-testPushToAutoDetectedRef");
writeFile(scratchWorkTree, "excluded.txt", "something else");
repo().withWorkTree(scratchWorkTree).add().files("excluded.txt").run();
repo().withWorkTree(scratchWorkTree).simpleCommand("commit", "-m", "message");
writeFile(workdir, "test.txt", "some content");
pushToRefsFor = repo().getPrimaryBranch().equals("main") ? "master" : "main";
options.setForce(true);
fetch = pushToRefsFor;
primaryBranchMigration = "True";
process(new DummyRevision("origin_ref"));
// Make sure commit adds new text
String showResult = git("--git-dir", repoGitDir.toString(), "show", getGerritRef(repo(), String.format("refs/for/%s.*", repo().getPrimaryBranch())));
assertThat(showResult).contains("some content");
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GerritDestinationTest method testReviewerFieldWithLabel.
@Test
public void testReviewerFieldWithLabel() throws Exception {
pushToRefsFor = "master%label=Foo";
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%label=Foo,hashtag=copybara_id_origin_ref_commiter@email," + "r=foo@example.com");
}
Aggregations