use of com.google.copybara.testing.git.GitTestUtil.Validator in project copybara by google.
the class GithubPrOriginTest method setup.
@Before
public void setup() throws Exception {
repoGitDir = Files.createTempDirectory("GithubPrDestinationTest-repoGitDir");
workdir = Files.createTempDirectory("workdir");
localHub = Files.createTempDirectory("localHub");
git("init", "--bare", repoGitDir.toString());
console = new TestingConsole();
options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
options.git = new TestGitOptions(localHub, () -> this.options.general, new Validator() {
@Override
public void validateFetch(String url, boolean prune, boolean force, Iterable<String> refspecs) {
for (String refspec : refspecs) {
// WARNING! This check is important. While using short names like
// 'master' in git fetch works for local git invocations, other
// implementations of GitRepository might have problems if we don't
// pass the whole reference.
assertThat(refspec).startsWith("refs/");
assertThat(refspec).contains(":refs/");
}
}
});
options.github = new GithubOptions(() -> options.general, options.git) {
@Override
public GithubApi getApi(String project) throws RepoException {
assertThat(project).isEqualTo(expectedProject);
return super.getApi(project);
}
@Override
protected HttpTransport getHttpTransport() {
return gitApiMockHttpTransport;
}
};
Path credentialsFile = Files.createTempFile("credentials", "test");
Files.write(credentialsFile, "https://user:SECRET@github.com".getBytes(UTF_8));
options.git.credentialHelperStorePath = credentialsFile.toString();
skylark = new SkylarkTestExecutor(options, GitModule.class);
skylarkParser = new SkylarkParser(ImmutableSet.of(Core.class, Authoring.Module.class, FolderModule.class, GitModule.class));
}
Aggregations