Search in sources :

Example 36 with DummyRevision

use of com.google.copybara.testing.DummyRevision 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 37 with DummyRevision

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

the class GitDestinationTest method doNotDeleteIncludedFilesInNonMatchingSubdir.

@Test
public void doNotDeleteIncludedFilesInNonMatchingSubdir() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    Files.createDirectories(workdir.resolve("foo"));
    Files.write(workdir.resolve("foo/bar"), "content".getBytes(UTF_8));
    repo().withWorkTree(workdir).add().files("foo/bar").run();
    repo().withWorkTree(workdir).simpleCommand("commit", "-m", "message");
    Files.write(workdir.resolve("foo/baz"), "content".getBytes(UTF_8));
    // Note the glob foo/** does not match the directory itself called 'foo',
    // only the contents.
    destinationFiles = Glob.createGlob(ImmutableList.of("foo/**"));
    process(newWriter(), new DummyRevision("origin_ref"));
    assertThatCheckout(repo(), primaryBranch).containsFile("foo/bar", "content").containsFile("foo/baz", "content").containsNoMoreFiles();
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 38 with DummyRevision

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

the class GitDestinationTest method processFetchRefDoesntExist.

@Test
public void processFetchRefDoesntExist() throws Exception {
    fetch = "testPullFromRef";
    push = "testPushToRef";
    Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
    ValidationException thrown = assertThrows(ValidationException.class, () -> process(newWriter(), new DummyRevision("origin_ref")));
    assertThat(thrown).hasMessageThat().contains("'refs/heads/testPullFromRef' doesn't exist");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 39 with DummyRevision

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

the class GitDestinationTest method processUserAborts.

@Test
public void processUserAborts() throws Exception {
    console = new TestingConsole().respondNo();
    fetch = primaryBranch;
    push = primaryBranch;
    Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
    ValidationException thrown = assertThrows(ValidationException.class, () -> processWithBaselineAndConfirmation(firstCommitWriter(), destinationFiles, new DummyRevision("origin_ref"), /*baseline=*/
    null, /*askForConfirmation=*/
    true));
    assertThat(thrown).hasMessageThat().contains("User aborted execution: did not confirm diff changes");
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) ValidationException(com.google.copybara.exception.ValidationException) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 40 with DummyRevision

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

the class GitDestinationTest method previousImportReference_nonCopybaraCommitsSinceLastMigrate.

@Test
public void previousImportReference_nonCopybaraCommitsSinceLastMigrate() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
    process(firstCommitWriter(), new DummyRevision("first_commit"));
    Path scratchTree = Files.createTempDirectory("GitDestinationTest-scratchTree");
    for (int i = 0; i < 20; i++) {
        Files.write(scratchTree.resolve("excluded.dat"), new byte[] { (byte) i });
        repo().withWorkTree(scratchTree).add().files("excluded.dat").run();
        repo().withWorkTree(scratchTree).simpleCommand("commit", "-m", "excluded #" + i);
    }
    assertThat(newWriter().getDestinationStatus(destinationFiles, DummyOrigin.LABEL_NAME).getBaseline()).isEqualTo("first_commit");
}
Also used : Path(java.nio.file.Path) 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