use of com.walmartlabs.concord.common.TemporaryPath in project concord by walmartlabs.
the class GitClientFetchTest method testFetch2.
@Test
public void testFetch2() throws Exception {
Path repo = GitUtils.createBareRepository(resourceToPath("/master"));
RevCommit commit0 = GitUtils.addContent(repo, resourceToPath("/test5/0_concord.yml"));
RevCommit commit1 = GitUtils.addContent(repo, resourceToPath("/test5/1_concord.yml"));
RevCommit commit2 = GitUtils.addContent(repo, resourceToPath("/test5/2_concord.yml"));
List<RevCommit> commits = Arrays.asList(commit0, commit1, commit2);
// fetch by commit + branch with clean repo
for (int i = 0; i < 3; i++) {
String commitId = commits.get(i).name();
try (TemporaryPath repoPath = IOUtils.tempDir("git-client-test")) {
String result = fetch(repo.toString(), "master", commitId, null, repoPath.path());
assertContent(repoPath, i + "_concord.yml", i + "-concord-content");
assertEquals(commitId, result);
}
}
// fetch by commit with clean repo
for (int i = 0; i < 3; i++) {
String commitId = commits.get(i).name();
try (TemporaryPath repoPath = IOUtils.tempDir("git-client-test")) {
String result = fetch(repo.toString(), null, commitId, null, repoPath.path());
assertContent(repoPath, i + "_concord.yml", i + "-concord-content");
assertEquals(commitId, result);
}
}
}
use of com.walmartlabs.concord.common.TemporaryPath in project concord by walmartlabs.
the class GitClientFetchTest method testFetch3.
@Test
public void testFetch3() throws Exception {
Path repo = GitUtils.createBareRepository(resourceToPath("/master"));
GitUtils.createNewBranch(repo, "branch-1", resourceToPath("/branch-1"));
GitUtils.createNewTag(repo, "tag-1", resourceToPath("/tag-1"));
String commitId;
String tagCommitId;
try (TemporaryPath repoPath = IOUtils.tempDir("git-client-test")) {
// fetch master
fetch(repo.toString(), "master", null, null, repoPath.path());
assertContent(repoPath, "master.txt", "master");
// fetch branch
commitId = fetch(repo.toString(), "branch-1", null, null, repoPath.path());
assertContent(repoPath, "branch-1.txt", "branch-1");
// fetch tag
tagCommitId = fetch(repo.toString(), "tag-1", null, null, repoPath.path());
assertContent(repoPath, "tag-1.txt", "tag-1");
// fetch by commit
fetch(repo.toString(), null, commitId, null, repoPath.path());
assertContent(repoPath, "branch-1.txt", "branch-1");
fetch(repo.toString(), null, tagCommitId, null, repoPath.path());
assertContent(repoPath, "tag-1.txt", "tag-1");
}
// fetch by commit with clean repo
try (TemporaryPath repoPath = IOUtils.tempDir("git-client-test")) {
String result = fetch(repo.toString(), "branch-1", commitId, null, repoPath.path());
assertContent(repoPath, "branch-1.txt", "branch-1");
assertEquals(result, commitId);
}
// fetch by commit with clean repo
try (TemporaryPath repoPath = IOUtils.tempDir("git-client-test")) {
String result = fetch(repo.toString(), "tag-1", tagCommitId, null, repoPath.path());
assertContent(repoPath, "tag-1.txt", "tag-1");
assertEquals(result, tagCommitId);
}
// fetch by commit with clean repo and without branch -> should fetch all repo and checkout commit-id
try (TemporaryPath repoPath = IOUtils.tempDir("git-client-test")) {
String result = fetch(repo.toString(), null, commitId, null, repoPath.path());
assertContent(repoPath, "branch-1.txt", "branch-1");
assertEquals(result, commitId);
}
// fetch same branch two times
try (TemporaryPath repoPath = IOUtils.tempDir("git-client-test")) {
// fetch branch
fetch(repo.toString(), "branch-1", null, null, repoPath.path());
assertContent(repoPath, "branch-1.txt", "branch-1");
// fetch branch
fetch(repo.toString(), "branch-1", null, null, repoPath.path());
assertContent(repoPath, "branch-1.txt", "branch-1");
}
}
use of com.walmartlabs.concord.common.TemporaryPath in project concord by walmartlabs.
the class GitClientRealTest method testFetchWithSubmodules.
@Test
public void testFetchWithSubmodules() throws Exception {
String branch = "master";
String commitId = null;
// with default oauth token
Secret secret = null;
try (TemporaryPath repoPath = IOUtils.tempDir("git-client-test")) {
fetch(HTTPS_SUBMODULE_REPO_URL, branch, commitId, secret, repoPath.path());
assertEquals("master", new String(Files.readAllBytes(repoPath.path().resolve("test"))).trim());
assertEquals("master", new String(Files.readAllBytes(repoPath.path().resolve("concord_poc").resolve("test"))).trim());
}
}
use of com.walmartlabs.concord.common.TemporaryPath in project concord by walmartlabs.
the class GitClientRealTest method assertFetch.
private void assertFetch(String url, String branch, String commitId, Secret secret, String expectedContent) throws IOException {
try (TemporaryPath repoPath = IOUtils.tempDir("git-client-test")) {
fetch(url, branch, commitId, secret, repoPath.path());
assertEquals(expectedContent, new String(Files.readAllBytes(repoPath.path().resolve("test"))).trim());
}
}
use of com.walmartlabs.concord.common.TemporaryPath in project concord by walmartlabs.
the class GitUtils method addContent.
public static RevCommit addContent(Path bareRepo, Path file) throws Exception {
try (TemporaryPath tmp = IOUtils.tempDir("repo-tmp");
Git git = Git.cloneRepository().setDirectory(tmp.path().toFile()).setURI(bareRepo.toAbsolutePath().toString()).call()) {
Files.copy(file, tmp.path().resolve(file.getFileName()), StandardCopyOption.REPLACE_EXISTING);
git.add().addFilepattern(".").call();
RevCommit commit = git.commit().setSign(false).setMessage("update").call();
git.push().call();
return commit;
}
}
Aggregations