use of com.google.copybara.DestinationEffect in project copybara by google.
the class GitHubDestinationTest method process.
private void process(Writer<GitRevision> writer, DummyRevision ref) throws ValidationException, RepoException, IOException {
TransformResult result = TransformResults.of(workdir, ref);
Changes changes = new Changes(ImmutableList.of(new Change<>(ref, new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "12345")), new Change<>(ref, new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "6789"))), ImmutableList.of());
result = result.withChanges(changes);
ImmutableList<DestinationEffect> destinationResult = writer.write(result, destinationFiles, console);
assertThat(destinationResult).hasSize(1);
assertThat(destinationResult.get(0).getErrors()).isEmpty();
assertThat(destinationResult.get(0).getType()).isEqualTo(Type.CREATED);
assertThat(destinationResult.get(0).getDestinationRef().getType()).isEqualTo("commit");
assertThat(destinationResult.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");
}
use of com.google.copybara.DestinationEffect in project copybara by google.
the class SubmodulesInDestinationTest method writeWithSubmoduleInDestination.
private void writeWithSubmoduleInDestination() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
Path scratchTree = Files.createTempDirectory("SubmodulesInDestinationTest-scratchTree");
GitRepository scratchRepo = repo().withWorkTree(scratchTree);
scratchRepo.simpleCommand("submodule", "add", "file://" + submodule.getGitDir(), "submodule");
scratchRepo.simpleCommand("commit", "-m", "commit submodule");
Files.write(workdir.resolve("test42"), new byte[] { 42 });
WriterContext writerContext = new WriterContext("SubmodulesInDestinationTest", "Test", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
Destination.Writer<GitRevision> writer = destination().newWriter(writerContext);
ImmutableList<DestinationEffect> result = writer.write(TransformResults.of(workdir, new DummyRevision("ref1")), destinationFiles, 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.DestinationEffect in project copybara by google.
the class SubmodulesInDestinationTest method submoduleInSubdirectoryWithSiblingFiles.
@Test
public void submoduleInSubdirectoryWithSiblingFiles() throws Exception {
destinationFiles = Glob.createGlob(ImmutableList.of("foo/a", "foo/c"));
fetch = primaryBranch;
push = primaryBranch;
Path scratchTree = Files.createTempDirectory("SubmodulesInDestinationTest-scratchTree");
GitRepository scratchRepo = repo().withWorkTree(scratchTree);
Files.createDirectories(scratchTree.resolve("foo"));
Files.write(scratchTree.resolve("foo/a"), new byte[] { 1 });
scratchRepo.add().files("foo/a").run();
scratchRepo.simpleCommand("submodule", "add", "file://" + submodule.getGitDir(), "foo/b");
scratchRepo.simpleCommand("commit", "-m", "commit submodule and foo/a");
// Create a commit that removes foo/a and adds foo/c
Files.createDirectories(workdir.resolve("foo"));
Files.write(workdir.resolve("foo/c"), new byte[] { 1 });
WriterContext writerContext = new WriterContext("SubmodulesInDestinationTest", "Test", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
Destination.Writer<GitRevision> writer = destination().newWriter(writerContext);
ImmutableList<DestinationEffect> result = writer.write(TransformResults.of(workdir, new DummyRevision("ref1")), destinationFiles, 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}");
GitTesting.assertThatCheckout(repo(), primaryBranch).containsFiles("foo/c", "foo/b").containsNoFiles("foo/a");
}
use of com.google.copybara.DestinationEffect in project copybara by google.
the class HgDestinationTest method testWrite.
@Test
public void testWrite() throws Exception {
Files.write(workdir.resolve("file.txt"), "first write".getBytes(UTF_8));
Files.write(workdir.resolve("test.txt"), "test".getBytes(UTF_8));
ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(1496333940000L), ZoneId.of("-04:00"));
DummyRevision originRef = new DummyRevision("origin_ref").withAuthor(new Author("Copy Bara", "copy@bara.com")).withTimestamp(zonedDateTime);
TransformResult result = TransformResults.of(workdir, originRef);
ImmutableList<DestinationEffect> destinationResult = writer.write(result, destinationFiles, console);
assertThat(destinationResult).hasSize(1);
assertThat(destinationResult.get(0).getErrors()).isEmpty();
assertThat(destinationResult.get(0).getType()).isEqualTo(Type.CREATED);
assertThat(destinationResult.get(0).getDestinationRef().getType()).isEqualTo("commit");
assertThat(destinationResult.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");
ImmutableList<HgLogEntry> commits = remoteRepo.log().run();
assertThat(commits).hasSize(2);
assertThat(commits.get(0).getDescription()).isEqualTo("" + "test summary\n" + "\n" + "DummyOrigin-RevId: origin_ref");
assertThat(commits).hasSize(2);
assertThat(commits.get(0).getZonedDate()).isEqualTo(zonedDateTime);
assertThat(commits.get(0).getFiles()).hasSize(1);
assertThat(commits.get(0).getFiles().get(0)).isEqualTo("test.txt");
assertThat(commits.get(1).getFiles()).hasSize(1);
assertThat(commits.get(1).getFiles().get(0)).isEqualTo("file.txt");
}
use of com.google.copybara.DestinationEffect in project copybara by google.
the class ConsoleEventMonitorTest method testEventMonitorPrintsToConsole.
@Test
public void testEventMonitorPrintsToConsole() {
eventMonitor.onMigrationStarted(new MigrationStartedEvent());
eventMonitor.onMigrationFinished(new MigrationFinishedEvent(ExitCode.SUCCESS));
eventMonitor.onChangeMigrationStarted(new ChangeMigrationStartedEvent());
DestinationEffect destinationEffect = new DestinationEffect(Type.CREATED, "Created revision 1234", ImmutableList.of(new OriginRef("ABCD")), new DestinationRef("1234", "commit", /*url=*/
null));
eventMonitor.onChangeMigrationFinished(new ChangeMigrationFinishedEvent(ImmutableList.of(destinationEffect), ImmutableMultimap.of(), ImmutableMultimap.of()));
MigrationReference<DummyRevision> workflow = MigrationReference.create("workflow", new DummyRevision("1111"), ImmutableList.of(newChange("2222"), newChange("3333")));
Info<?> info = Info.create(ImmutableMultimap.of("origin", "foo"), ImmutableMultimap.of("dest", "bar"), ImmutableList.of(workflow));
eventMonitor.onInfoFinished(new InfoFinishedEvent(info, ImmutableMap.of("foo_a", "foo_b")));
console.assertThat().equalsNext(VERBOSE, "onMigrationStarted(): MigrationStartedEvent").equalsNext(VERBOSE, "onMigrationFinished(): " + "MigrationFinishedEvent{exitCode=SUCCESS, profiler=null}").equalsNext(VERBOSE, "onChangeMigrationStarted(): ChangeMigrationStartedEvent{}").matchesNext(VERBOSE, "onChangeMigrationFinished[(][)]: ChangeMigrationFinishedEvent[{].*[}]").matchesNext(VERBOSE, "onInfoFinished[(][)]: InfoFinishedEvent[{].*(origin).*" + "(foo).*(dest).*(bar).*(foo_a).*(foo_b).*[}]").containsNoMoreMessages();
}
Aggregations