Search in sources :

Example 66 with ValidationException

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

the class GitMirrorTest method testDefaultMirrorInStarlark_invalid_destination.

@Test
public void testDefaultMirrorInStarlark_invalid_destination() throws Exception {
    String cfg = "" + NATIVE_MIRROR_IN_STARLARK_FUNC + "git.mirror(" + "    name = 'default'," + "    origin = 'file://" + originRepo.getGitDir().toAbsolutePath() + "'," + "    destination = 'file://" + destRepo.getGitDir().toAbsolutePath() + "'," + "    refspecs = [" + String.format("       'refs/heads/%s:refs/heads/origin_primary'", primaryBranch) + "    ]," + "    actions = [native_mirror(refspec = {" + String.format("       'refs/heads/%s':'refs/heads/INVALID'", primaryBranch) + "})]," + ")";
    Migration mirror = loadMigration(cfg, "default");
    ValidationException ve = assertThrows(ValidationException.class, () -> mirror.run(workdir, ImmutableList.of()));
    assertThat(ve).hasMessageThat().contains("Action tried to push to destination one or more refspec not covered by git.mirror");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Migration(com.google.copybara.config.Migration) Test(org.junit.Test)

Example 67 with ValidationException

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

the class GitMirrorTest method testActionFailure.

@Test
public void testActionFailure() throws Exception {
    ValidationException ve = checkActionFailure();
    assertThat(ve).hasMessageThat().contains("Something bad happened");
    assertThat(ve).hasMessageThat().doesNotContain("Another thing bad happened");
    console.assertThat().onceInLog(MessageType.INFO, "Hello, this is action1");
    console.assertThat().timesInLog(0, MessageType.INFO, "Hello, this is action2");
    console.assertThat().timesInLog(0, MessageType.INFO, "Hello, this is action3");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Example 68 with ValidationException

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

the class GitHubEndpointTest method testGetPullRequestComment_invalidId.

@Test
public void testGetPullRequestComment_invalidId() {
    ValidationException expected = assertThrows(ValidationException.class, () -> runFeedback(ImmutableList.of("ctx.destination.get_pull_request_comment(comment_id = 'foo')")));
    assertThat(expected).hasMessageThat().contains("Invalid comment id foo");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Example 69 with ValidationException

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

the class GitHubEndpointTest method testGetPullRequestComments_notFound.

@Test
public void testGetPullRequestComments_notFound() {
    gitUtil.mockApi(eq("GET"), eq("https://api.github.com/repos/google/example/pulls/12345/comments?per_page=100"), mockGitHubNotFound());
    ValidationException expected = assertThrows(ValidationException.class, () -> runFeedback(ImmutableList.of("ctx.destination.get_pull_request_comments(number = 12345)")));
    assertThat(expected).hasMessageThat().contains("Pull Request Comments not found");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Example 70 with ValidationException

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

the class GitHubEndpointTest method testCreateStatusLimitReached.

@Test
public void testCreateStatusLimitReached() throws Exception {
    gitUtil.mockApi(eq("POST"), contains("/statuses/c59774"), mockResponseWithStatus("{\n" + "\"message\" : \"This SHA and context has reached the maximum number of statuses\",\n" + "\"documentation_url\" : \"https://developer.github.com/v3\"\n" + "}", 422, ALWAYS_TRUE));
    ValidationException expected = assertThrows(ValidationException.class, () -> runFeedback(ImmutableList.<String>builder().add("ctx.destination.create_status(" + "sha = 'c597746de9c1704e648ddc3ffa0d2096b146d600'," + " state = 'success', context = 'test', description = 'Observed foo')").build()));
    assertThat(expected).hasMessageThat().contains("This SHA and context has reached the maximum number of statuses");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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