Search in sources :

Example 76 with TestingConsole

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

the class HgDestinationTest method setup.

@Before
public void setup() throws Exception {
    options = new OptionsBuilder().setHomeDir(Files.createTempDirectory("home").toString());
    destinationFiles = Glob.ALL_FILES;
    options.general.setFileSystemForTest(FileSystems.getDefault());
    workdir = options.general.getDirFactory().newTempDir("workdir");
    console = new TestingConsole();
    hgDestPath = Files.createTempDirectory("HgDestinationTest-hgDestRepo");
    url = "file://" + hgDestPath;
    remoteRepo = new HgRepository(hgDestPath, /*verbose*/
    false, CommandRunner.DEFAULT_TIMEOUT);
    remoteRepo.init();
    Files.write(hgDestPath.resolve("file.txt"), "first write".getBytes(UTF_8));
    remoteRepo.hg(hgDestPath, "add");
    remoteRepo.hg(hgDestPath, "commit", "-m", "first commit");
    fetch = "tip";
    push = "default";
    destination = HgDestination.newHgDestination(url, fetch, push, options.general, options.hg);
    writer = newWriter();
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) Before(org.junit.Before)

Example 77 with TestingConsole

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

the class CommandLineGuideTest method testGitToGitTemplatePredicateNotSatisfied.

@Test
public void testGitToGitTemplatePredicateNotSatisfied() {
    String urlPrefix = "https://github.com/google/";
    TestingConsole console = new TestingConsole();
    console.respondWithString(urlPrefix.concat("origin")).respondWithString(urlPrefix.concat("destination")).respondWithString("not a valid email");
    optionsBuilder.setConsole(console);
    CommandLineGuide.runForCommandLine(new CommandEnv(temp, skylark.createModuleSet().getOptions(), ImmutableList.of("copy.bara.sky")));
    assertThat(Joiner.on('\n').join(console.getMessages().stream().map(Message::getText).collect(Collectors.toList()))).contains("Invalid response");
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Message(com.google.copybara.util.console.Message) CommandEnv(com.google.copybara.CommandEnv) Test(org.junit.Test)

Example 78 with TestingConsole

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

the class CommandLineGuideTest method testGitToGitTemplate.

@Test
public void testGitToGitTemplate() {
    TestingConsole console = new TestingConsole();
    String urlPrefix = "https://github.com/google/";
    console.respondWithString(urlPrefix.concat("origin")).respondWithString(urlPrefix.concat("destination")).respondWithString("Copybara <copy@bara.com>");
    optionsBuilder.setConsole(console);
    CommandLineGuide.runForCommandLine(new CommandEnv(temp, skylark.createModuleSet().getOptions(), ImmutableList.of("copy.bara.sky")));
    ConfigBuilder expectedConfig = new ConfigBuilder(new GitToGitTemplate());
    expectedConfig.setNamedStringParameter("origin_url", urlPrefix.concat("origin"));
    expectedConfig.setNamedStringParameter("destination_url", urlPrefix.concat("destination"));
    expectedConfig.setNamedStringParameter("email", "Copybara <copy@bara.com>");
    assertThat(Joiner.on('\n').join(console.getMessages().stream().map(Message::getText).collect(Collectors.toList()))).contains(expectedConfig.build());
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Message(com.google.copybara.util.console.Message) CommandEnv(com.google.copybara.CommandEnv) Test(org.junit.Test)

Example 79 with TestingConsole

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

the class LatestVersionSelectorTest method setup.

@Before
public void setup() throws Exception {
    options = new OptionsBuilder();
    TestingConsole console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
    skylark = new SkylarkTestExecutor(options);
    // 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().getEnvironment());
    options.setHomeDir(userHomeForTest.toString());
    createTestRepo(Files.createTempDirectory("remote"));
    url = "file://" + remote.toFile().getAbsolutePath();
    writeFile(remote, "test.txt", "some content");
    repo.add().files("test.txt").run();
    git("commit", "-m", "first file", "--date", COMMIT_TIME);
    cliReference = "foo";
}
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 80 with TestingConsole

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

the class DurationConverterTest method checkFetchTimeout.

private void checkFetchTimeout(String flagValue, Duration expected) throws IOException {
    ImmutableMap<String, String> envWithHome = ImmutableMap.of("HOME", Files.createTempDirectory("foo").toString());
    ModuleSupplier moduleSupplier = new ModuleSupplier(envWithHome, FileSystems.getDefault(), new TestingConsole());
    Options options = moduleSupplier.create().getOptions();
    JCommander jCommander = new JCommander(options.getAll());
    jCommander.parse("--fetch-timeout", flagValue);
    assertThat(options.get(GeneralOptions.class).fetchTimeout).isEquivalentAccordingToCompareTo(expected);
}
Also used : GeneralOptions(com.google.copybara.GeneralOptions) Options(com.google.copybara.Options) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) GeneralOptions(com.google.copybara.GeneralOptions) JCommander(com.beust.jcommander.JCommander) ModuleSupplier(com.google.copybara.ModuleSupplier)

Aggregations

TestingConsole (com.google.copybara.util.console.testing.TestingConsole)96 Before (org.junit.Before)57 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)55 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)54 Test (org.junit.Test)34 Path (java.nio.file.Path)15 GitTestUtil (com.google.copybara.testing.git.GitTestUtil)8 FileSystem (java.nio.file.FileSystem)8 IOException (java.io.IOException)7 LowLevelHttpRequest (com.google.api.client.http.LowLevelHttpRequest)6 DummyChecker (com.google.copybara.testing.DummyChecker)6 DummyOrigin (com.google.copybara.testing.DummyOrigin)6 Console (com.google.copybara.util.console.Console)6 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)5 MockLowLevelHttpRequest (com.google.api.client.testing.http.MockLowLevelHttpRequest)5 MockLowLevelHttpResponse (com.google.api.client.testing.http.MockLowLevelHttpResponse)5 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)5 GitRepository (com.google.copybara.git.GitRepository)5 LowLevelHttpResponse (com.google.api.client.http.LowLevelHttpResponse)4 RepoException (com.google.copybara.exception.RepoException)4