Search in sources :

Example 1 with MapConfigFile

use of com.google.copybara.config.MapConfigFile in project copybara by google.

the class PatchTransformationTest method setup.

@Before
public void setup() throws IOException {
    checkoutDir = Files.createTempDirectory("workdir");
    Files.createDirectories(checkoutDir);
    console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console);
    general = options.build().get(GeneralOptions.class);
    skylark = new SkylarkTestExecutor(options, PatchModule.class);
    ImmutableMap<String, byte[]> configFiles = ImmutableMap.of("diff.patch", (DIFF).getBytes(UTF_8), "series", ("diff.patch\n").getBytes(UTF_8));
    patchFile = new MapConfigFile(configFiles, "diff.patch");
    seriesFile = new MapConfigFile(configFiles, "series");
    options.setEnvironment(GitTestUtil.getGitEnv());
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) GeneralOptions(com.google.copybara.GeneralOptions) MapConfigFile(com.google.copybara.config.MapConfigFile) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 2 with MapConfigFile

use of com.google.copybara.config.MapConfigFile 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)

Example 3 with MapConfigFile

use of com.google.copybara.config.MapConfigFile in project copybara by google.

the class PatchTransformationTest method setup.

@Before
public void setup() throws IOException {
    checkoutDir = Files.createTempDirectory("workdir");
    Files.createDirectories(checkoutDir);
    console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console);
    patchingOptions = options.build().get(PatchingOptions.class);
    skylark = new SkylarkTestExecutor(options);
    ImmutableMap<String, byte[]> configFiles = ImmutableMap.of("diff.patch", (DIFF).getBytes(UTF_8), "series", ("diff.patch\n").getBytes(UTF_8));
    patchFile = new MapConfigFile(configFiles, "diff.patch");
    seriesFile = new MapConfigFile(configFiles, "series");
    options.setEnvironment(GitTestUtil.getGitEnv().getEnvironment());
    // In preparation to switch to the new default. PatchingOptionsTest has more coverage on this.
    options.patch.useGitApply = false;
    options.patch.skipVersionCheck = false;
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) MapConfigFile(com.google.copybara.config.MapConfigFile) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 4 with MapConfigFile

use of com.google.copybara.config.MapConfigFile in project copybara by google.

the class WorkflowTest method customIdentity_customPathIncluded.

@Test
public void customIdentity_customPathIncluded() throws Exception {
    options.workflowOptions.initHistory = true;
    byte[] cfgContent = ("" + "core.workflow(\n" + "    name = 'default',\n" + "    authoring = " + authoring + "\n," + "    origin = testing.origin(),\n" + "    destination = testing.destination(),\n" + "    change_identity = '${copybara_config_path}foo${label:some_label}',\n" + "    mode = 'ITERATIVE',\n" + ")\n\n" + "").getBytes(UTF_8);
    Config config1 = skylark.loadConfig(new MapConfigFile(ImmutableMap.of("foo/copy.bara.sky", cfgContent), "foo/copy.bara.sky"));
    Config config2 = skylark.loadConfig(new MapConfigFile(ImmutableMap.of("bar/copy.bara.sky", cfgContent), "bar/copy.bara.sky"));
    origin.addSimpleChange(1, "change\n\nsome_label=a");
    config1.getMigration("default").run(workdir, ImmutableList.of());
    ImmutableList<String> oneResult = destination.processed.stream().map(ProcessedChange::getChangeIdentity).collect(ImmutableList.toImmutableList());
    destination.processed.clear();
    config2.getMigration("default").run(workdir, ImmutableList.of());
    ImmutableList<String> twoResult = destination.processed.stream().map(ProcessedChange::getChangeIdentity).collect(ImmutableList.toImmutableList());
    assertThat(oneResult).isNotEqualTo(twoResult);
}
Also used : Config(com.google.copybara.config.Config) MapConfigFile(com.google.copybara.config.MapConfigFile) Test(org.junit.Test)

Example 5 with MapConfigFile

use of com.google.copybara.config.MapConfigFile in project copybara by google.

the class QuiltTransformationTest method setUp.

@Before
public void setUp() throws IOException {
    checkoutDir = Files.createTempDirectory("workdir");
    Files.createDirectories(checkoutDir);
    console = new TestingConsole();
    // QuiltTransformation needs to write and read from to real temp directory.
    options = new OptionsBuilder().setWorkdirToRealTempDir();
    // GeneralOptions.getDirFactory() requires $HOME to be set. We set --output-root instead.
    options.setOutputRootToTmpDir();
    patchingOptions = options.build().get(PatchingOptions.class);
    patchingOptions.quiltBin = setUpQuiltBin(patchingOptions.getGeneralOptions());
    skylark = new SkylarkTestExecutor(options);
    ImmutableMap<String, byte[]> configFiles = ImmutableMap.of("patches/diff.patch", OLDDIFF.getBytes(UTF_8), "patches/series", SERIES.getBytes(UTF_8));
    patchFile = new MapConfigFile(configFiles, "patches/diff.patch");
    seriesFile = new MapConfigFile(configFiles, "patches/series");
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) MapConfigFile(com.google.copybara.config.MapConfigFile) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Aggregations

MapConfigFile (com.google.copybara.config.MapConfigFile)5 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)4 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)3 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)3 Before (org.junit.Before)3 Test (org.junit.Test)2 GeneralOptions (com.google.copybara.GeneralOptions)1 Config (com.google.copybara.config.Config)1 RepoException (com.google.copybara.exception.RepoException)1