use of com.google.copybara.WriterContext in project copybara by google.
the class FolderDestinationTest method testRelativePaths.
@Test
public void testRelativePaths() throws Exception {
Path dest = Files.createDirectories(Files.createTempDirectory("workdir").resolve("one"));
workdir = Files.createTempDirectory("local_folder");
Files.write(Files.createDirectories(dest.resolve("folder")).resolve("file1.txt"), "foo".getBytes(UTF_8));
Files.write(Files.createDirectories(workdir.resolve("folder")).resolve("file1.txt"), "bar".getBytes(UTF_8));
options.setWorkdirToRealTempDir();
options.folderDestination.localFolder = dest.resolve("../one").toString();
WriterContext writerContext = new WriterContext("not_important", "not_important", false, new DummyRevision("not_important"), Glob.ALL_FILES.roots());
skylark.<FolderDestination>eval("dest", "dest = folder.destination()").newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("not_important")), Glob.createGlob(ImmutableList.of("folder/file1.txt"), ImmutableList.of()), options.general.console());
assertThatPath(dest).containsFile("folder/file1.txt", "bar").containsNoMoreFiles();
}
use of com.google.copybara.WriterContext 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.WriterContext 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.WriterContext 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.WriterContext 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");
}
Aggregations