Search in sources :

Example 96 with DummyRevision

use of com.google.copybara.testing.DummyRevision in project copybara by google.

the class GerritDestinationTest method specifyChangeId.

@Test
public void specifyChangeId() throws Exception {
    fetch = "master";
    writeFile(workdir, "file", "some content");
    String changeId = "Iaaaaaaaaaabbbbbbbbbbccccccccccdddddddddd";
    options.setForce(true);
    options.gerrit.gerritChangeId = changeId;
    process(new DummyRevision("origin_ref"));
    assertThat(lastCommitChangeIdLine("origin_ref", repo())).isEqualTo(GerritDestination.CHANGE_ID_LABEL + ": " + changeId);
    git("branch", "master", getGerritRef(repo(), "refs/for/master"));
    writeFile(workdir, "file", "some different content");
    changeId = "Ibbbbbbbbbbccccccccccddddddddddeeeeeeeeee";
    options.setForce(false);
    options.gerrit.gerritChangeId = changeId;
    process(new DummyRevision("origin_ref"));
    assertThat(lastCommitChangeIdLine("origin_ref", repo())).isEqualTo(GerritDestination.CHANGE_ID_LABEL + ": " + changeId);
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 97 with DummyRevision

use of com.google.copybara.testing.DummyRevision in project copybara by google.

the class GerritDestinationTest method testCc.

@Test
public void testCc() 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", "cc = [\"${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") : 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," + "cc=foo@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 98 with DummyRevision

use of com.google.copybara.testing.DummyRevision in project copybara by google.

the class GerritDestinationTest method testHashTagFound.

@Test
public void testHashTagFound() throws Exception {
    fetch = "master";
    writeFile(workdir, "file", "some content");
    options.setForce(true);
    String secondChangeId = "I" + Hashing.sha1().newHasher().putString("origin_ref", StandardCharsets.UTF_8).putString(options.gitDestination.committerEmail, StandardCharsets.UTF_8).putInt(1).hash();
    gitUtil.mockApi(eq("GET"), eq("https://localhost:33333/changes/?q=" + "hashtag:%22copybara_id_origin_ref_commiter@email%22%20AND" + "%20project:foo/bar%20AND%20status:NEW"), mockResponse(String.format("[{  change_id : \"%s\",  status : \"NEW\"}]", secondChangeId)));
    process(new DummyRevision("origin_ref"));
    assertThat(lastCommitChangeIdLine("origin_ref", repo())).isEqualTo(GerritDestination.CHANGE_ID_LABEL + ": " + secondChangeId);
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 99 with DummyRevision

use of com.google.copybara.testing.DummyRevision in project copybara by google.

the class GerritDestinationTest method changeExists.

@Test
public void changeExists() throws Exception {
    fetch = "master";
    writeFile(workdir, "file", "some content");
    options.setForce(true);
    process(new DummyRevision("origin_ref"));
    // ChangeId is randomly generated.
    assertThat(lastCommitChangeIdLine("origin_ref", repo())).isNotEmpty();
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 100 with DummyRevision

use of com.google.copybara.testing.DummyRevision in project copybara by google.

the class GerritDestinationTest method testLabels.

@Test
public void testLabels() 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", "labels = [\"${SOME_LABELS}\"]");
    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_LABELS") ? ImmutableList.of("Foo+1", "Bar-1") : 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," + "label=Foo\\+1,label=Bar-1");
}
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)

Aggregations

DummyRevision (com.google.copybara.testing.DummyRevision)144 Test (org.junit.Test)124 WriterContext (com.google.copybara.WriterContext)58 Path (java.nio.file.Path)29 DestinationEffect (com.google.copybara.DestinationEffect)28 Author (com.google.copybara.authoring.Author)21 Changes (com.google.copybara.Changes)19 Glob (com.google.copybara.util.Glob)19 ValidationException (com.google.copybara.exception.ValidationException)18 IOException (java.io.IOException)16 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)14 TransformResult (com.google.copybara.TransformResult)13 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)13 ZonedDateTime (java.time.ZonedDateTime)13 TransformWork (com.google.copybara.TransformWork)12 RepoException (com.google.copybara.exception.RepoException)12 CheckerException (com.google.copybara.checks.CheckerException)11 DummyChecker (com.google.copybara.testing.DummyChecker)11 FileSubjects.assertThatPath (com.google.copybara.testing.FileSubjects.assertThatPath)11 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)11