Search in sources :

Example 11 with DestinationEffect

use of com.google.copybara.DestinationEffect in project copybara by google.

the class GerritDestinationTest method gerritSubmit_alreadySubmittable.

@Test
public void gerritSubmit_alreadySubmittable() 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\"," + "  submittable : true" + "}]"));
    AtomicBoolean submitCalled = new AtomicBoolean(false);
    gitUtil.mockApi(eq("POST"), matches(BASE_URL + "/changes/.*/revisions/.*/review"), mockResponseWithStatus("Change should not be voted on", 500));
    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());
    List<DestinationEffect> result = destination.newWriter(writerContext).write(TransformResults.of(workdir, originRef).withSummary("Test message").withIdentity(originRef.asString()), glob, console);
    assertThat(submitCalled.get()).isTrue();
    assertThat(result).hasSize(1);
    assertThat(result.get(0).getErrors()).isEmpty();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WriterContext(com.google.copybara.WriterContext) MockRequestAssertion(com.google.copybara.testing.git.GitTestUtil.MockRequestAssertion) DestinationEffect(com.google.copybara.DestinationEffect) DummyRevision(com.google.copybara.testing.DummyRevision) Glob(com.google.copybara.util.Glob) Test(org.junit.Test)

Example 12 with DestinationEffect

use of com.google.copybara.DestinationEffect in project copybara by google.

the class GerritDestinationTest method testDisableNotifications.

@Test
public void testDisableNotifications() throws Exception {
    pushToRefsFor = "master";
    fetch = "master";
    options.setForce(true);
    Path workTree = Files.createTempDirectory("populate");
    GitRepository repo = repo().withWorkTree(workTree);
    writeFile(workTree, "file.txt", "some content");
    repo.add().all().run();
    repo.simpleCommand("commit", "-m", "Some commit");
    writeFile(workdir, "file.txt", "new content");
    DummyRevision originRef = new DummyRevision("origin_ref");
    WriterContext writerContext = new WriterContext("GerritDestination", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
    ImmutableList<DestinationEffect> result = destination("submit = False", "notify = 'NONE'").newWriter(writerContext).write(TransformResults.of(workdir, originRef).withIdentity(originRef.asString()), Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths), console);
    assertThat(result).hasSize(1);
    assertThatGerritCheckout(repo(), "refs/for/master%notify=NONE,hashtag=copybara_id_origin_ref_commiter@email").containsFile("file.txt", "new content").containsNoMoreFiles();
}
Also used : Path(java.nio.file.Path) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) WriterContext(com.google.copybara.WriterContext) DestinationEffect(com.google.copybara.DestinationEffect) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 13 with DestinationEffect

use of com.google.copybara.DestinationEffect in project copybara by google.

the class GitDestinationTest method testChecker.

@Test
public void testChecker() throws Exception {
    Writer<GitRevision> writer = firstCommitWriter();
    Files.write(workdir.resolve("existing"), "BAD".getBytes(UTF_8));
    ImmutableList<DestinationEffect> result = writer.write(TransformResults.of(workdir, new DummyRevision("ref1")), destinationFiles, console);
    assertThat(result).hasSize(1);
    assertThat(result.get(0).getType()).isEqualTo(Type.CREATED);
    options.testingOptions.checker = new DummyChecker(ImmutableSet.of("BAD"));
    checker = "testing.dummy_checker()";
    final Writer<GitRevision> writer2 = newWriter();
    Files.write(workdir.resolve("new_file"), "ok".getBytes(UTF_8));
    result = writer2.write(TransformResults.of(workdir, new DummyRevision("ref2")), destinationFiles, console);
    assertThat(result).hasSize(1);
    assertThat(result.get(0).getErrors()).isEmpty();
    assertThat(result.get(0).getType()).isEqualTo(Type.CREATED);
    Files.write(workdir.resolve("new_file"), "BAD".getBytes(UTF_8));
    CheckerException ex = assertThrows(CheckerException.class, () -> writer2.write(TransformResults.of(workdir, new DummyRevision("ref3")), destinationFiles, console));
    assertThat(ex).hasMessageThat().containsMatch("Bad word 'bad' found:.*/new_file:1");
    assertThat(ex).hasMessageThat().doesNotContainMatch("Bad word 'bad' found:.*/existing:1");
}
Also used : DestinationEffect(com.google.copybara.DestinationEffect) CheckerException(com.google.copybara.checks.CheckerException) DummyRevision(com.google.copybara.testing.DummyRevision) DummyChecker(com.google.copybara.testing.DummyChecker) Test(org.junit.Test)

Example 14 with DestinationEffect

use of com.google.copybara.DestinationEffect in project copybara by google.

the class GitDestinationTest method processWithBaselineAndConfirmation.

private void processWithBaselineAndConfirmation(Writer<GitRevision> writer, Glob destinationFiles, DummyRevision originRef, String baseline, boolean askForConfirmation) throws ValidationException, RepoException, IOException {
    TransformResult result = TransformResults.of(workdir, originRef);
    if (baseline != null) {
        result = result.withBaseline(baseline);
    }
    if (askForConfirmation) {
        result = result.withAskForConfirmation(true);
    }
    ImmutableList<DestinationEffect> destinationResult = writer.write(result, destinationFiles, console);
    assertThat(destinationResult).hasSize(1);
    assertThat(destinationResult.get(0).getErrors()).isEmpty();
    assertThat(destinationResult.get(0).getType()).isEqualTo(Type.CREATED);
    assertThat(destinationResult.get(0).getDestinationRef().getType()).isEqualTo("commit");
    assertThat(destinationResult.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");
}
Also used : TransformResult(com.google.copybara.TransformResult) DestinationEffect(com.google.copybara.DestinationEffect)

Example 15 with DestinationEffect

use of com.google.copybara.DestinationEffect in project copybara by google.

the class GitHubDestinationTest method testPrToUpdateIngoredForInitHistory.

@Test
public void testPrToUpdateIngoredForInitHistory() throws Exception {
    options.workflowOptions.initHistory = true;
    addFiles(remote, primaryBranch, "first change", ImmutableMap.<String, String>builder().put("foo.txt", "foo").buildOrThrow());
    WriterContext writerContext = new WriterContext("piper_to_github", "test", false, new DummyRevision("origin_ref1"), Glob.ALL_FILES.roots());
    writeFile(this.workdir, "test.txt", "some content");
    Writer<GitRevision> writer = destinationWithExistingPrBranch("other", "True").newWriter(writerContext);
    DummyRevision ref = new DummyRevision("origin_ref1");
    TransformResult result = TransformResults.of(workdir, ref);
    Changes changes = new Changes(ImmutableList.of(new Change<>(ref, new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "12345")), new Change<>(ref, new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "6789"))), ImmutableList.of());
    result = result.withChanges(changes);
    ImmutableList<DestinationEffect> destinationResult = writer.write(result, destinationFiles, console);
    assertThat(destinationResult).hasSize(1);
    assertThat(destinationResult.get(0).getErrors()).isEmpty();
    assertThat(destinationResult.get(0).getType()).isEqualTo(Type.CREATED);
    assertThat(destinationResult.get(0).getDestinationRef().getType()).isEqualTo("commit");
    assertThat(destinationResult.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");
    // This is a migration of two changes (use the same ref because mocks)
    verifyNoInteractions(gitUtil.httpTransport());
    GitTesting.assertThatCheckout(remote, primaryBranch).containsFile("test.txt", "some content").containsNoMoreFiles();
    assertThat(remote.simpleCommand("show-ref").getStdout()).doesNotContain("other");
}
Also used : Changes(com.google.copybara.Changes) WriterContext(com.google.copybara.WriterContext) TransformResult(com.google.copybara.TransformResult) DestinationEffect(com.google.copybara.DestinationEffect) DummyRevision(com.google.copybara.testing.DummyRevision) Author(com.google.copybara.authoring.Author) Change(com.google.copybara.Change) Test(org.junit.Test)

Aggregations

DestinationEffect (com.google.copybara.DestinationEffect)39 DummyRevision (com.google.copybara.testing.DummyRevision)26 Test (org.junit.Test)23 WriterContext (com.google.copybara.WriterContext)19 Author (com.google.copybara.authoring.Author)13 Glob (com.google.copybara.util.Glob)12 ImmutableList (com.google.common.collect.ImmutableList)11 Changes (com.google.copybara.Changes)10 ChangeMessage (com.google.copybara.ChangeMessage)8 Metadata (com.google.copybara.Metadata)7 MigrationInfo (com.google.copybara.MigrationInfo)7 TransformResult (com.google.copybara.TransformResult)7 TransformWork (com.google.copybara.TransformWork)7 CheckerException (com.google.copybara.checks.CheckerException)7 ValidationException (com.google.copybara.exception.ValidationException)7 GerritMessageInfo (com.google.copybara.git.GerritDestination.GerritMessageInfo)7 DummyChecker (com.google.copybara.testing.DummyChecker)7 FileSubjects.assertThatPath (com.google.copybara.testing.FileSubjects.assertThatPath)7 LowLevelHttpRequest (com.google.api.client.http.LowLevelHttpRequest)6 Joiner (com.google.common.base.Joiner)6