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();
}
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");
}
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());
}
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";
}
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);
}
Aggregations