Search in sources :

Example 11 with Message

use of com.google.copybara.util.console.Message in project copybara by google.

the class GerritDestinationTest method testReviewersFieldWithTopic.

@Test
public void testReviewersFieldWithTopic() throws Exception {
    pushToRefsFor = "master";
    writeFile(workdir, "file", "some content");
    fetch = "master";
    options.gerrit.gerritTopic = "testTopic";
    options.setForce(true);
    url = "https://localhost:33333/foo/bar";
    mockNoChangesFound();
    DummyRevision originRef = new DummyRevision("origin_ref");
    GerritDestination destination = destination("submit = False", "reviewers = [\"${SOME_REVIEWER}\"]");
    Glob glob = Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths);
    WriterContext writerContext = new WriterContext("GerritDestination", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
    List<DestinationEffect> result = destination.newWriter(writerContext).write(TransformResults.of(workdir, originRef).withSummary("Test message").withIdentity(originRef.asString()).withLabelFinder(e -> e.equals("SOME_REVIEWER") ? ImmutableList.of("foo@example.com", "bar@example.com") : ImmutableList.of()), glob, console);
    assertThat(result).hasSize(1);
    assertThat(result.get(0).getErrors()).isEmpty();
    assertPushRef("refs/for/master%topic=testTopic,hashtag=copybara_id_origin_ref_commiter@email," + "r=foo@example.com,r=bar@example.com");
}
Also used : GitTestUtil(com.google.copybara.testing.git.GitTestUtil) LowLevelHttpRequest(com.google.api.client.http.LowLevelHttpRequest) Validator(com.google.copybara.testing.git.GitTestUtil.Validator) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ZonedDateTime(java.time.ZonedDateTime) DestinationEffect(com.google.copybara.DestinationEffect) WriterContext(com.google.copybara.WriterContext) TransformWork(com.google.copybara.TransformWork) Author(com.google.copybara.authoring.Author) GitTestUtil.getGitEnv(com.google.copybara.testing.git.GitTestUtil.getGitEnv) ChangeIdPolicy(com.google.copybara.git.GerritDestination.ChangeIdPolicy) GitTesting(com.google.copybara.git.testing.GitTesting) Path(java.nio.file.Path) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) DEFAULT_TIMEOUT(com.google.copybara.util.CommandRunner.DEFAULT_TIMEOUT) Type(com.google.copybara.DestinationEffect.Type) ImmutableSet(com.google.common.collect.ImmutableSet) ArgumentMatchers.startsWith(org.mockito.ArgumentMatchers.startsWith) DummyEndpoint(com.google.copybara.testing.DummyEndpoint) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ZoneId(java.time.ZoneId) ALWAYS_TRUE(com.google.copybara.testing.git.GitTestUtil.ALWAYS_TRUE) CheckerException(com.google.copybara.checks.CheckerException) List(java.util.List) GitTestUtil.mockResponseAndValidateRequest(com.google.copybara.testing.git.GitTestUtil.mockResponseAndValidateRequest) ArgumentMatchers.matches(org.mockito.ArgumentMatchers.matches) LabelFinder(com.google.copybara.LabelFinder) GitRepository.newBareRepo(com.google.copybara.git.GitRepository.newBareRepo) RedundantChangeException(com.google.copybara.exception.RedundantChangeException) Pattern(java.util.regex.Pattern) GitTestUtil.mockResponse(com.google.copybara.testing.git.GitTestUtil.mockResponse) Joiner(com.google.common.base.Joiner) Writer(com.google.copybara.Destination.Writer) Iterables(com.google.common.collect.Iterables) DummyRevision(com.google.copybara.testing.DummyRevision) GitTestUtil.mockResponseWithStatus(com.google.copybara.testing.git.GitTestUtil.mockResponseWithStatus) 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) MockRequestAssertion(com.google.copybara.testing.git.GitTestUtil.MockRequestAssertion) MessageType(com.google.copybara.util.console.Message.MessageType) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Hashing(com.google.common.hash.Hashing) Changes(com.google.copybara.Changes) ChangeMessage(com.google.copybara.ChangeMessage) Strings(com.google.common.base.Strings) Answer(org.mockito.stubbing.Answer) ImmutableList(com.google.common.collect.ImmutableList) Metadata(com.google.copybara.Metadata) TransformResults(com.google.copybara.testing.TransformResults) GerritApiException(com.google.copybara.git.gerritapi.GerritApiException) MigrationInfo(com.google.copybara.MigrationInfo) PathSubject(com.google.copybara.testing.FileSubjects.PathSubject) Before(org.junit.Before) 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) DummyChecker(com.google.copybara.testing.DummyChecker) ValidationException(com.google.copybara.exception.ValidationException) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) GerritWriteHook(com.google.copybara.git.GerritDestination.GerritWriteHook) Glob(com.google.copybara.util.Glob) Message(com.google.copybara.util.console.Message) GitTestUtil.writeFile(com.google.copybara.testing.git.GitTestUtil.writeFile) GerritMessageInfo(com.google.copybara.git.GerritDestination.GerritMessageInfo) WriterContext(com.google.copybara.WriterContext) DestinationEffect(com.google.copybara.DestinationEffect) DummyRevision(com.google.copybara.testing.DummyRevision) Glob(com.google.copybara.util.Glob) Test(org.junit.Test)

Example 12 with Message

use of com.google.copybara.util.console.Message in project copybara by google.

the class CommandLineGuideTest method testGitToGitTemplatePredicateNotSatisfied.

@Test
public void testGitToGitTemplatePredicateNotSatisfied() {
    String urlPrefix = "https://github.com/google/";
    TestingConsole console = new TestingConsole();
    console.respondWithString(urlPrefix.concat("origin")).respondWithString(urlPrefix.concat("destination")).respondWithString("not a valid email");
    optionsBuilder.setConsole(console);
    CommandLineGuide.runForCommandLine(new CommandEnv(temp, skylark.createModuleSet().getOptions(), ImmutableList.of("copy.bara.sky")));
    assertThat(Joiner.on('\n').join(console.getMessages().stream().map(Message::getText).collect(Collectors.toList()))).contains("Invalid response");
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Message(com.google.copybara.util.console.Message) CommandEnv(com.google.copybara.CommandEnv) Test(org.junit.Test)

Example 13 with Message

use of com.google.copybara.util.console.Message in project copybara by google.

the class CommandLineGuideTest method testGitToGitTemplate.

@Test
public void testGitToGitTemplate() {
    TestingConsole console = new TestingConsole();
    String urlPrefix = "https://github.com/google/";
    console.respondWithString(urlPrefix.concat("origin")).respondWithString(urlPrefix.concat("destination")).respondWithString("Copybara <copy@bara.com>");
    optionsBuilder.setConsole(console);
    CommandLineGuide.runForCommandLine(new CommandEnv(temp, skylark.createModuleSet().getOptions(), ImmutableList.of("copy.bara.sky")));
    ConfigBuilder expectedConfig = new ConfigBuilder(new GitToGitTemplate());
    expectedConfig.setNamedStringParameter("origin_url", urlPrefix.concat("origin"));
    expectedConfig.setNamedStringParameter("destination_url", urlPrefix.concat("destination"));
    expectedConfig.setNamedStringParameter("email", "Copybara <copy@bara.com>");
    assertThat(Joiner.on('\n').join(console.getMessages().stream().map(Message::getText).collect(Collectors.toList()))).contains(expectedConfig.build());
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Message(com.google.copybara.util.console.Message) CommandEnv(com.google.copybara.CommandEnv) Test(org.junit.Test)

Aggregations

Message (com.google.copybara.util.console.Message)13 Test (org.junit.Test)10 ValidationException (com.google.copybara.exception.ValidationException)9 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)9 ImmutableList (com.google.common.collect.ImmutableList)7 Iterables (com.google.common.collect.Iterables)7 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)7 ChangeMessage (com.google.copybara.ChangeMessage)7 RepoException (com.google.copybara.exception.RepoException)7 LowLevelHttpRequest (com.google.api.client.http.LowLevelHttpRequest)6 Joiner (com.google.common.base.Joiner)6 Strings (com.google.common.base.Strings)6 ImmutableSet (com.google.common.collect.ImmutableSet)6 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)6 Hashing (com.google.common.hash.Hashing)6 Truth.assertThat (com.google.common.truth.Truth.assertThat)6 Changes (com.google.copybara.Changes)6 Writer (com.google.copybara.Destination.Writer)6 DestinationEffect (com.google.copybara.DestinationEffect)6 Type (com.google.copybara.DestinationEffect.Type)6