use of com.google.copybara.testing.RecordsProcessCallDestination in project copybara by google.
the class GitOriginTest method partialFetchFailsWithFetchingTheWholeRepo.
@Test
public void partialFetchFailsWithFetchingTheWholeRepo() throws Exception {
RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
options.testingOptions.destination = destination;
options.setLastRevision(firstCommitRef);
@SuppressWarnings("unchecked") Workflow<GitRevision, Revision> wf = (Workflow<GitRevision, Revision>) skylark.loadConfig("" + "core.workflow(\n" + " name = 'default',\n" + " origin = git.origin(\n" + " url = '" + url + "',\n" + " include_branch_commit_logs = True,\n" + " partial_fetch = True,\n" + " ),\n" + " origin_files = glob(['**']),\n" + " destination = testing.destination(),\n" + " authoring = authoring.pass_thru('example <example@example.com>'),\n" + ")\n").getMigration("default");
ValidationException repoException = assertThrows(ValidationException.class, () -> wf.run(Files.createTempDirectory("foo"), ImmutableList.of("HEAD")));
assertThat(repoException).hasMessageThat().contains("Config error: partial_fetch feature is not compatible with fetching the whole repo.");
}
use of com.google.copybara.testing.RecordsProcessCallDestination in project copybara by google.
the class GitOriginTest method checkChangesMergeNoop.
@SuppressWarnings("unchecked")
private ImmutableList<? extends Change<?>> checkChangesMergeNoop(boolean importNoopChanges) throws Exception {
RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
options.testingOptions.destination = destination;
String author = "John Name <john@name.com>";
singleFileCommit(author, "base", "base.txt", "");
options.setLastRevision(repo.parseRef(defaultBranch));
// Don't remove or add an include change before this commit. This allow us to test that we
// traverse parents and not children:
singleFileCommit(author, "exclude1", "exclude1", "");
git("branch", "feature1");
git("branch", "feature2");
singleFileCommit(author, "main_branch_change", "one.txt", "");
// Make sure one_change is shown before in git log.
Thread.sleep(1100);
git("checkout", "feature1");
singleFileCommit(author, "feature1", "feature1.txt", "");
git("checkout", defaultBranch);
git("merge", defaultBranch, "feature1");
String feature1Merge = repo.parseRef(defaultBranch);
// Make sure one_change is shown before in git log.
Thread.sleep(1100);
git("checkout", "feature2");
singleFileCommit(author, "change1", "base.txt", "base");
// Revert
singleFileCommit(author, "change2", "base.txt", "");
singleFileCommit(author, "change3", "exclude.txt", "I should be excluded");
git("checkout", defaultBranch);
git("merge", defaultBranch, "feature2");
String headSha1 = repo.parseRef(defaultBranch);
Workflow<GitRevision, Revision> wf = (Workflow<GitRevision, Revision>) skylark.loadConfig("" + "core.workflow(\n" + " name = 'default',\n" + " origin = git.origin(\n" + " url = '" + url + "',\n" + " first_parent = False,\n" + " ),\n" + " origin_files = glob(['**'], exclude = ['exclude**']),\n" + " destination = testing.destination(),\n" + " migrate_noop_changes = " + (importNoopChanges ? "True" : "False") + ",\n" + " authoring = authoring.pass_thru('example <example@example.com>'),\n" + ")\n").getMigration("default");
wf.run(checkoutDir, ImmutableList.of(defaultBranch));
String expected = importNoopChanges ? headSha1 : feature1Merge;
String actual = Iterables.getLast(destination.processed).getOriginRef().asString();
assertWithMessage(String.format("Expected:\n%s\nBut found:\n%s", Iterables.getOnlyElement(repo.log(expected).withLimit(1).run()), Iterables.getOnlyElement(repo.log(actual).withLimit(1).run()))).that(actual).isEqualTo(expected);
return Iterables.getLast(destination.processed).getOriginChanges();
}
use of com.google.copybara.testing.RecordsProcessCallDestination in project copybara by google.
the class TransformDebugTest method setup.
@Before
public void setup() throws Exception {
options = new OptionsBuilder();
origin = new DummyOrigin();
destination = new RecordsProcessCallDestination();
options.testingOptions.origin = origin;
options.testingOptions.destination = destination;
skylark = new SkylarkTestExecutor(options);
workdir = Files.createTempDirectory("workdir");
options.setHomeDir(Files.createTempDirectory("home").toString());
options.setWorkdirToRealTempDir();
console = Mockito.mock(Console.class);
when(console.colorize(any(), anyString())).thenAnswer((Answer<String>) invocationOnMock -> (String) invocationOnMock.getArguments()[1]);
}
use of com.google.copybara.testing.RecordsProcessCallDestination in project copybara by google.
the class MigrateCmdTest method setUp.
@Before
public void setUp() throws Exception {
console = new TestingConsole();
temp = Files.createTempDirectory("temp");
optionsBuilder = new OptionsBuilder();
optionsBuilder.setConsole(console).setOutputRootToTmpDir();
optionsBuilder.setForce(true);
Path userHomeForTest = Files.createTempDirectory("home");
optionsBuilder.setEnvironment(GitTestUtil.getGitEnv().getEnvironment());
optionsBuilder.setHomeDir(userHomeForTest.toString());
eventMonitor = new TestingEventMonitor();
optionsBuilder.general.enableEventMonitor("just testing", eventMonitor);
outPut = optionsBuilder.general.getOutputRoot();
optionsBuilder.general.starlarkMode = StarlarkMode.STRICT.name();
remote = Files.createTempDirectory("remote");
repo = GitRepository.newRepo(/*verbose*/
true, remote, new GitEnvironment(optionsBuilder.general.getEnvironment())).init();
primaryBranch = repo.getPrimaryBranch();
Files.createDirectories(remote.resolve("include"));
Files.write(remote.resolve("include/fileA.txt"), new byte[0]);
git(remote, "add", "include/fileA.txt");
git(remote, "commit", "-m", "not include");
optionsBuilder.setLastRevision(repo.parseRef("HEAD"));
git(remote, "checkout", primaryBranch);
Files.write(remote.resolve("include/mainline-file.txt"), new byte[0]);
git(remote, "add", "include/mainline-file.txt");
git(remote, "commit", "-m", "message_a!");
optionsBuilder.general.dryRunMode = true;
url = "file://" + remote.toFile().getAbsolutePath();
writeFile(remote, "test.txt", "some content");
writeFile(remote, "testA.txt", "some content");
repo.add().files("test.txt", "testA.txt").run();
git(remote, "commit", "-m", "first file", "--date", COMMIT_TIME);
optionsBuilder.setForce(true);
RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
optionsBuilder.testingOptions.destination = destination;
skylark = new SkylarkTestExecutor(optionsBuilder);
}
use of com.google.copybara.testing.RecordsProcessCallDestination in project copybara by google.
the class TransformWorkTest method setup.
@Before
public void setup() throws IOException {
origin = new DummyOrigin().setAuthor(ORIGINAL_AUTHOR);
destination = new RecordsProcessCallDestination();
OptionsBuilder options = new OptionsBuilder();
console = new TestingConsole();
options.setConsole(console);
options.testingOptions.origin = origin;
options.testingOptions.destination = destination;
// We don't care about force for this test
options.setForce(true);
skylark = new SkylarkTestExecutor(options);
workdir = Files.createTempDirectory("workdir");
}
Aggregations