use of com.google.copybara.testing.SkylarkTestExecutor 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.testing.SkylarkTestExecutor 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.testing.SkylarkTestExecutor 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.testing.SkylarkTestExecutor in project copybara by google.
the class FolderDestinationTest method setup.
@Before
public void setup() throws IOException {
workdir = Files.createTempDirectory("workdir");
options = new OptionsBuilder().setWorkdirToRealTempDir().setHomeDir(StandardSystemProperty.USER_HOME.value());
Files.createDirectory(workdir.resolve("dir"));
Files.write(workdir.resolve("test.txt"), new byte[] {});
Files.write(workdir.resolve("dir/file.txt"), new byte[] {});
excludedPathsForDeletion = ImmutableList.of();
skylark = new SkylarkTestExecutor(options);
}
use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.
the class BuildifierFormatTest method setup.
@Before
public void setup() throws IOException {
console = new TestingConsole();
options = new OptionsBuilder();
options.setConsole(console);
File buildifier = Paths.get(System.getenv("TEST_SRCDIR")).resolve(System.getenv("TEST_WORKSPACE")).resolve("javatests/com/google/copybara/format").resolve("buildifier").toFile();
options.buildifier.buildifierBin = buildifier.getAbsolutePath();
checkoutDir = Files.createTempDirectory("BuildifierFormatTest");
skylark = new SkylarkTestExecutor(options);
}
Aggregations