Search in sources :

Example 81 with DummyRevision

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

the class InfoTest method testInfoUpToDate.

@Test
public void testInfoUpToDate() throws Exception {
    info = new InfoCmd((configPath, sourceRef) -> new ConfigLoader(skylark.createModuleSet(), skylark.createConfigFile("copy.bara.sky", configInfo), optionsBuilder.general.getStarlarkMode()) {

        @Override
        public Config load(Console console) {
            return config;
        }

        @Override
        public ConfigWithDependencies loadWithDependencies(Console console) {
            return configWithDeps;
        }
    }, getFakeContextProvider());
    MigrationReference<DummyRevision> workflow = MigrationReference.create("workflow", new DummyRevision("1111"), ImmutableList.of());
    Info<?> mockedInfo = Info.create(dummyOriginDescription, dummyDestinationDescription, ImmutableList.of(workflow));
    Mockito.<Info<? extends Revision>>when(migration.getInfo()).thenReturn(mockedInfo);
    info.run(new CommandEnv(temp, optionsBuilder.build(), ImmutableList.of("copy.bara.sky", "workflow")));
    assertThat(eventMonitor.infoFinishedEvent).isNotNull();
    assertThat(eventMonitor.infoFinishedEvent.getInfo()).isEqualTo(mockedInfo);
    console.assertThat().onceInLog(MessageType.INFO, ".*last_migrated 1111 - last_available None.*");
}
Also used : MigrationReference(com.google.copybara.Info.MigrationReference) DummyRevision(com.google.copybara.testing.DummyRevision) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) MessageType(com.google.copybara.util.console.Message.MessageType) ImmutableList(com.google.common.collect.ImmutableList) Author(com.google.copybara.authoring.Author) ExitCode(com.google.copybara.util.ExitCode) Config(com.google.copybara.config.Config) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Path(java.nio.file.Path) Before(org.junit.Before) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) ImmutableMap(com.google.common.collect.ImmutableMap) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Files(java.nio.file.Files) Migration(com.google.copybara.config.Migration) ValidationException(com.google.copybara.exception.ValidationException) ConfigWithDependencies(com.google.copybara.config.SkylarkParser.ConfigWithDependencies) Console(com.google.copybara.util.console.Console) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Instant(java.time.Instant) ZoneId(java.time.ZoneId) Mockito(org.mockito.Mockito) TestingEventMonitor(com.google.copybara.testing.TestingEventMonitor) StarlarkMode(com.google.copybara.util.console.StarlarkMode) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) SUCCESS(com.google.copybara.util.ExitCode.SUCCESS) Mockito.mock(org.mockito.Mockito.mock) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Console(com.google.copybara.util.console.Console) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 82 with DummyRevision

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

the class WorkflowTest method testDisableCheckout.

@Test
public void testDisableCheckout() throws Exception {
    transformations = ImmutableList.of();
    extraWorkflowFields = ImmutableList.of("checkout = False");
    Workflow<?, ?> workflow = workflow();
    DummyRevision head = origin.resolve("HEAD");
    workflow.run(workdir, ImmutableList.of("HEAD"));
    ProcessedChange change = Iterables.getLast(destination.processed);
    assertThat(change.getOriginRef()).isEqualTo(head);
    assertThatPath(workdir).containsNoMoreFiles();
}
Also used : ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 83 with DummyRevision

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

the class WorkflowTest method checkAfterAllMigrations.

private void checkAfterAllMigrations(String rev, WorkflowMode mode) throws Exception {
    origin.singleFileChange(0, "base commit", "foo.txt", "0");
    DummyRevision base = origin.resolve("HEAD");
    origin.singleFileChange(1, "first commit", "foo.txt", "1");
    origin.singleFileChange(2, "second commit", "foo.txt", "2");
    origin.singleFileChange(3, "third commit", "foo.txt", "3");
    String config = "" + "def after_all(ctx):\n" + "  ctx.destination.message('after_all '" + " + str([e.type + ' ' + e.destination_ref.id for e in ctx.effects]))\n" + "def after(ctx):\n" + "  ctx.destination.message('after '" + " + str([e.type + ' ' + e.destination_ref.id for e in ctx.effects]))\n" + "\n" + "core.workflow(\n" + "  name = 'default',\n" + "  origin = testing.origin(),\n" + "  destination = testing.destination(),\n" + "  transformations = [],\n" + "  mode = \"" + mode.name() + "\",\n" + "  authoring = " + authoring + ",\n" + "  after_migration = [after],\n" + "  after_workflow = [after_all]" + ")\n";
    options.setLastRevision(base.asString());
    loadConfig(config).getMigration("default").run(workdir, ImmutableList.of(rev));
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision)

Example 84 with DummyRevision

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

the class WorkflowTest method testSquashAlreadyMigratedWithForce.

@Test
public void testSquashAlreadyMigratedWithForce() throws Exception {
    origin.addSimpleChange(/*timestamp*/
    1);
    String oldRef = resolveHead();
    origin.addSimpleChange(/*timestamp*/
    2);
    origin.addSimpleChange(/*timestamp*/
    3);
    includeReleaseNotes = true;
    options.setForce(true);
    workflow().run(workdir, ImmutableList.of(HEAD));
    WriterContext writerContext = new WriterContext("piper_to_github", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
    assertThat(destination.newWriter(writerContext).getDestinationStatus(Glob.ALL_FILES, origin.getLabelName()).getBaseline()).isEqualTo("3");
    workflow().run(workdir, ImmutableList.of(oldRef));
    assertThat(destination.newWriter(writerContext).getDestinationStatus(Glob.ALL_FILES, origin.getLabelName()).getBaseline()).isEqualTo("0");
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 85 with DummyRevision

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

the class FolderDestinationTest method testRelativePaths.

@Test
public void testRelativePaths() throws Exception {
    Path dest = Files.createDirectories(Files.createTempDirectory("workdir").resolve("one"));
    workdir = Files.createTempDirectory("local_folder");
    Files.write(Files.createDirectories(dest.resolve("folder")).resolve("file1.txt"), "foo".getBytes(UTF_8));
    Files.write(Files.createDirectories(workdir.resolve("folder")).resolve("file1.txt"), "bar".getBytes(UTF_8));
    options.setWorkdirToRealTempDir();
    options.folderDestination.localFolder = dest.resolve("../one").toString();
    WriterContext writerContext = new WriterContext("not_important", "not_important", false, new DummyRevision("not_important"), Glob.ALL_FILES.roots());
    skylark.<FolderDestination>eval("dest", "dest = folder.destination()").newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("not_important")), Glob.createGlob(ImmutableList.of("folder/file1.txt"), ImmutableList.of()), options.general.console());
    assertThatPath(dest).containsFile("folder/file1.txt", "bar").containsNoMoreFiles();
}
Also used : Path(java.nio.file.Path) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) WriterContext(com.google.copybara.WriterContext) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Aggregations

DummyRevision (com.google.copybara.testing.DummyRevision)144 Test (org.junit.Test)124 WriterContext (com.google.copybara.WriterContext)58 Path (java.nio.file.Path)29 DestinationEffect (com.google.copybara.DestinationEffect)28 Author (com.google.copybara.authoring.Author)21 Changes (com.google.copybara.Changes)19 Glob (com.google.copybara.util.Glob)19 ValidationException (com.google.copybara.exception.ValidationException)18 IOException (java.io.IOException)16 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)14 TransformResult (com.google.copybara.TransformResult)13 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)13 ZonedDateTime (java.time.ZonedDateTime)13 TransformWork (com.google.copybara.TransformWork)12 RepoException (com.google.copybara.exception.RepoException)12 CheckerException (com.google.copybara.checks.CheckerException)11 DummyChecker (com.google.copybara.testing.DummyChecker)11 FileSubjects.assertThatPath (com.google.copybara.testing.FileSubjects.assertThatPath)11 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)11