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");
}
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();
}
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");
}
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");
}
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");
}
Aggregations