Search in sources :

Example 1 with DummyRevision

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

the class GitDestinationTest method processWithBaselineNotFoundMasterNotFound.

@Test
public void processWithBaselineNotFoundMasterNotFound() throws Exception {
    fetch = "test_test_test";
    push = "master";
    Files.write(workdir.resolve("test.txt"), "more content".getBytes());
    thrown.expect(RepoException.class);
    thrown.expectMessage("Cannot find baseline 'I_dont_exist' and fetch reference 'test_test_test'");
    processWithBaseline(firstCommitWriter(), new DummyRevision("origin_ref"), "I_dont_exist");
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 2 with DummyRevision

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

the class GithubPrDestinationTest method testDestinationStatus.

@Test
public void testDestinationStatus() throws ValidationException, IOException, RepoException {
    options.githubDestination.createPullRequest = false;
    gitApiMockHttpTransport = GitTestUtil.NO_GITHUB_API_CALLS;
    GithubPrDestination d = skylark.eval("r", "r = git.github_pr_destination(" + "    url = 'https://github.com/foo'" + ")");
    Writer<GitRevision> writer = d.newWriter(Glob.ALL_FILES, /*dryRun=*/
    false, "feature", /*oldWriter=*/
    null);
    GitRepository remote = localHubRepo("foo");
    addFiles(remote, "master", "first change\n\nDummyOrigin-RevId: baseline", ImmutableMap.<String, String>builder().put("foo.txt", "").build());
    DestinationStatus status = writer.getDestinationStatus("DummyOrigin-RevId");
    assertThat(status.getBaseline()).isEqualTo("baseline");
    assertThat(status.getPendingChanges()).isEmpty();
    Files.write(this.workdir.resolve("test.txt"), "some content".getBytes());
    writer.write(TransformResults.of(this.workdir, new DummyRevision("one")), console);
    // New writer since after changes it keeps state internally for ITERATIVE mode
    status = d.newWriter(Glob.ALL_FILES, /*dryRun=*/
    false, "feature", /*oldWriter=*/
    null).getDestinationStatus("DummyOrigin-RevId");
    assertThat(status.getBaseline()).isEqualTo("baseline");
    // Not supported for now as we rewrite the whole branch history.
    assertThat(status.getPendingChanges()).isEmpty();
}
Also used : DestinationStatus(com.google.copybara.Destination.DestinationStatus) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 3 with DummyRevision

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

the class GithubPrDestinationTest method testCustomTitleAndBody.

@Test
public void testCustomTitleAndBody() throws ValidationException, IOException, RepoException {
    options.githubDestination.destinationPrBranch = "feature";
    gitApiMockHttpTransport = new GitApiMockHttpTransport() {

        @Override
        protected byte[] getContent(String method, String url, MockLowLevelHttpRequest request) throws IOException {
            boolean isPulls = "https://api.github.com/repos/foo/pulls".equals(url);
            if ("GET".equals(method) && isPulls) {
                return "[]".getBytes(UTF_8);
            } else if ("POST".equals(method) && isPulls) {
                assertThat(request.getContentAsString()).isEqualTo("{\"base\":\"master\"," + "\"body\":\"custom body\"," + "\"head\":\"feature\"," + "\"title\":\"custom title\"}");
                return ("{\n" + "  \"id\": 1,\n" + "  \"number\": 12345,\n" + "  \"state\": \"open\",\n" + "  \"title\": \"custom title\",\n" + "  \"body\": \"custom body\"" + "}").getBytes();
            }
            fail(method + " " + url);
            throw new IllegalStateException();
        }
    };
    GithubPrDestination d = skylark.eval("r", "r = git.github_pr_destination(" + "    url = 'https://github.com/foo', \n" + "    title = 'custom title',\n" + "    body = 'custom body',\n" + ")");
    Writer<GitRevision> writer = d.newWriter(Glob.ALL_FILES, /*dryRun=*/
    false, null, /*oldWriter=*/
    null);
    GitRepository remote = localHubRepo("foo");
    addFiles(remote, null, "first change", ImmutableMap.<String, String>builder().put("foo.txt", "").build());
    Files.write(this.workdir.resolve("test.txt"), "some content".getBytes());
    writer.write(TransformResults.of(this.workdir, new DummyRevision("one")), console);
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) GitApiMockHttpTransport(com.google.copybara.testing.OptionsBuilder.GitApiMockHttpTransport) IOException(java.io.IOException) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) Test(org.junit.Test)

Example 4 with DummyRevision

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

the class GerritDestinationTest method specifyTopic.

@Test
public void specifyTopic() throws Exception {
    fetch = "master";
    options.setForce(true);
    Files.write(workdir.resolve("file"), "some content".getBytes());
    options.gerrit.gerritTopic = "testTopic";
    process(new DummyRevision("origin_ref"));
    boolean correctMessage = console.getMessages().stream().anyMatch(message -> message.getText().contains("refs/for/master%topic=testTopic"));
    assertThat(correctMessage).isTrue();
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 5 with DummyRevision

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

the class CopybaraTest method testInfoUpToDate.

@Test
public void testInfoUpToDate() throws Exception {
    MigrationReference<DummyRevision> workflow = MigrationReference.create("workflow", new DummyRevision("1111"), ImmutableList.of());
    Info<? extends Revision> mockedInfo = Info.create(ImmutableList.of(workflow));
    Mockito.<Info<? extends Revision>>when(migration.getInfo()).thenReturn(mockedInfo);
    Copybara copybara = new Copybara(new ConfigValidator() {
    }, migration -> {
    }, /*configLoaderProvider=*/
    null);
    copybara.info(optionsBuilder.build(), config, "workflow");
    assertThat(eventMonitor.infoFinishedEvent).isNotNull();
    assertThat(eventMonitor.infoFinishedEvent.getInfo()).isEqualTo(mockedInfo);
    console.assertThat().onceInLog(MessageType.INFO, ".*last_migrated 1111 - last_available None.*");
}
Also used : ConfigValidator(com.google.copybara.config.ConfigValidator) DummyRevision(com.google.copybara.testing.DummyRevision) 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