Search in sources :

Example 1 with Writer

use of com.google.copybara.Destination.Writer in project copybara by google.

the class GitDestinationTest method testChangeDescriptionEmpty_empty_commit.

@Test
public void testChangeDescriptionEmpty_empty_commit() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    Path scratchTree = Files.createTempDirectory("GitDestinationTest-testLocalRepo");
    Files.write(scratchTree.resolve("foo"), "foo\n".getBytes(UTF_8));
    repo().withWorkTree(scratchTree).add().force().files("foo").run();
    repo().withWorkTree(scratchTree).simpleCommand("commit", "-a", "-m", "change");
    DummyRevision originRef = new DummyRevision("origin_ref");
    WriterContext writerContext = new WriterContext("GitDestinationTest", "test", true, new DummyRevision("origin_ref1"), Glob.ALL_FILES.roots());
    Writer<GitRevision> writer = destination().newWriter(writerContext);
    ValidationException e = assertThrows(EmptyChangeException.class, () -> writer.write(TransformResults.of(workdir, originRef).withSummary("").withLabelFinder(s -> ImmutableList.of()).withSetRevId(false), Glob.createGlob(ImmutableList.of("nothing_to_be_found"), ImmutableList.of("test.txt")), console));
    assertThat(e).hasMessageThat().contains("Migration of the revision resulted in an empty change");
}
Also used : Path(java.nio.file.Path) TransformResult(com.google.copybara.TransformResult) ZonedDateTime(java.time.ZonedDateTime) DestinationEffect(com.google.copybara.DestinationEffect) WriterContext(com.google.copybara.WriterContext) VisitResult(com.google.copybara.ChangeVisitable.VisitResult) Author(com.google.copybara.authoring.Author) GitTestUtil.getGitEnv(com.google.copybara.testing.git.GitTestUtil.getGitEnv) Change(com.google.copybara.Change) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) ZoneOffset(java.time.ZoneOffset) GitTesting(com.google.copybara.git.testing.GitTesting) Path(java.nio.file.Path) DEFAULT_TIMEOUT(com.google.copybara.util.CommandRunner.DEFAULT_TIMEOUT) Type(com.google.copybara.DestinationEffect.Type) ImmutableSet(com.google.common.collect.ImmutableSet) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) ImmutableMap(com.google.common.collect.ImmutableMap) GitTesting.assertThatCheckout(com.google.copybara.git.testing.GitTesting.assertThatCheckout) DestinationStatus(com.google.copybara.Destination.DestinationStatus) Instant(java.time.Instant) ZoneId(java.time.ZoneId) CheckerException(com.google.copybara.checks.CheckerException) List(java.util.List) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Writer(com.google.copybara.Destination.Writer) DummyRevision(com.google.copybara.testing.DummyRevision) Assert.assertThrows(org.junit.Assert.assertThrows) DummyOrigin(com.google.copybara.testing.DummyOrigin) RunWith(org.junit.runner.RunWith) RepoException(com.google.copybara.exception.RepoException) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) MessageType(com.google.copybara.util.console.Message.MessageType) Changes(com.google.copybara.Changes) ChangeMessage(com.google.copybara.ChangeMessage) ArrayList(java.util.ArrayList) Truth(com.google.common.truth.Truth) ImmutableList(com.google.common.collect.ImmutableList) TransformResults(com.google.copybara.testing.TransformResults) CommandOutput(com.google.copybara.util.CommandOutput) Nullable(javax.annotation.Nullable) Before(org.junit.Before) Functions(com.google.common.base.Functions) ChangeMessage.parseMessage(com.google.copybara.ChangeMessage.parseMessage) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) DummyChecker(com.google.copybara.testing.DummyChecker) ValidationException(com.google.copybara.exception.ValidationException) UserPassword(com.google.copybara.git.GitCredential.UserPassword) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Maps(com.google.common.collect.Maps) Baseline(com.google.copybara.Origin.Baseline) Glob(com.google.copybara.util.Glob) TransformWorks(com.google.copybara.testing.TransformWorks) GitTestUtil.writeFile(com.google.copybara.testing.git.GitTestUtil.writeFile) WriterContext(com.google.copybara.WriterContext) ValidationException(com.google.copybara.exception.ValidationException) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 2 with Writer

use of com.google.copybara.Destination.Writer in project copybara by google.

the class GitDestinationTest method testChangeDescriptionEmpty_setRevId.

@Test
public void testChangeDescriptionEmpty_setRevId() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    Path scratchTree = Files.createTempDirectory("GitDestinationTest-testLocalRepo");
    Files.write(scratchTree.resolve("foo"), "foo\n".getBytes(UTF_8));
    repo().withWorkTree(scratchTree).add().force().files("foo").run();
    repo().withWorkTree(scratchTree).simpleCommand("commit", "-a", "-m", "change");
    DummyRevision originRef = new DummyRevision("origin_ref");
    WriterContext writerContext = new WriterContext("GitDestinationTest", "test", true, new DummyRevision("origin_ref1"), Glob.ALL_FILES.roots());
    Writer<GitRevision> writer = destination().newWriter(writerContext);
    ValidationException e = assertThrows(ValidationException.class, () -> writer.write(TransformResults.of(workdir, originRef).withSummary("").withLabelFinder(s -> ImmutableList.of()).withSetRevId(false), Glob.createGlob(ImmutableList.of("**"), ImmutableList.of("test.txt")), console));
    assertThat(e).hasMessageThat().contains("Change description is empty");
}
Also used : Path(java.nio.file.Path) TransformResult(com.google.copybara.TransformResult) ZonedDateTime(java.time.ZonedDateTime) DestinationEffect(com.google.copybara.DestinationEffect) WriterContext(com.google.copybara.WriterContext) VisitResult(com.google.copybara.ChangeVisitable.VisitResult) Author(com.google.copybara.authoring.Author) GitTestUtil.getGitEnv(com.google.copybara.testing.git.GitTestUtil.getGitEnv) Change(com.google.copybara.Change) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) ZoneOffset(java.time.ZoneOffset) GitTesting(com.google.copybara.git.testing.GitTesting) Path(java.nio.file.Path) DEFAULT_TIMEOUT(com.google.copybara.util.CommandRunner.DEFAULT_TIMEOUT) Type(com.google.copybara.DestinationEffect.Type) ImmutableSet(com.google.common.collect.ImmutableSet) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) ImmutableMap(com.google.common.collect.ImmutableMap) GitTesting.assertThatCheckout(com.google.copybara.git.testing.GitTesting.assertThatCheckout) DestinationStatus(com.google.copybara.Destination.DestinationStatus) Instant(java.time.Instant) ZoneId(java.time.ZoneId) CheckerException(com.google.copybara.checks.CheckerException) List(java.util.List) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Writer(com.google.copybara.Destination.Writer) DummyRevision(com.google.copybara.testing.DummyRevision) Assert.assertThrows(org.junit.Assert.assertThrows) DummyOrigin(com.google.copybara.testing.DummyOrigin) RunWith(org.junit.runner.RunWith) RepoException(com.google.copybara.exception.RepoException) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) MessageType(com.google.copybara.util.console.Message.MessageType) Changes(com.google.copybara.Changes) ChangeMessage(com.google.copybara.ChangeMessage) ArrayList(java.util.ArrayList) Truth(com.google.common.truth.Truth) ImmutableList(com.google.common.collect.ImmutableList) TransformResults(com.google.copybara.testing.TransformResults) CommandOutput(com.google.copybara.util.CommandOutput) Nullable(javax.annotation.Nullable) Before(org.junit.Before) Functions(com.google.common.base.Functions) ChangeMessage.parseMessage(com.google.copybara.ChangeMessage.parseMessage) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) DummyChecker(com.google.copybara.testing.DummyChecker) ValidationException(com.google.copybara.exception.ValidationException) UserPassword(com.google.copybara.git.GitCredential.UserPassword) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Maps(com.google.common.collect.Maps) Baseline(com.google.copybara.Origin.Baseline) Glob(com.google.copybara.util.Glob) TransformWorks(com.google.copybara.testing.TransformWorks) GitTestUtil.writeFile(com.google.copybara.testing.git.GitTestUtil.writeFile) WriterContext(com.google.copybara.WriterContext) ValidationException(com.google.copybara.exception.ValidationException) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Aggregations

Functions (com.google.common.base.Functions)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)2 Maps (com.google.common.collect.Maps)2 Truth (com.google.common.truth.Truth)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 Change (com.google.copybara.Change)2 ChangeMessage (com.google.copybara.ChangeMessage)2 ChangeMessage.parseMessage (com.google.copybara.ChangeMessage.parseMessage)2 VisitResult (com.google.copybara.ChangeVisitable.VisitResult)2 Changes (com.google.copybara.Changes)2 DestinationStatus (com.google.copybara.Destination.DestinationStatus)2 Writer (com.google.copybara.Destination.Writer)2 DestinationEffect (com.google.copybara.DestinationEffect)2 Type (com.google.copybara.DestinationEffect.Type)2 Baseline (com.google.copybara.Origin.Baseline)2 TransformResult (com.google.copybara.TransformResult)2