Search in sources :

Example 86 with DummyRevision

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

the class GerritDestinationTest method process.

private void process(DummyRevision originRef, GerritDestination destination) throws ValidationException, RepoException, IOException {
    WriterContext writerContext = new WriterContext("GerritDestination", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
    Writer<GitRevision> gitRevisionWriter = destination.newWriter(writerContext);
    // This is largely unused, except for the label finder.
    TransformWork work = new TransformWork(workdir, new Metadata("Desc", new Author("foo", "foo@foo.com"), ImmutableSetMultimap.of()), Changes.EMPTY, console, new MigrationInfo(DummyOrigin.LABEL_NAME, null), originRef, console -> new DummyEndpoint(), console -> gitRevisionWriter.getFeedbackEndPoint(console), () -> gitRevisionWriter.getDestinationReader(console, null, workdir));
    ImmutableList<DestinationEffect> result = gitRevisionWriter.write(TransformResults.of(workdir, originRef).withLabelFinder(work::getAllLabels).withIdentity(originRef.asString()), Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths), console);
    assertThat(result).hasSize(1);
    assertThat(result.get(0).getErrors()).isEmpty();
    assertThat(result.get(0).getType()).isEqualTo(Type.CREATED);
    assertThat(result.get(0).getDestinationRef().getType()).isEqualTo("commit");
    assertThat(result.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");
}
Also used : DummyEndpoint(com.google.copybara.testing.DummyEndpoint) WriterContext(com.google.copybara.WriterContext) MigrationInfo(com.google.copybara.MigrationInfo) DestinationEffect(com.google.copybara.DestinationEffect) TransformWork(com.google.copybara.TransformWork) DummyRevision(com.google.copybara.testing.DummyRevision) Metadata(com.google.copybara.Metadata) Author(com.google.copybara.authoring.Author)

Example 87 with DummyRevision

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

the class GerritDestinationTest method gerritChangeIdChangesBetweenCommits.

@Test
public void gerritChangeIdChangesBetweenCommits() throws Exception {
    fetch = "master";
    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("[]"));
    gitUtil.mockApi(eq("GET"), eq("https://localhost:33333/changes/?q=" + "hashtag:%22copybara_id_origin_ref2_commiter@email%22%20AND" + "%20project:foo/bar%20AND%20status:NEW"), mockResponse("[]"));
    writeFile(workdir, "file", "some content");
    options.setForce(true);
    process(new DummyRevision("origin_ref"));
    String firstChangeIdLine = lastCommitChangeIdLine("origin_ref", repo());
    writeFile(workdir, "file2", "some more content");
    git("branch", "master", getGerritRef(repo(), "refs/for/master"));
    options.setForce(false);
    process(new DummyRevision("origin_ref2"));
    assertThat(firstChangeIdLine).isNotEqualTo(lastCommitChangeIdLine("origin_ref2", repo()));
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 88 with DummyRevision

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

the class GerritDestinationTest method testEmptyReviewersField.

@Test
public void testEmptyReviewersField() 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()), glob, console);
    assertThat(result).hasSize(1);
    assertThat(result.get(0).getErrors()).isEmpty();
    assertPushRef("refs/for/master%topic=testTopic");
}
Also used : 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 89 with DummyRevision

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

the class GerritDestinationTest method runForDefaults.

private String runForDefaults() throws IOException, ValidationException, RepoException {
    fakeOneCommitInDestination();
    git("branch", "foo");
    writeFile(workdir, "file", "some content");
    String changeId = "Iaaaaaaaaaabbbbbbbbbbccccccccccdddddddddd";
    options.gerrit.gerritChangeId = changeId;
    process(new DummyRevision("origin_ref"));
    return GerritDestination.CHANGE_ID_LABEL + ": " + changeId;
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision)

Example 90 with DummyRevision

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

the class GerritDestinationTest method gerritSubmit_plusTwoRestricted.

@Test
public void gerritSubmit_plusTwoRestricted() throws Exception {
    options.gerrit.gerritChangeId = null;
    fetch = "master";
    writeFile(workdir, "file", "some content");
    url = BASE_URL + "/foo/bar";
    repoGitDir = gitUtil.mockRemoteRepo("user:SECRET@copybara-not-real.com/foo/bar").getGitDir();
    gitUtil.mockApi(eq("GET"), startsWith(BASE_URL + "/changes/"), mockResponse("[" + "{" + "  change_id : \"Iaaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\"," + "  status : \"NEW\"" + "}]"));
    AtomicBoolean submitCalled = new AtomicBoolean(false);
    AtomicBoolean reviewCalled = new AtomicBoolean(false);
    gitUtil.mockApi(eq("POST"), matches(BASE_URL + "/changes/.*/revisions/.*/review"), mockResponseWithStatus("Applying label \\\"Code-Review\\\": 2 is restricted\\n\\n", 401));
    gitUtil.mockApi(eq("POST"), matches(BASE_URL + "/changes/.*/submit"), mockResponseAndValidateRequest("{" + "  change_id : \"Iaaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\"," + "  status : \"submitted\"" + "}", new MockRequestAssertion("Always true with side-effect", s -> {
        submitCalled.set(true);
        return true;
    })));
    options.setForce(true);
    DummyRevision originRef = new DummyRevision("origin_ref");
    GerritDestination destination = destination("submit = True", "gerrit_submit = True");
    Glob glob = Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths);
    WriterContext writerContext = new WriterContext("GerritDestinationTest", "test", false, originRef, Glob.ALL_FILES.roots());
    ValidationException validationException = assertThrows(ValidationException.class, () -> destination.newWriter(writerContext).write(TransformResults.of(workdir, originRef).withSummary("Test message").withIdentity(originRef.asString()), glob, console));
    assertThat(validationException).hasMessageThat().contains("2 is restricted");
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WriterContext(com.google.copybara.WriterContext) MockRequestAssertion(com.google.copybara.testing.git.GitTestUtil.MockRequestAssertion) ValidationException(com.google.copybara.exception.ValidationException) 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