use of com.google.copybara.testing.RecordsProcessCallDestination in project copybara by google.
the class ReadConfigFromChangeWorkflowTest method setup.
@Before
public void setup() {
options = new OptionsBuilder();
origin = new DummyOrigin();
destination = new RecordsProcessCallDestination();
options.testingOptions.origin = origin;
options.testingOptions.destination = destination;
options.general.starlarkMode = StarlarkMode.STRICT.name();
skylark = new SkylarkTestExecutor(options);
}
use of com.google.copybara.testing.RecordsProcessCallDestination in project copybara by google.
the class WorkflowTest method iterativeWorkflowConfirmationHandlingTest.
@Test
public void iterativeWorkflowConfirmationHandlingTest() throws Exception {
for (int timestamp = 0; timestamp < 10; timestamp++) {
origin.addSimpleChange(timestamp);
}
console().respondYes().respondNo();
RecordsProcessCallDestination programmableDestination = new RecordsProcessCallDestination(ImmutableList.of(ImmutableList.of(), ImmutableList.of("some error"), ImmutableList.of("Another error")));
options.testingOptions.destination = programmableDestination;
Workflow<?, ?> workflow = iterativeWorkflow(/*previousRef=*/
"2");
ChangeRejectedException expected = assertThrows(ChangeRejectedException.class, () -> workflow.run(workdir, ImmutableList.of("9")));
assertThat(expected.getMessage()).contains("Iterative workflow aborted by user after: Change 3 of 7 (5)");
assertThat(programmableDestination.processed).hasSize(3);
}
use of com.google.copybara.testing.RecordsProcessCallDestination in project copybara by google.
the class WorkflowTest method testOnFinishHook_temporaryError.
// Validates that the hook is executed when the workflow throws an exception != VE, and that
// the correct effect is populated
@Test
public void testOnFinishHook_temporaryError() throws Exception {
options.testingOptions.destination = new RecordsProcessCallDestination() {
@Override
public Writer<Revision> newWriter(WriterContext writerContext) {
return new RecordsProcessCallDestination.WriterImpl(false) {
@Override
public ImmutableList<DestinationEffect> write(TransformResult transformResult, Glob destinationFiles, Console console) throws RepoException {
throw new RepoException("Repo exception!");
}
};
}
};
verifyHookForException(RepoException.class, Type.TEMPORARY_ERROR, "Repo exception!");
}
use of com.google.copybara.testing.RecordsProcessCallDestination in project copybara by google.
the class GitOriginTest method partialFetch_canFetchRootFile.
@Test
public void partialFetch_canFetchRootFile() throws Exception {
RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
options.testingOptions.destination = destination;
options.setLastRevision(firstCommitRef);
Files.write(remote.resolve("file.txt"), new byte[0]);
git("add", "file.txt");
git("commit", "-m", "message");
@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(['directory/**', 'file.txt']),\n" + " destination = testing.destination(),\n" + " authoring = authoring.pass_thru('example <example@example.com>'),\n" + ")\n").getMigration("default");
wf.run(Files.createTempDirectory("foo"), ImmutableList.of("HEAD"));
List<ProcessedChange> changes = destination.processed;
assertThat(changes).hasSize(1);
}
use of com.google.copybara.testing.RecordsProcessCallDestination in project copybara by google.
the class GitOriginTest method partialFetchAtGitOrigin.
@Test
public void partialFetchAtGitOrigin() throws Exception {
Files.createDirectories(remote.resolve("include"));
Files.write(remote.resolve("include/fileA.txt"), new byte[0]);
git("add", "include/fileA.txt");
git("commit", "-m", "not include");
git("checkout", defaultBranch);
Files.createDirectories(remote.resolve("include"));
Files.write(remote.resolve("include/mainline-file.txt"), new byte[0]);
git("add", "include/mainline-file.txt");
git("commit", "-m", "message_a!");
options.setForce(true);
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(['include/mainline-file.txt']),\n" + " destination = testing.destination(),\n" + " mode = 'ITERATIVE',\n" + " authoring = authoring.pass_thru('example <example@example.com>'),\n" + ")\n").getMigration("default");
wf.run(Files.createTempDirectory("foo"), ImmutableList.of("HEAD"));
List<ProcessedChange> changes = destination.processed;
assertThat(changes).hasSize(1);
assertThat(changes.get(0).getChangesSummary()).contains("message_a!");
}
Aggregations