use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class GlobConverterTest method parseGlob.
private PathMatcher parseGlob(String value) 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("--read-config-from-head-paths", value);
return options.get(WorkflowOptions.class).readConfigFromChangePaths.relativeTo(Paths.get("/"));
}
use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class OnboardCmdTest method testOnboardCmdTextAdventure.
@Test
public void testOnboardCmdTextAdventure() throws Exception {
TestingConsole console = new TestingConsole();
console.respondWithString("https://github.com/google/origin").respondWithString("https://github.com/google/destination").respondWithString("Copybara <copy@bara.com>");
optionsBuilder.setConsole(console);
OnboardCmd onboardCmd = new OnboardCmd();
ExitCode exit = onboardCmd.run(new CommandEnv(temp, skylark.createModuleSet().getOptions(), ImmutableList.of("copy.bara.sky")));
assertThat(exit).isEqualTo(ExitCode.SUCCESS);
ConfigBuilder expectedConfig = new ConfigBuilder(new GitToGitTemplate());
expectedConfig.setNamedStringParameter("origin_url", "https://github.com/google/origin");
expectedConfig.setNamedStringParameter("destination_url", "https://github.com/google/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 GitRepoTypeTest method setup.
@Before
public void setup() throws Exception {
repoGitDir = Files.createTempDirectory("testRepo");
fileRepoDir = Files.createTempDirectory("fileRepo");
// We mock by default to avoid accidental network calls.
testRepo = new GitRepository(repoGitDir, null, /*verbose=*/
true, getGitEnv(), Duration.ofMinutes(1), /*noVerify=*/
false) {
@Override
public GitRevision fetchSingleRefWithTags(String url, String ref, boolean fetchTags, boolean partialFetch) {
interceptedFetches.add(new String[] { url, ref });
return new GitRevision(this, Strings.repeat("0", 40));
}
};
testRepo.init();
prepareFileRepo();
console = new TestingConsole();
generalOptions = new OptionsBuilder().setConsole(console).build().get(GeneralOptions.class);
}
use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class SameGitTreeTest method setup.
@Before
public void setup() throws Exception {
workdir = Files.createTempDirectory("workdir");
gitDir = Files.createTempDirectory("gitdir");
console = new TestingConsole();
options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
repository = GitRepository.newBareRepo(gitDir, getGitEnv(), /*verbose=*/
true, DEFAULT_TIMEOUT, /*noVerify=*/
false).withWorkTree(workdir);
repository.init();
}
use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class GitHubApiTest method getTransport.
@Override
public GitHubApiTransport getTransport() throws Exception {
credentialsFile = Files.createTempFile("credentials", "test");
Files.write(credentialsFile, "https://user:SECRET@github.com".getBytes(UTF_8));
GitRepository repo = newBareRepo(Files.createTempDirectory("test_repo"), getGitEnv(), /*verbose=*/
true, DEFAULT_TIMEOUT, /*noVerify=*/
false).init().withCredentialHelper("store --file=" + credentialsFile);
requestToResponse = new HashMap<>();
requestValidators = new HashMap<>();
httpTransport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
String requestString = method + " " + url;
MockLowLevelHttpRequest request = new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() throws IOException {
System.err.println(getContentAsString());
Predicate<String> validator = requestValidators.get(method + " " + url);
if (validator != null) {
assertWithMessage("Request content did not match expected values.").that(validator.test(getContentAsString())).isTrue();
}
return super.execute();
}
};
MockLowLevelHttpResponse response = requestToResponse.get(requestString);
if (response == null) {
response = new MockLowLevelHttpResponse();
response.setContent(String.format("{ 'message' : 'This is not the repo you are looking for! %s %s'," + " 'documentation_url' : 'http://github.com/some_url'}", method, url));
response.setStatusCode(404);
}
request.setResponse(response);
return request;
}
};
return new GitHubApiTransportImpl(repo, httpTransport, "some_storage_file", new TestingConsole());
}
Aggregations