Search in sources :

Example 6 with DummyOrigin

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

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

the class WorkflowTest method setup.

@Before
public void setup() throws Exception {
    options = new OptionsBuilder();
    options.setOutputRootToTmpDir();
    authoring = "authoring.overwrite('" + DEFAULT_AUTHOR + "')";
    includeReleaseNotes = false;
    workdir = Files.createTempDirectory("workdir");
    Files.createDirectories(workdir);
    origin = new DummyOrigin().setAuthor(ORIGINAL_AUTHOR);
    originFiles = "glob(['**'], exclude = ['copy.bara.sky', 'excluded/**'])";
    destinationFiles = "glob(['**'])";
    destination = new RecordsProcessCallDestination();
    transformations = ImmutableList.of("" + "        core.replace(\n" + "             before = '${linestart}${number}',\n" + "             after = '${linestart}" + PREFIX + "${number}',\n" + "             regex_groups = {\n" + "                 'number'    : '[0-9]+',\n" + "                 'linestart' : '^',\n" + "             },\n" + "             multiline = True," + "        )");
    TestingConsole console = new TestingConsole();
    options.setConsole(console);
    options.testingOptions.origin = origin;
    options.testingOptions.destination = destination;
    // Force by default unless we are testing the flag.
    options.setForce(true);
    skylark = new SkylarkTestExecutor(options);
    eventMonitor = new TestingEventMonitor();
    options.general.enableEventMonitor("test", eventMonitor);
    transformWork = TransformWorks.of(workdir, "example", console);
    setRevId = true;
    smartPrune = false;
    migrateNoopChangesField = false;
    extraWorkflowFields = ImmutableList.of();
}
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) TestingEventMonitor(com.google.copybara.testing.TestingEventMonitor) Before(org.junit.Before)

Example 8 with DummyOrigin

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

the class GitDestinationIntegrateTest method testGerritSemiFakeMerge.

@Test
public void testGerritSemiFakeMerge() throws ValidationException, IOException, RepoException {
    Path workTree = Files.createTempDirectory("test");
    GitRepository repo = gitUtil.mockRemoteRepo("example.com/gerrit").withWorkTree(workTree);
    String label = new GerritIntegrateLabel(repo, options.general, "https://example.com/gerrit", 1020, 1, CHANGE_ID).toString();
    assertThat(label).isEqualTo("gerrit https://example.com/gerrit 1020 Patch Set 1 " + CHANGE_ID);
    GitRevision firstChange = singleChange(workTree, repo, "ignore_me", "Feature1 change");
    GitRevision secondChange = singleChange(workTree, repo, "ignore_me2", "Feature2 change");
    GitTestUtil.createFakeGerritNodeDbMeta(repo, 1020, CHANGE_ID);
    repo.simpleCommand("update-ref", "refs/changes/20/1020/1", firstChange.getSha1());
    repo.simpleCommand("update-ref", "refs/changes/20/1020/2", secondChange.getSha1());
    GitDestination destination = destinationWithDefaultIntegrates();
    GitLogEntry previous = createBaseDestinationChange(destination);
    migrateOriginChange(destination, "Test change\n" + "\n" + GitModule.DEFAULT_INTEGRATE_LABEL + "=" + label + "\n", "some content");
    // Make sure commit adds new text
    String showResult = git("--git-dir", repoGitDir.toString(), "show", primaryBranch);
    assertThat(showResult).contains("some content");
    GitTesting.assertThatCheckout(repo(), primaryBranch).containsFile("test.txt", "some content").containsFile("ignore_me", "").containsNoMoreFiles();
    GitLogEntry merge = getLastMigratedChange(primaryBranch);
    assertThat(merge.getBody()).isEqualTo("Merge Gerrit change 1020 Patch Set 1\n" + "\n" + "DummyOrigin-RevId: test\n" + "Change-Id: " + CHANGE_ID + "\n");
    assertThat(Lists.transform(merge.getParents(), GitRevision::getSha1)).isEqualTo(Lists.newArrayList(previous.getCommit().getSha1(), firstChange.getSha1()));
    assertThat(console.getMessages().stream().filter(e -> e.getType() == MessageType.WARNING).findAny().get().getText()).contains("Change 1020 has more patch sets after Patch Set 1." + " Latest is Patch Set 2. Not all changes might be migrated");
}
Also used : Path(java.nio.file.Path) Writer(com.google.copybara.Destination.Writer) GitTestUtil(com.google.copybara.testing.git.GitTestUtil) Iterables(com.google.common.collect.Iterables) DummyRevision(com.google.copybara.testing.DummyRevision) Assert.assertThrows(org.junit.Assert.assertThrows) TransformResult(com.google.copybara.TransformResult) DummyOrigin(com.google.copybara.testing.DummyOrigin) RunWith(org.junit.runner.RunWith) RepoException(com.google.copybara.exception.RepoException) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) MessageType(com.google.copybara.util.console.Message.MessageType) WriterContext(com.google.copybara.WriterContext) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Strategy(com.google.copybara.git.GitIntegrateChanges.Strategy) GitTestUtil.getGitEnv(com.google.copybara.testing.git.GitTestUtil.getGitEnv) CannotResolveRevisionException(com.google.copybara.exception.CannotResolveRevisionException) GitTesting(com.google.copybara.git.testing.GitTesting) TransformResults(com.google.copybara.testing.TransformResults) Path(java.nio.file.Path) Before(org.junit.Before) DEFAULT_TIMEOUT(com.google.copybara.util.CommandRunner.DEFAULT_TIMEOUT) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ValidationException(com.google.copybara.exception.ValidationException) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) DestinationStatus(com.google.copybara.Destination.DestinationStatus) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Glob(com.google.copybara.util.Glob) FAKE_MERGE_AND_INCLUDE_FILES(com.google.copybara.git.GitIntegrateChanges.Strategy.FAKE_MERGE_AND_INCLUDE_FILES) Optional(java.util.Optional) INCLUDE_FILES(com.google.copybara.git.GitIntegrateChanges.Strategy.INCLUDE_FILES) FAKE_MERGE(com.google.copybara.git.GitIntegrateChanges.Strategy.FAKE_MERGE) Joiner(com.google.common.base.Joiner) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) Test(org.junit.Test)

Example 9 with DummyOrigin

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

the class GitDestinationReaderTest method setup.

@Before
public void setup() throws Exception {
    destinationPath = Files.createTempDirectory("destination");
    gitDir = Files.createTempDirectory("gitDir");
    console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console);
    options.setHomeDir(Files.createTempDirectory("home").toString());
    origin = new DummyOrigin();
    options.testingOptions.origin = origin;
    repo = GitRepository.newBareRepo(destinationPath, getGitEnv(), /*verbose=*/
    true, DEFAULT_TIMEOUT, /*noVerify=*/
    false).withWorkTree(gitDir).init();
    primaryBranch = repo.getPrimaryBranch();
    options.gitDestination.committerEmail = "commiter@email";
    options.gitDestination.committerName = "Bara Kopi";
    workDir = Files.createTempDirectory("workdir");
    options.setWorkdirToRealTempDir(workDir.toString());
    skylark = new SkylarkTestExecutor(options);
    origin.singleFileChange(1580341755, "first", "foo/origin.txt", "AAAA").singleFileChange(1580341795, "second", "foo/origin.txt", "BBBB");
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) DummyOrigin(com.google.copybara.testing.DummyOrigin) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 10 with DummyOrigin

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

the class MetadataModuleTest method setup.

@Before
public void setup() throws Exception {
    options = new OptionsBuilder();
    authoring = "authoring.overwrite('" + DEFAULT_AUTHOR + "')";
    workdir = Files.createTempDirectory("workdir");
    Files.createDirectories(workdir);
    origin = new DummyOrigin().setAuthor(ORIGINAL_AUTHOR);
    destination = new RecordsProcessCallDestination();
    options.setConsole(new TestingConsole());
    options.testingOptions.origin = origin;
    options.testingOptions.destination = destination;
    skylark = new SkylarkTestExecutor(options);
    origin.addSimpleChange(0, "first commit\n\nExtended text").setAuthor(FOO_BAR).addSimpleChange(1, "second commit\n\nExtended text").setAuthor(FOO_BAZ).addSimpleChange(2, "third commit\n\nExtended text");
    options.setLastRevision("0");
    // We don't care about already migrated code
    options.setForce(true);
    testingConsole = new TestingConsole();
    options.setConsole(testingConsole);
}
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

DummyOrigin (com.google.copybara.testing.DummyOrigin)11 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)10 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)10 Before (org.junit.Before)10 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)8 ValidationException (com.google.copybara.exception.ValidationException)5 RecordsProcessCallDestination (com.google.copybara.testing.RecordsProcessCallDestination)5 Test (org.junit.Test)5 Truth.assertThat (com.google.common.truth.Truth.assertThat)4 IOException (java.io.IOException)4 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)4 Files (java.nio.file.Files)4 Path (java.nio.file.Path)4 Joiner (com.google.common.base.Joiner)3 ImmutableList (com.google.common.collect.ImmutableList)3 Iterables (com.google.common.collect.Iterables)3 Lists (com.google.common.collect.Lists)3 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)3 DestinationStatus (com.google.copybara.Destination.DestinationStatus)3 Writer (com.google.copybara.Destination.Writer)3