Search in sources :

Example 56 with ValidationException

use of com.google.copybara.exception.ValidationException in project copybara by google.

the class GitCredentialTest method testNotFound.

@Test
public void testNotFound() throws Exception {
    ValidationException expected = assertThrows(ValidationException.class, () -> credential.fill(repoGitDir, "https://somehost.com/foo/bar"));
    assertThat(expected).hasMessageThat().contains("Interactive prompting of passwords for git is disabled");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Example 57 with ValidationException

use of com.google.copybara.exception.ValidationException 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 58 with ValidationException

use of com.google.copybara.exception.ValidationException in project copybara by google.

the class GitDestinationTest method processFetchRefDoesntExist.

@Test
public void processFetchRefDoesntExist() throws Exception {
    fetch = "testPullFromRef";
    push = "testPushToRef";
    Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
    ValidationException thrown = assertThrows(ValidationException.class, () -> process(newWriter(), new DummyRevision("origin_ref")));
    assertThat(thrown).hasMessageThat().contains("'refs/heads/testPullFromRef' doesn't exist");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 59 with ValidationException

use of com.google.copybara.exception.ValidationException in project copybara by google.

the class GitDestinationTest method processUserAborts.

@Test
public void processUserAborts() throws Exception {
    console = new TestingConsole().respondNo();
    fetch = primaryBranch;
    push = primaryBranch;
    Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
    ValidationException thrown = assertThrows(ValidationException.class, () -> processWithBaselineAndConfirmation(firstCommitWriter(), destinationFiles, new DummyRevision("origin_ref"), /*baseline=*/
    null, /*askForConfirmation=*/
    true));
    assertThat(thrown).hasMessageThat().contains("User aborted execution: did not confirm diff changes");
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) ValidationException(com.google.copybara.exception.ValidationException) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 60 with ValidationException

use of com.google.copybara.exception.ValidationException in project copybara by google.

the class GitDestinationTest method gitUserEmailMustBeConfigured.

@Test
public void gitUserEmailMustBeConfigured() throws Exception {
    options.gitDestination.committerName = "Foo Bara";
    options.gitDestination.committerEmail = "";
    fetch = primaryBranch;
    push = primaryBranch;
    ValidationException thrown = assertThrows(ValidationException.class, () -> process(firstCommitWriter(), new DummyRevision("first_commit")));
    assertThat(thrown).hasMessageThat().contains("'user.name' and/or 'user.email' are not configured.");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Aggregations

ValidationException (com.google.copybara.exception.ValidationException)178 Test (org.junit.Test)125 Path (java.nio.file.Path)33 RepoException (com.google.copybara.exception.RepoException)29 NonReversibleValidationException (com.google.copybara.exception.NonReversibleValidationException)26 ImmutableList (com.google.common.collect.ImmutableList)21 IOException (java.io.IOException)19 Console (com.google.copybara.util.console.Console)16 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)14 DummyRevision (com.google.copybara.testing.DummyRevision)14 Glob (com.google.copybara.util.Glob)14 ProfilerTask (com.google.copybara.profiler.Profiler.ProfilerTask)13 Nullable (javax.annotation.Nullable)13 Migration (com.google.copybara.config.Migration)11 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)11 Iterables (com.google.common.collect.Iterables)10 Change (com.google.copybara.Change)10 CannotResolveRevisionException (com.google.copybara.exception.CannotResolveRevisionException)10 Collectors (java.util.stream.Collectors)10 WriterContext (com.google.copybara.WriterContext)9