Search in sources :

Example 1 with TestingConsole

use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.

the class GitDestinationTest method processUserAborts.

@Test
public void processUserAborts() throws Exception {
    console = new TestingConsole().respondNo();
    fetch = "master";
    push = "master";
    Files.write(workdir.resolve("test.txt"), "some content".getBytes());
    thrown.expect(ValidationException.class);
    thrown.expectMessage("User aborted execution: did not confirm diff changes");
    processWithBaselineAndConfirmation(firstCommitWriter(), new DummyRevision("origin_ref"), /*baseline=*/
    null, /*askForConfirmation=*/
    true);
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 2 with TestingConsole

use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.

the class GitDestinationTest method processEmptyDiff.

@Test
public void processEmptyDiff() throws Exception {
    console = new TestingConsole().respondYes();
    fetch = "master";
    push = "master";
    Files.write(workdir.resolve("test.txt"), "some content".getBytes());
    processWithBaselineAndConfirmation(firstCommitWriter(), new DummyRevision("origin_ref1"), /*baseline=*/
    null, /*askForConfirmation=*/
    true);
    thrown.expect(EmptyChangeException.class);
    // process empty change. Shouldn't ask anything.
    processWithBaselineAndConfirmation(newWriter(), new DummyRevision("origin_ref2"), /*baseline=*/
    null, /*askForConfirmation=*/
    true);
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 3 with TestingConsole

use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.

the class GitOriginSubmodulesTest method setup.

@Before
public void setup() throws Exception {
    OptionsBuilder options = new OptionsBuilder().setConsole(new TestingConsole()).setOutputRootToTmpDir();
    skylark = new SkylarkTestExecutor(options, GitModule.class);
    // Pass custom HOME directory so that we run an hermetic test and we
    // can add custom configuration to $HOME/.gitconfig.
    Path userHomeForTest = Files.createTempDirectory("home");
    options.setHomeDir(userHomeForTest.toString());
    checkoutDir = Files.createTempDirectory("checkout");
}
Also used : Path(java.nio.file.Path) 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 4 with TestingConsole

use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.

the class GitOriginTest method testGitUrlOverwrite.

/**
 * Check that we can overwrite the git url using the CLI option and that we show a message
 */
@Test
public void testGitUrlOverwrite() throws Exception {
    createTestRepo(Files.createTempDirectory("cliremote"));
    git("init");
    Files.write(remote.resolve("cli_remote.txt"), "some change".getBytes(UTF_8));
    repo.add().files("cli_remote.txt").run();
    git("commit", "-m", "a change from somewhere");
    TestingConsole testConsole = new TestingConsole();
    options.setConsole(testConsole);
    origin = origin();
    String newUrl = "file://" + remote.toFile().getAbsolutePath();
    Reader<GitRevision> reader = newReader();
    Change<GitRevision> cliHead = reader.change(origin.resolve(newUrl));
    reader.checkout(cliHead.getRevision(), checkoutDir);
    assertThat(cliHead.firstLineMessage()).isEqualTo("a change from somewhere");
    assertThatPath(checkoutDir).containsFile("cli_remote.txt", "some change").containsNoMoreFiles();
    testConsole.assertThat().onceInLog(MessageType.WARNING, "Git origin URL overwritten in the command line as " + newUrl);
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Test(org.junit.Test)

Example 5 with TestingConsole

use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.

the class GitOriginTest method setup.

@Before
public void setup() throws Exception {
    options = new OptionsBuilder();
    console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
    skylark = new SkylarkTestExecutor(options, GitModule.class);
    // Pass custom HOME directory so that we run an hermetic test and we
    // can add custom configuration to $HOME/.gitconfig.
    Path userHomeForTest = Files.createTempDirectory("home");
    options.setEnvironment(GitTestUtil.getGitEnv());
    options.setHomeDir(userHomeForTest.toString());
    createTestRepo(Files.createTempDirectory("remote"));
    checkoutDir = Files.createTempDirectory("checkout");
    url = "file://" + remote.toFile().getAbsolutePath();
    ref = "other";
    moreOriginArgs = "";
    origin = origin();
    Files.write(remote.resolve("test.txt"), "some content".getBytes(UTF_8));
    repo.add().files("test.txt").run();
    git("commit", "-m", "first file", "--date", commitTime);
    firstCommitRef = repo.parseRef("HEAD");
    originFiles = Glob.ALL_FILES;
}
Also used : Path(java.nio.file.Path) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) 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

TestingConsole (com.google.copybara.util.console.testing.TestingConsole)43 Before (org.junit.Before)30 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)28 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)24 Test (org.junit.Test)12 FileSystem (java.nio.file.FileSystem)7 Core (com.google.copybara.Core)5 Path (java.nio.file.Path)5 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)4 SkylarkParser (com.google.copybara.config.SkylarkParser)4 RepoException (com.google.copybara.exception.RepoException)4 DummyOrigin (com.google.copybara.testing.DummyOrigin)4 TestGitOptions (com.google.copybara.testing.git.GitTestUtil.TestGitOptions)4 HttpTransport (com.google.api.client.http.HttpTransport)3 Authoring (com.google.copybara.authoring.Authoring)3 DummyRevision (com.google.copybara.testing.DummyRevision)3 GitApiMockHttpTransport (com.google.copybara.testing.OptionsBuilder.GitApiMockHttpTransport)3 RecordsProcessCallDestination (com.google.copybara.testing.RecordsProcessCallDestination)3 MockLowLevelHttpRequest (com.google.api.client.testing.http.MockLowLevelHttpRequest)2 GeneralOptions (com.google.copybara.GeneralOptions)2