use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.
the class MainTest method setUp.
@Before
public void setUp() throws Exception {
called = false;
Path userHomeDir = Files.createTempDirectory("MainTest");
System.setProperty("user.home", userHomeDir.toString());
options = new OptionsBuilder();
skylark = new SkylarkTestExecutor(options);
}
use of com.google.copybara.testing.SkylarkTestExecutor 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.SkylarkTestExecutor in project copybara by google.
the class WorkflowTest method testShowDiffInOriginFail.
@Test
public void testShowDiffInOriginFail() throws Exception {
origin.addSimpleChange(/*timestamp*/
1);
origin.addSimpleChange(/*timestamp*/
2);
origin.addSimpleChange(/*timestamp*/
3);
options.workflowOptions.lastRevision = "1";
options.workflowOptions.diffInOrigin = true;
Workflow<?, ?> workflow = (Workflow<?, ?>) new SkylarkTestExecutor(options).loadConfig("core.workflow(\n" + " name = 'foo',\n" + " origin = testing.origin(),\n" + " destination = testing.destination(),\n" + " mode = 'ITERATIVE',\n" + " authoring = " + authoring + ",\n" + " transformations = [metadata.replace_message(''),],\n" + ")\n").getMigration("foo");
ValidationException e = assertThrows(ValidationException.class, () -> workflow.run(workdir, ImmutableList.of("HEAD")));
assertThat(e).hasMessageThat().contains("diff_in_origin is not supported by origin " + origin.getType());
}
use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.
the class WorkflowTest method testTestWorkflowWithDiffInOrigin.
@Test
public void testTestWorkflowWithDiffInOrigin() 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().respondYes();
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" + " ref = '" + primaryBranch + "'\n" + " ),\n" + " 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, "Change 1 of 1 \\(.*\\)\\: Continue to migrate with '" + workflow.getMode() + "'" + " to " + workflow.getDestination().getType() + "\\?");
}
use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.
the class WorkflowTest method testDynamicTransformThrowingRepoException.
@Test
public void testDynamicTransformThrowingRepoException() throws Exception {
SkylarkTestExecutor exec = skylark.withStaticModules(ImmutableSet.of(ThrowingCallable.class));
origin.singleFileChange(0, "one commit", "foo.txt", "1");
Workflow<?, ?> wf = ((Workflow<?, ?>) exec.loadConfig(new MapConfigFile(ImmutableMap.of("copy.bara.sky", ("" + "def dynamic_foo(ctx):\n" + " dynamic_test.throw_repo()\n" + "" + "core.workflow(\n" + " name = 'default',\n" + " authoring = " + authoring + "\n," + " origin = testing.origin(),\n" + " destination = testing.destination(),\n" + " transformations = [dynamic_foo],\n" + ")\n" + "").getBytes(UTF_8)), "copy.bara.sky")).getMigration("default"));
RepoException expected = assertThrows(RepoException.class, () -> wf.run(workdir, ImmutableList.of("HEAD")));
assertThat(expected).hasMessageThat().contains("Oh noes");
}
Aggregations