Search in sources :

Example 41 with SkylarkTestExecutor

use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.

the class ExamplesTest method testExamples.

@Test
public void testExamples() {
    SkylarkTestExecutor executor = getExecutor();
    ImmutableList.Builder<Result> resBuilder = ImmutableList.builder();
    for (Class<?> module : executor.getModules()) {
        for (Method method : module.getMethods()) {
            Examples examples = method.getAnnotation(Examples.class);
            ImmutableList<Example> samples;
            if (examples == null) {
                Example singleSample = method.getAnnotation(Example.class);
                if (singleSample != null) {
                    samples = ImmutableList.of(singleSample);
                } else {
                    continue;
                }
            } else {
                samples = ImmutableList.copyOf(examples.value());
            }
            resBuilder.addAll(checkExamples(executor, module, samples, method.getName()));
        }
    }
    ImmutableList<Result> result = resBuilder.build();
    // Normally we won't remove examples or modules. This checks that we don't go down. This
    // is the number of modules in Apr 2019. We can update this from time to time. It is not
    // critical to have an accurate number, but that we don't lose at least these.
    assertWithMessage("Less examples than expected").that(result.size()).isAtLeast(48);
    Set<? extends Class<?>> modules = result.stream().map(e -> e.cls).collect(Collectors.toSet());
    assertWithMessage("Less classes than expected: " + modules).that(modules.size()).isAtLeast(5);
    List<Result> errors = result.stream().filter(Result::isError).collect(Collectors.toList());
    assertWithMessage("Errors in examples(" + errors.size() + "):\n\n" + Joiner.on("\n-----------------------------\n").join(errors)).that(errors).isEmpty();
}
Also used : SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Examples(com.google.copybara.doc.annotations.Examples) RunWith(org.junit.runner.RunWith) ValidationException(com.google.copybara.exception.ValidationException) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) Set(java.util.Set) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Collectors(java.util.stream.Collectors) Strings(com.google.common.base.Strings) List(java.util.List) Example(com.google.copybara.doc.annotations.Example) ImmutableList(com.google.common.collect.ImmutableList) Method(java.lang.reflect.Method) Nullable(javax.annotation.Nullable) Joiner(com.google.common.base.Joiner) ImmutableList(com.google.common.collect.ImmutableList) Method(java.lang.reflect.Method) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Example(com.google.copybara.doc.annotations.Example) Examples(com.google.copybara.doc.annotations.Examples) Test(org.junit.Test)

Example 42 with SkylarkTestExecutor

use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.

the class MigrateCmdTest method setUp.

@Before
public void setUp() throws Exception {
    console = new TestingConsole();
    temp = Files.createTempDirectory("temp");
    optionsBuilder = new OptionsBuilder();
    optionsBuilder.setConsole(console).setOutputRootToTmpDir();
    optionsBuilder.setForce(true);
    Path userHomeForTest = Files.createTempDirectory("home");
    optionsBuilder.setEnvironment(GitTestUtil.getGitEnv().getEnvironment());
    optionsBuilder.setHomeDir(userHomeForTest.toString());
    eventMonitor = new TestingEventMonitor();
    optionsBuilder.general.enableEventMonitor("just testing", eventMonitor);
    outPut = optionsBuilder.general.getOutputRoot();
    optionsBuilder.general.starlarkMode = StarlarkMode.STRICT.name();
    remote = Files.createTempDirectory("remote");
    repo = GitRepository.newRepo(/*verbose*/
    true, remote, new GitEnvironment(optionsBuilder.general.getEnvironment())).init();
    primaryBranch = repo.getPrimaryBranch();
    Files.createDirectories(remote.resolve("include"));
    Files.write(remote.resolve("include/fileA.txt"), new byte[0]);
    git(remote, "add", "include/fileA.txt");
    git(remote, "commit", "-m", "not include");
    optionsBuilder.setLastRevision(repo.parseRef("HEAD"));
    git(remote, "checkout", primaryBranch);
    Files.write(remote.resolve("include/mainline-file.txt"), new byte[0]);
    git(remote, "add", "include/mainline-file.txt");
    git(remote, "commit", "-m", "message_a!");
    optionsBuilder.general.dryRunMode = true;
    url = "file://" + remote.toFile().getAbsolutePath();
    writeFile(remote, "test.txt", "some content");
    writeFile(remote, "testA.txt", "some content");
    repo.add().files("test.txt", "testA.txt").run();
    git(remote, "commit", "-m", "first file", "--date", COMMIT_TIME);
    optionsBuilder.setForce(true);
    RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
    optionsBuilder.testingOptions.destination = destination;
    skylark = new SkylarkTestExecutor(optionsBuilder);
}
Also used : Path(java.nio.file.Path) RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) GitEnvironment(com.google.copybara.git.GitEnvironment) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) TestingEventMonitor(com.google.copybara.testing.TestingEventMonitor) Before(org.junit.Before)

Example 43 with SkylarkTestExecutor

use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.

the class TransformWorkTest method setup.

@Before
public void setup() throws IOException {
    origin = new DummyOrigin().setAuthor(ORIGINAL_AUTHOR);
    destination = new RecordsProcessCallDestination();
    OptionsBuilder options = new OptionsBuilder();
    console = new TestingConsole();
    options.setConsole(console);
    options.testingOptions.origin = origin;
    options.testingOptions.destination = destination;
    // We don't care about force for this test
    options.setForce(true);
    skylark = new SkylarkTestExecutor(options);
    workdir = Files.createTempDirectory("workdir");
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) DummyOrigin(com.google.copybara.testing.DummyOrigin) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 44 with SkylarkTestExecutor

use of com.google.copybara.testing.SkylarkTestExecutor 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);
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) DummyTrigger(com.google.copybara.testing.DummyTrigger) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) TestingEventMonitor(com.google.copybara.testing.TestingEventMonitor) Before(org.junit.Before)

Example 45 with SkylarkTestExecutor

use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.

the class WorkflowTest method testEmptyDescriptionForFolderDestination.

@Test
public void testEmptyDescriptionForFolderDestination() throws Exception {
    origin.singleFileChange(/*timestamp=*/
    44, "commit 1", "bar.txt", "1");
    options.setWorkdirToRealTempDir().setHomeDir(StandardSystemProperty.USER_HOME.value());
    new SkylarkTestExecutor(options).loadConfig("core.workflow(\n" + "    name = 'foo',\n" + "    origin = testing.origin(),\n" + "    destination = folder.destination(),\n" + "    authoring = " + authoring + ",\n" + "    transformations = [metadata.replace_message(''),],\n" + ")\n").getMigration("foo").run(workdir, ImmutableList.of());
}
Also used : 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