Search in sources :

Example 71 with ValidationException

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

the class GitOriginTest method testInvalidGithubUrl.

@Test
public void testInvalidGithubUrl() throws Exception {
    ValidationException expected = assertThrows(ValidationException.class, () -> skylark.eval("result", "result = git.github_origin(\n" + "    url = 'https://foo.com/copybara',\n" + "    ref = 'main',\n" + ")"));
    console.assertThat().onceInLog(MessageType.ERROR, ".*Invalid Github URL: https://foo.com/copybara.*");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Example 72 with ValidationException

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

the class GitOriginTest method testInvalidGithubUrlWithGithubString.

@Test
public void testInvalidGithubUrlWithGithubString() throws Exception {
    ValidationException expected = assertThrows(ValidationException.class, () -> skylark.eval("result", "result = git.github_origin(\n" + "    url = 'https://foo.com/github.com',\n" + "    ref = 'main',\n" + ")"));
    console.assertThat().onceInLog(MessageType.ERROR, ".*Invalid Github URL: https://foo.com/github.com.*");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Example 73 with ValidationException

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

the class GitOriginTest method partialFetchFailsWithFetchingTheWholeRepo.

@Test
public void partialFetchFailsWithFetchingTheWholeRepo() throws Exception {
    RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
    options.testingOptions.destination = destination;
    options.setLastRevision(firstCommitRef);
    @SuppressWarnings("unchecked") Workflow<GitRevision, Revision> wf = (Workflow<GitRevision, Revision>) skylark.loadConfig("" + "core.workflow(\n" + "    name = 'default',\n" + "    origin = git.origin(\n" + "         url = '" + url + "',\n" + "         include_branch_commit_logs = True,\n" + "         partial_fetch = True,\n" + "    ),\n" + "    origin_files = glob(['**']),\n" + "    destination = testing.destination(),\n" + "    authoring = authoring.pass_thru('example <example@example.com>'),\n" + ")\n").getMigration("default");
    ValidationException repoException = assertThrows(ValidationException.class, () -> wf.run(Files.createTempDirectory("foo"), ImmutableList.of("HEAD")));
    assertThat(repoException).hasMessageThat().contains("Config error: partial_fetch feature is not compatible with fetching the whole repo.");
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) ValidationException(com.google.copybara.exception.ValidationException) Revision(com.google.copybara.Revision) Workflow(com.google.copybara.Workflow) Test(org.junit.Test)

Example 74 with ValidationException

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

the class GitHubHostTest method testGetProjectNameFromUrl.

@Test
public void testGetProjectNameFromUrl() throws Exception {
    assertThat(GITHUB_COM.getProjectNameFromUrl("https://github.com/foo")).isEqualTo("foo");
    assertThat(GITHUB_COM.getProjectNameFromUrl("http://github.com/foo")).isEqualTo("foo");
    assertThat(GITHUB_COM.getProjectNameFromUrl("https://github.com/foo/bar")).isEqualTo("foo/bar");
    assertThat(GITHUB_COM.getProjectNameFromUrl("http://github.com/foo/bar")).isEqualTo("foo/bar");
    assertThat(GITHUB_COM.getProjectNameFromUrl("http://github.com/foo/bar/foobar")).isEqualTo("foo/bar");
    assertThat(GITHUB_COM.getProjectNameFromUrl("ssh://git@github.com/foo/bar.git")).isEqualTo("foo/bar");
    assertThat(GITHUB_COM.getProjectNameFromUrl("git@github.com/foo/bar.git")).isEqualTo("foo/bar");
    assertThat(GITHUB_COM.getProjectNameFromUrl("git@github.com:foo/bar.git")).isEqualTo("foo/bar");
    ValidationException noProject = assertThrows(ValidationException.class, () -> GITHUB_COM.getProjectNameFromUrl("foo@bar:baz"));
    assertThat(noProject).hasMessageThat().contains("Cannot find project name");
    ValidationException notGitHub = assertThrows(ValidationException.class, () -> GITHUB_COM.getProjectNameFromUrl("file://some/local/dir"));
    assertThat(notGitHub).hasMessageThat().contains("Not a github url");
    ValidationException noUrl = assertThrows(ValidationException.class, () -> GITHUB_COM.getProjectNameFromUrl(""));
    assertThat(noUrl).hasMessageThat().contains("Empty url");
    // While www.github.com is a valid host, we prefer the non-www version for consistency.
    assertThat(assertThrows(ValidationException.class, () -> GITHUB_COM.getProjectNameFromUrl("https://www.github.com/foo"))).hasMessageThat().contains("Expected host: github.com");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Example 75 with ValidationException

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

the class HgRepositoryTest method testPullInvalidPath.

@Test
public void testPullInvalidPath() throws Exception {
    String invalidPath = "/not/a/path";
    ValidationException e = assertThrows(ValidationException.class, () -> repository.pullAll(invalidPath));
    assertThat(e).hasMessageThat().contains("Repository not found");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) 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