use of com.google.copybara.testing.OptionsBuilder in project copybara by google.
the class GerritOriginTest method setup.
@Before
public void setup() throws Exception {
options = new OptionsBuilder();
TestingConsole console = new TestingConsole();
options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
SkylarkTestExecutor 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"));
String url = "file://" + remote.toFile().getAbsolutePath();
origin = skylark.eval("result", String.format("result = " + "git.gerrit_origin(" + " url = '%s'," + ")", url));
Files.write(remote.resolve("base.txt"), new byte[0]);
repo.add().files("base.txt").run();
git("commit", "-m", "baseline", "--date", commitTime);
baseline = repo.parseRef("HEAD");
Files.write(remote.resolve("test.txt"), "some content".getBytes());
repo.add().files("test.txt").run();
git("commit", "-m", "first change", "--date", commitTime);
firstRevision = new GitRevision(repo, repo.parseRef("HEAD"), GitRepoType.gerritPatchSetAsReviewReference(1), "12345", ImmutableMap.of(GERRIT_CHANGE_NUMBER_LABEL, "12345", GERRIT_CHANGE_ID_LABEL, CHANGE_ID, GERRIT_CHANGE_DESCRIPTION_LABEL, CHANGE_DESCRIPTION, DEFAULT_INTEGRATE_LABEL, "gerrit " + url + " 12345 Patch Set 1 " + CHANGE_ID), url);
git("update-ref", "refs/changes/45/12345/1", firstRevision.getSha1());
git("commit", "-m", "second change", "--date", commitTime, "--amend");
secondRevision = new GitRevision(repo, repo.parseRef("HEAD"), GitRepoType.gerritPatchSetAsReviewReference(2), "12345", ImmutableMap.of(GERRIT_CHANGE_NUMBER_LABEL, "12345", GERRIT_CHANGE_ID_LABEL, CHANGE_ID, GERRIT_CHANGE_DESCRIPTION_LABEL, CHANGE_DESCRIPTION, DEFAULT_INTEGRATE_LABEL, "gerrit " + url + " 12345 Patch Set 2 " + CHANGE_ID), url);
git("update-ref", "refs/changes/45/12345/2", secondRevision.getSha1());
git("commit", "-m", "third change", "--date", commitTime, "--amend");
thirdRevision = new GitRevision(repo, repo.parseRef("HEAD"), GitRepoType.gerritPatchSetAsReviewReference(3), "12345", ImmutableMap.of(GERRIT_CHANGE_NUMBER_LABEL, "12345", GERRIT_CHANGE_ID_LABEL, CHANGE_ID, GERRIT_CHANGE_DESCRIPTION_LABEL, CHANGE_DESCRIPTION, DEFAULT_INTEGRATE_LABEL, "gerrit " + url + " 12345 Patch Set 3 " + CHANGE_ID), url);
git("update-ref", "refs/changes/45/12345/3", thirdRevision.getSha1());
GitTestUtil.createFakeGerritNodeDbMeta(repo, 12345, CHANGE_ID);
}
use of com.google.copybara.testing.OptionsBuilder in project copybara by google.
the class GitDestinationIntegrateTest method setup.
@Before
public void setup() throws Exception {
repoGitDir = Files.createTempDirectory("GitDestinationTest-repoGitDir");
workdir = Files.createTempDirectory("workdir");
localHub = Files.createTempDirectory("localRepos");
git("init", "--bare", repoGitDir.toString());
console = new TestingConsole();
options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
options.git = new TestGitOptions(localHub, () -> options.general);
options.github = new GithubOptions(() -> options.general, options.git) {
@Override
protected HttpTransport getHttpTransport() {
return GitTestUtil.NO_GITHUB_API_CALLS;
}
};
options.gitDestination = new GitDestinationOptions(() -> options.general, options.git);
options.gitDestination.committerEmail = "commiter@email";
options.gitDestination.committerName = "Bara Kopi";
destinationFiles = Glob.createGlob(ImmutableList.of("**"), ImmutableList.of("ignore*"));
options.setForce(true);
url = "file://" + repoGitDir;
skylark = new SkylarkTestExecutor(options, GitModule.class);
}
use of com.google.copybara.testing.OptionsBuilder in project copybara by google.
the class GerritApiTest method setUp.
@Before
public void setUp() throws Exception {
OptionsBuilder options = new OptionsBuilder().setWorkdirToRealTempDir().setEnvironment(GitTestUtil.getGitEnv()).setOutputRootToTmpDir();
credentialsFile = Files.createTempFile("credentials", "test");
Files.write(credentialsFile, "https://user:SECRET@copybara-not-real.com".getBytes(UTF_8));
GitRepository repo = newBareRepo(Files.createTempDirectory("test_repo"), getGitEnv(), /*verbose=*/
true).init().withCredentialHelper("store --file=" + credentialsFile);
httpTransport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
String requestString = method + " " + url;
MockLowLevelHttpRequest request = new MockLowLevelHttpRequest();
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
request.setResponse(response);
for (Entry<Predicate<String>, byte[]> entry : requestToResponse.entrySet()) {
if (entry.getKey().test(requestString)) {
byte[] content = entry.getValue();
assertWithMessage("'" + method + " " + url + "'").that(content).isNotNull();
response.setContent(content);
return request;
}
}
response.setStatusCode(404);
response.setContent(("NO URL MATCHED! (Returning 404) REQUEST: " + requestString));
return request;
}
};
GerritOptions gerritOptions = new GerritOptions(() -> options.general, options.git) {
@Override
protected HttpTransport getHttpTransport() {
return httpTransport;
}
@Override
protected GitRepository getCredentialsRepo() throws RepoException {
return repo;
}
};
gerritApi = gerritOptions.newGerritApi(getHost() + "/foo/bar/baz");
}
use of com.google.copybara.testing.OptionsBuilder in project copybara by google.
the class PatchTransformationTest method setup.
@Before
public void setup() throws IOException {
checkoutDir = Files.createTempDirectory("workdir");
Files.createDirectories(checkoutDir);
console = new TestingConsole();
options = new OptionsBuilder().setConsole(console);
general = options.build().get(GeneralOptions.class);
skylark = new SkylarkTestExecutor(options, PatchModule.class);
ImmutableMap<String, byte[]> configFiles = ImmutableMap.of("diff.patch", (DIFF).getBytes(UTF_8), "series", ("diff.patch\n").getBytes(UTF_8));
patchFile = new MapConfigFile(configFiles, "diff.patch");
seriesFile = new MapConfigFile(configFiles, "series");
options.setEnvironment(GitTestUtil.getGitEnv());
}
use of com.google.copybara.testing.OptionsBuilder in project copybara by google.
the class CoreTransformTest method setup.
@Before
public void setup() throws IOException {
FileSystem fs = Jimfs.newFileSystem();
checkoutDir = fs.getPath("/test-checkoutDir");
Files.createDirectories(checkoutDir);
OptionsBuilder options = new OptionsBuilder();
skylark = new SkylarkTestExecutor(options, Core.class);
console = new TestingConsole();
options.setConsole(console);
}
Aggregations