use of com.google.copybara.WriterContext in project copybara by google.
the class FolderDestinationTest method write.
private void write() throws ValidationException, RepoException, IOException {
WriterContext writerContext = new WriterContext("FolderDestinationTest", "test", false, new DummyRevision("origin_ref"), Glob.ALL_FILES.roots());
skylark.<Destination<Revision>>eval("dest", "dest = folder.destination()").newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("origin_ref")), Glob.createGlob(ImmutableList.of("**"), excludedPathsForDeletion), options.general.console());
}
use of com.google.copybara.WriterContext 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.WriterContext 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");
}
use of com.google.copybara.WriterContext in project copybara by google.
the class GerritDestinationTest method testReviewerFieldWithTopic.
@Test
public void testReviewerFieldWithTopic() 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()).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%topic=testTopic,hashtag=copybara_id_origin_ref_commiter@email," + "r=foo@example.com");
}
use of com.google.copybara.WriterContext in project copybara by google.
the class GerritDestinationTest method gerritSubmit_success.
@Test
public void gerritSubmit_success() 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"), mockResponseAndValidateRequest("{\"labels\": { \"Code-Review\": 2}}", new MockRequestAssertion("Always true with side-effect", s -> {
reviewCalled.set(true);
return true;
})));
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());
List<DestinationEffect> result = destination.newWriter(writerContext).write(TransformResults.of(workdir, originRef).withSummary("Test message").withIdentity(originRef.asString()), glob, console);
assertThat(reviewCalled.get()).isTrue();
assertThat(submitCalled.get()).isTrue();
assertThat(result).hasSize(1);
assertThat(result.get(0).getErrors()).isEmpty();
}
Aggregations