Search in sources :

Example 16 with DestinationEffect

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}");
}
Also used : Changes(com.google.copybara.Changes) TransformResult(com.google.copybara.TransformResult) DestinationEffect(com.google.copybara.DestinationEffect) Author(com.google.copybara.authoring.Author) Change(com.google.copybara.Change)

Example 17 with DestinationEffect

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}");
}
Also used : Path(java.nio.file.Path) WriterContext(com.google.copybara.WriterContext) Destination(com.google.copybara.Destination) DestinationEffect(com.google.copybara.DestinationEffect) DummyRevision(com.google.copybara.testing.DummyRevision)

Example 18 with DestinationEffect

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");
}
Also used : Path(java.nio.file.Path) WriterContext(com.google.copybara.WriterContext) Destination(com.google.copybara.Destination) DestinationEffect(com.google.copybara.DestinationEffect) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 19 with DestinationEffect

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");
}
Also used : TransformResult(com.google.copybara.TransformResult) ZonedDateTime(java.time.ZonedDateTime) DestinationEffect(com.google.copybara.DestinationEffect) DummyRevision(com.google.copybara.testing.DummyRevision) Author(com.google.copybara.authoring.Author) HgLogEntry(com.google.copybara.hg.HgRepository.HgLogEntry) Test(org.junit.Test)

Example 20 with DestinationEffect

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();
}
Also used : DestinationRef(com.google.copybara.DestinationEffect.DestinationRef) InfoFinishedEvent(com.google.copybara.monitor.EventMonitor.InfoFinishedEvent) DestinationEffect(com.google.copybara.DestinationEffect) ChangeMigrationFinishedEvent(com.google.copybara.monitor.EventMonitor.ChangeMigrationFinishedEvent) ChangeMigrationStartedEvent(com.google.copybara.monitor.EventMonitor.ChangeMigrationStartedEvent) DummyRevision(com.google.copybara.testing.DummyRevision) MigrationStartedEvent(com.google.copybara.monitor.EventMonitor.MigrationStartedEvent) ChangeMigrationStartedEvent(com.google.copybara.monitor.EventMonitor.ChangeMigrationStartedEvent) MigrationFinishedEvent(com.google.copybara.monitor.EventMonitor.MigrationFinishedEvent) ChangeMigrationFinishedEvent(com.google.copybara.monitor.EventMonitor.ChangeMigrationFinishedEvent) OriginRef(com.google.copybara.DestinationEffect.OriginRef) Test(org.junit.Test)

Aggregations

DestinationEffect (com.google.copybara.DestinationEffect)39 DummyRevision (com.google.copybara.testing.DummyRevision)26 Test (org.junit.Test)23 WriterContext (com.google.copybara.WriterContext)19 Author (com.google.copybara.authoring.Author)13 Glob (com.google.copybara.util.Glob)12 ImmutableList (com.google.common.collect.ImmutableList)11 Changes (com.google.copybara.Changes)10 ChangeMessage (com.google.copybara.ChangeMessage)8 Metadata (com.google.copybara.Metadata)7 MigrationInfo (com.google.copybara.MigrationInfo)7 TransformResult (com.google.copybara.TransformResult)7 TransformWork (com.google.copybara.TransformWork)7 CheckerException (com.google.copybara.checks.CheckerException)7 ValidationException (com.google.copybara.exception.ValidationException)7 GerritMessageInfo (com.google.copybara.git.GerritDestination.GerritMessageInfo)7 DummyChecker (com.google.copybara.testing.DummyChecker)7 FileSubjects.assertThatPath (com.google.copybara.testing.FileSubjects.assertThatPath)7 LowLevelHttpRequest (com.google.api.client.http.LowLevelHttpRequest)6 Joiner (com.google.common.base.Joiner)6