Search in sources :

Example 66 with DummyRevision

use of com.google.copybara.testing.DummyRevision 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 67 with DummyRevision

use of com.google.copybara.testing.DummyRevision 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 68 with DummyRevision

use of com.google.copybara.testing.DummyRevision 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 69 with DummyRevision

use of com.google.copybara.testing.DummyRevision in project copybara by google.

the class HgDestinationTest method createRevisionAndWrite.

private void createRevisionAndWrite(String referenceName) throws RepoException, ValidationException, IOException {
    DummyRevision originRef = new DummyRevision(referenceName);
    TransformResult result = TransformResults.of(workdir, originRef);
    writer.write(result, destinationFiles, console);
}
Also used : TransformResult(com.google.copybara.TransformResult) DummyRevision(com.google.copybara.testing.DummyRevision)

Example 70 with DummyRevision

use of com.google.copybara.testing.DummyRevision 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

DummyRevision (com.google.copybara.testing.DummyRevision)144 Test (org.junit.Test)124 WriterContext (com.google.copybara.WriterContext)58 Path (java.nio.file.Path)29 DestinationEffect (com.google.copybara.DestinationEffect)28 Author (com.google.copybara.authoring.Author)21 Changes (com.google.copybara.Changes)19 Glob (com.google.copybara.util.Glob)19 ValidationException (com.google.copybara.exception.ValidationException)18 IOException (java.io.IOException)16 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)14 TransformResult (com.google.copybara.TransformResult)13 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)13 ZonedDateTime (java.time.ZonedDateTime)13 TransformWork (com.google.copybara.TransformWork)12 RepoException (com.google.copybara.exception.RepoException)12 CheckerException (com.google.copybara.checks.CheckerException)11 DummyChecker (com.google.copybara.testing.DummyChecker)11 FileSubjects.assertThatPath (com.google.copybara.testing.FileSubjects.assertThatPath)11 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)11