use of com.google.copybara.util.Glob in project copybara by google.
the class GerritDestinationTest method testLabels.
@Test
public void testLabels() 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", "labels = [\"${SOME_LABELS}\"]");
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_LABELS") ? ImmutableList.of("Foo+1", "Bar-1") : 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," + "label=Foo\\+1,label=Bar-1");
}
use of com.google.copybara.util.Glob in project copybara by google.
the class GerritDestinationTest method testReviewersFieldWithTopic.
@Test
public void testReviewersFieldWithTopic() 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", "bar@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,r=bar@example.com");
}
use of com.google.copybara.util.Glob in project copybara by google.
the class GerritDestinationTest method testChecker.
@Test
public void testChecker() throws Exception {
options.gerrit.gerritChangeId = null;
fetch = "master";
pushToRefsFor = "master";
writeFile(workdir, "file", "BAD");
options.setForce(true);
url = "https://localhost:33333/foo/bar";
GitRepository repo = gitUtil.mockRemoteRepo("localhost:33333/foo/bar");
mockNoChangesFound();
DummyRevision originRef = new DummyRevision("origin_ref");
options.testingOptions.checker = new DummyChecker(ImmutableSet.of("BAD"));
GerritDestination destination = destination("submit = True, checker = testing.dummy_checker()");
Glob glob = Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths);
WriterContext writerContext = new WriterContext("GerritDestinationTest", "test", false, originRef, Glob.ALL_FILES.roots());
assertThat(assertThrows(CheckerException.class, () -> destination.newWriter(writerContext).write(TransformResults.of(workdir, originRef).withSummary("Test message").withIdentity(originRef.asString()), glob, console))).hasMessageThat().contains("Bad word 'bad' found");
}
use of com.google.copybara.util.Glob in project copybara by google.
the class GitDestinationTest method multipleMigrationsToOneDestination_withComplexGlobs.
/**
* Verify that multiple (exclusive) migrations can write to the same Git repository. This is,
* migrations from different origins writing to a different subpaths in the Git repo and excluding
* the other ones.
*/
@Test
public void multipleMigrationsToOneDestination_withComplexGlobs() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
Files.createDirectories(workdir.resolve("foo"));
Files.createDirectories(workdir.resolve("foo/bar"));
Files.createDirectories(workdir.resolve("baz"));
Files.write(workdir.resolve("foo/one"), "First version".getBytes(UTF_8));
Files.write(workdir.resolve("foo/bar/one"), "First version".getBytes(UTF_8));
Files.write(workdir.resolve("baz/one"), "First version".getBytes(UTF_8));
repo().withWorkTree(workdir).add().files("foo/one").files("foo/bar/one").files("baz/one").run();
repo().withWorkTree(workdir).simpleCommand("commit", "-m", "Initial commit");
Glob repoAglob = Glob.createGlob(ImmutableList.of("foo/**"), ImmutableList.of("foo/bar/**"));
Glob repoBglob = Glob.createGlob(ImmutableList.of("foo/bar/**"));
// Change on repo A
Files.write(workdir.resolve("foo/one"), "Second version".getBytes(UTF_8));
Writer<GitRevision> writer1 = newWriter();
DummyRevision repoAfirstRev = new DummyRevision("Foo first");
process(writer1, repoAglob, repoAfirstRev);
assertThatCheckout(repo(), primaryBranch).containsFile("foo/one", "Second version").containsFile("foo/bar/one", "First version").containsFile("baz/one", "First version").containsNoMoreFiles();
verifyDestinationStatus(repoAglob, repoAfirstRev);
// Change on repo B, does not affect repo A paths
Files.write(workdir.resolve("foo/bar/one"), "Second version".getBytes(UTF_8));
Writer<GitRevision> writer2 = newWriter();
DummyRevision repoBfirstRev = new DummyRevision("Bar first");
process(writer2, repoBglob, repoBfirstRev);
assertThatCheckout(repo(), primaryBranch).containsFile("foo/one", "Second version").containsFile("foo/bar/one", "Second version").containsFile("baz/one", "First version").containsNoMoreFiles();
verifyDestinationStatus(repoAglob, repoAfirstRev);
verifyDestinationStatus(repoBglob, repoBfirstRev);
// Change on repo A does not affect repo B paths
Files.write(workdir.resolve("foo/one"), "Third version".getBytes(UTF_8));
Writer<GitRevision> writer3 = newWriter();
DummyRevision repoASecondRev = new DummyRevision("Foo second");
process(writer3, repoAglob, repoASecondRev);
assertThatCheckout(repo(), primaryBranch).containsFile("foo/one", "Third version").containsFile("foo/bar/one", "Second version").containsFile("baz/one", "First version").containsNoMoreFiles();
verifyDestinationStatus(repoAglob, repoASecondRev);
verifyDestinationStatus(repoBglob, repoBfirstRev);
}
Aggregations