Search in sources :

Example 6 with SkylarkTestExecutor

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);
}
Also used : Path(java.nio.file.Path) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 7 with SkylarkTestExecutor

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);
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) DummyOrigin(com.google.copybara.testing.DummyOrigin) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 8 with SkylarkTestExecutor

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());
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Test(org.junit.Test)

Example 9 with SkylarkTestExecutor

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() + "\\?");
}
Also used : GitRepository(com.google.copybara.git.GitRepository) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) GitRevision(com.google.copybara.git.GitRevision) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Test(org.junit.Test)

Example 10 with SkylarkTestExecutor

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");
}
Also used : MapConfigFile(com.google.copybara.config.MapConfigFile) RepoException(com.google.copybara.exception.RepoException) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Test(org.junit.Test)

Aggregations

SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)70 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)58 Before (org.junit.Before)58 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)54 Path (java.nio.file.Path)17 Test (org.junit.Test)14 GitTestUtil (com.google.copybara.testing.git.GitTestUtil)9 DummyOrigin (com.google.copybara.testing.DummyOrigin)8 ValidationException (com.google.copybara.exception.ValidationException)7 FileSystem (java.nio.file.FileSystem)7 DummyChecker (com.google.copybara.testing.DummyChecker)6 RecordsProcessCallDestination (com.google.copybara.testing.RecordsProcessCallDestination)6 MapConfigFile (com.google.copybara.config.MapConfigFile)4 RepoException (com.google.copybara.exception.RepoException)4 Console (com.google.copybara.util.console.Console)4 IOException (java.io.IOException)4 LowLevelHttpRequest (com.google.api.client.http.LowLevelHttpRequest)3 ImmutableList (com.google.common.collect.ImmutableList)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 DummyRevision (com.google.copybara.testing.DummyRevision)3