Search in sources :

Example 6 with RecordsProcessCallDestination

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

the class GitOriginTest method partialFetchFailsWithFetchingTheWholeRepo.

@Test
public void partialFetchFailsWithFetchingTheWholeRepo() throws Exception {
    RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
    options.testingOptions.destination = destination;
    options.setLastRevision(firstCommitRef);
    @SuppressWarnings("unchecked") Workflow<GitRevision, Revision> wf = (Workflow<GitRevision, Revision>) skylark.loadConfig("" + "core.workflow(\n" + "    name = 'default',\n" + "    origin = git.origin(\n" + "         url = '" + url + "',\n" + "         include_branch_commit_logs = True,\n" + "         partial_fetch = True,\n" + "    ),\n" + "    origin_files = glob(['**']),\n" + "    destination = testing.destination(),\n" + "    authoring = authoring.pass_thru('example <example@example.com>'),\n" + ")\n").getMigration("default");
    ValidationException repoException = assertThrows(ValidationException.class, () -> wf.run(Files.createTempDirectory("foo"), ImmutableList.of("HEAD")));
    assertThat(repoException).hasMessageThat().contains("Config error: partial_fetch feature is not compatible with fetching the whole repo.");
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) ValidationException(com.google.copybara.exception.ValidationException) Revision(com.google.copybara.Revision) Workflow(com.google.copybara.Workflow) Test(org.junit.Test)

Example 7 with RecordsProcessCallDestination

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

the class GitOriginTest method checkChangesMergeNoop.

@SuppressWarnings("unchecked")
private ImmutableList<? extends Change<?>> checkChangesMergeNoop(boolean importNoopChanges) throws Exception {
    RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
    options.testingOptions.destination = destination;
    String author = "John Name <john@name.com>";
    singleFileCommit(author, "base", "base.txt", "");
    options.setLastRevision(repo.parseRef(defaultBranch));
    // Don't remove or add an include change before this commit. This allow us to test that we
    // traverse parents and not children:
    singleFileCommit(author, "exclude1", "exclude1", "");
    git("branch", "feature1");
    git("branch", "feature2");
    singleFileCommit(author, "main_branch_change", "one.txt", "");
    // Make sure one_change is shown before in git log.
    Thread.sleep(1100);
    git("checkout", "feature1");
    singleFileCommit(author, "feature1", "feature1.txt", "");
    git("checkout", defaultBranch);
    git("merge", defaultBranch, "feature1");
    String feature1Merge = repo.parseRef(defaultBranch);
    // Make sure one_change is shown before in git log.
    Thread.sleep(1100);
    git("checkout", "feature2");
    singleFileCommit(author, "change1", "base.txt", "base");
    // Revert
    singleFileCommit(author, "change2", "base.txt", "");
    singleFileCommit(author, "change3", "exclude.txt", "I should be excluded");
    git("checkout", defaultBranch);
    git("merge", defaultBranch, "feature2");
    String headSha1 = repo.parseRef(defaultBranch);
    Workflow<GitRevision, Revision> wf = (Workflow<GitRevision, Revision>) skylark.loadConfig("" + "core.workflow(\n" + "    name = 'default',\n" + "    origin = git.origin(\n" + "         url = '" + url + "',\n" + "         first_parent = False,\n" + "    ),\n" + "    origin_files = glob(['**'], exclude = ['exclude**']),\n" + "    destination = testing.destination(),\n" + "    migrate_noop_changes = " + (importNoopChanges ? "True" : "False") + ",\n" + "    authoring = authoring.pass_thru('example <example@example.com>'),\n" + ")\n").getMigration("default");
    wf.run(checkoutDir, ImmutableList.of(defaultBranch));
    String expected = importNoopChanges ? headSha1 : feature1Merge;
    String actual = Iterables.getLast(destination.processed).getOriginRef().asString();
    assertWithMessage(String.format("Expected:\n%s\nBut found:\n%s", Iterables.getOnlyElement(repo.log(expected).withLimit(1).run()), Iterables.getOnlyElement(repo.log(actual).withLimit(1).run()))).that(actual).isEqualTo(expected);
    return Iterables.getLast(destination.processed).getOriginChanges();
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) Revision(com.google.copybara.Revision) Workflow(com.google.copybara.Workflow)

Example 8 with RecordsProcessCallDestination

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

the class TransformDebugTest method setup.

@Before
public void setup() throws Exception {
    options = new OptionsBuilder();
    origin = new DummyOrigin();
    destination = new RecordsProcessCallDestination();
    options.testingOptions.origin = origin;
    options.testingOptions.destination = destination;
    skylark = new SkylarkTestExecutor(options);
    workdir = Files.createTempDirectory("workdir");
    options.setHomeDir(Files.createTempDirectory("home").toString());
    options.setWorkdirToRealTempDir();
    console = Mockito.mock(Console.class);
    when(console.colorize(any(), anyString())).thenAnswer((Answer<String>) invocationOnMock -> (String) invocationOnMock.getArguments()[1]);
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assert.assertThrows(org.junit.Assert.assertThrows) DummyOrigin(com.google.copybara.testing.DummyOrigin) RunWith(org.junit.runner.RunWith) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) Answer(org.mockito.stubbing.Answer) Workflow(com.google.copybara.Workflow) Path(java.nio.file.Path) Before(org.junit.Before) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ValidationException(com.google.copybara.exception.ValidationException) Mockito.times(org.mockito.Mockito.times) 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) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) ArgumentMatchers.matches(org.mockito.ArgumentMatchers.matches) TransformWorks(com.google.copybara.testing.TransformWorks) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DummyOrigin(com.google.copybara.testing.DummyOrigin) Console(com.google.copybara.util.console.Console) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 9 with RecordsProcessCallDestination

use of com.google.copybara.testing.RecordsProcessCallDestination 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 10 with RecordsProcessCallDestination

use of com.google.copybara.testing.RecordsProcessCallDestination 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)

Aggregations

RecordsProcessCallDestination (com.google.copybara.testing.RecordsProcessCallDestination)18 Test (org.junit.Test)11 Workflow (com.google.copybara.Workflow)7 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)7 Revision (com.google.copybara.Revision)6 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)6 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)6 Before (org.junit.Before)6 DummyOrigin (com.google.copybara.testing.DummyOrigin)5 ValidationException (com.google.copybara.exception.ValidationException)4 ProcessedChange (com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange)4 Console (com.google.copybara.util.console.Console)4 Path (java.nio.file.Path)4 ImmutableList (com.google.common.collect.ImmutableList)3 Glob (com.google.copybara.util.Glob)3 ChangeRejectedException (com.google.copybara.exception.ChangeRejectedException)2 RepoException (com.google.copybara.exception.RepoException)2 TestingEventMonitor (com.google.copybara.testing.TestingEventMonitor)2 IOException (java.io.IOException)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)1