use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class FeedbackTest method setup.
@Before
public void setup() throws Exception {
workdir = Jimfs.newFileSystem().getPath("/");
console = new TestingConsole(/*verbose=*/
false);
eventMonitor = new TestingEventMonitor();
options = new OptionsBuilder();
options.setConsole(console);
options.general.enableEventMonitor("justTesting", eventMonitor);
dummyTrigger = new DummyTrigger();
options.testingOptions.feedbackTrigger = dummyTrigger;
skylark = new SkylarkTestExecutor(options);
}
use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class WorkflowTest method setup.
@Before
public void setup() throws Exception {
options = new OptionsBuilder();
options.setOutputRootToTmpDir();
authoring = "authoring.overwrite('" + DEFAULT_AUTHOR + "')";
includeReleaseNotes = false;
workdir = Files.createTempDirectory("workdir");
Files.createDirectories(workdir);
origin = new DummyOrigin().setAuthor(ORIGINAL_AUTHOR);
originFiles = "glob(['**'], exclude = ['copy.bara.sky', 'excluded/**'])";
destinationFiles = "glob(['**'])";
destination = new RecordsProcessCallDestination();
transformations = ImmutableList.of("" + " core.replace(\n" + " before = '${linestart}${number}',\n" + " after = '${linestart}" + PREFIX + "${number}',\n" + " regex_groups = {\n" + " 'number' : '[0-9]+',\n" + " 'linestart' : '^',\n" + " },\n" + " multiline = True," + " )");
TestingConsole console = new TestingConsole();
options.setConsole(console);
options.testingOptions.origin = origin;
options.testingOptions.destination = destination;
// Force by default unless we are testing the flag.
options.setForce(true);
skylark = new SkylarkTestExecutor(options);
eventMonitor = new TestingEventMonitor();
options.general.enableEventMonitor("test", eventMonitor);
transformWork = TransformWorks.of(workdir, "example", console);
setRevId = true;
smartPrune = false;
migrateNoopChangesField = false;
extraWorkflowFields = ImmutableList.of();
}
use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class WorkflowTest method testTestWorkflowWithDiffInOriginAndRespondNo.
@Test
public void testTestWorkflowWithDiffInOriginAndRespondNo() throws Exception {
GitRepository remote = GitRepository.newBareRepo(Files.createTempDirectory("gitdir"), getGitEnv(), /*verbose=*/
true, DEFAULT_TIMEOUT, /*noVerify=*/
false).withWorkTree(workdir);
remote.init();
String primaryBranch = remote.getPrimaryBranch();
Files.write(workdir.resolve("foo.txt"), new byte[] {});
remote.add().files("foo.txt").run();
remote.simpleCommand("commit", "foo.txt", "-m", "message_a");
GitRevision lastRev = remote.resolveReference(primaryBranch);
Files.write(workdir.resolve("bar.txt"), "change content".getBytes(UTF_8));
remote.add().files("bar.txt").run();
remote.simpleCommand("commit", "bar.txt", "-m", "message_s");
TestingConsole testingConsole = new TestingConsole().respondNo();
options.workflowOptions.lastRevision = lastRev.getSha1();
options.setWorkdirToRealTempDir().setConsole(testingConsole).setHomeDir(StandardSystemProperty.USER_HOME.value());
Workflow<?, ?> workflow = (Workflow<?, ?>) new SkylarkTestExecutor(options).loadConfig("core.workflow(\n" + " name = 'foo',\n" + " origin = git.origin(url='" + remote.getGitDir() + "'),\n" + " destination = folder.destination(),\n" + " mode = 'ITERATIVE',\n" + " authoring = " + authoring + ",\n" + " transformations = [metadata.replace_message(''),],\n" + ")\n").getMigration("foo");
workflow.getWorkflowOptions().diffInOrigin = true;
ChangeRejectedException e = assertThrows(ChangeRejectedException.class, () -> workflow.run(workdir, ImmutableList.of(primaryBranch)));
assertThat(e.getMessage()).contains("User aborted execution: did not confirm diff in origin changes.");
}
use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class WorkflowTest method testWorkflowWithEmptyDiffInOrigin.
@Test
public void testWorkflowWithEmptyDiffInOrigin() throws Exception {
GitRepository remote = GitRepository.newBareRepo(Files.createTempDirectory("gitdir"), getGitEnv(), /*verbose=*/
true, DEFAULT_TIMEOUT, /*noVerify=*/
false).withWorkTree(workdir);
remote.init();
String primaryBranch = remote.getPrimaryBranch();
Files.write(workdir.resolve("foo.txt"), new byte[] {});
remote.add().files("foo.txt").run();
remote.simpleCommand("commit", "foo.txt", "-m", "message_a");
GitRevision lastRev = remote.resolveReference(primaryBranch);
Files.write(workdir.resolve("foo.txt"), "change content".getBytes(UTF_8));
remote.add().files("foo.txt").run();
remote.simpleCommand("commit", "foo.txt", "-m", "message_a");
Files.write(workdir.resolve("foo.txt"), new byte[] {});
remote.add().files("foo.txt").run();
remote.simpleCommand("commit", "foo.txt", "-m", "message_a");
TestingConsole testingConsole = new TestingConsole().respondYes();
options.workflowOptions.lastRevision = lastRev.getSha1();
options.general.force = false;
options.setWorkdirToRealTempDir().setConsole(testingConsole).setHomeDir(StandardSystemProperty.USER_HOME.value());
Workflow<?, ?> workflow = (Workflow<?, ?>) new SkylarkTestExecutor(options).loadConfig("core.workflow(\n" + " name = 'foo',\n" + String.format(" origin = git.origin(url='%s', ref='%s'),\n", remote.getGitDir(), primaryBranch) + " destination = folder.destination(),\n" + " mode = 'ITERATIVE',\n" + " authoring = " + authoring + ",\n" + " transformations = [metadata.replace_message(''),],\n" + ")\n").getMigration("foo");
workflow.getWorkflowOptions().diffInOrigin = true;
workflow.run(workdir, ImmutableList.of(primaryBranch));
testingConsole.assertThat().onceInLog(MessageType.WARNING, ".*No difference at diff_in_origin.*");
}
use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class ApiCheckerTest method testCheckError.
@Test
public void testCheckError() {
ApiChecker checker = new ApiChecker(new FakeChecker() {
@Override
public void doCheck(ImmutableMap<String, String> fields, Console console) throws CheckerException {
throw new CheckerException("Check failed!");
}
}, new TestingConsole());
ValidationException e = assertThrows(ValidationException.class, () -> checker.check("foo", new Object()));
assertThat(e).hasMessageThat().isEqualTo("Check failed!");
ValidationException failedCheck = assertThrows(ValidationException.class, () -> checker.check("foo", new Object(), "bar", new Object()));
assertThat(failedCheck).hasMessageThat().isEqualTo("Check failed!");
ValidationException failedCheckArgs = assertThrows(ValidationException.class, () -> checker.check("foo", new Object(), "bar", new Object(), "baz", new Object()));
assertThat(failedCheckArgs).hasMessageThat().isEqualTo("Check failed!");
}
Aggregations