Search in sources :

Example 6 with TemporaryPath

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);
        }
    }
}
Also used : Path(java.nio.file.Path) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.jupiter.api.Test)

Example 7 with TemporaryPath

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");
    }
}
Also used : Path(java.nio.file.Path) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) Test(org.junit.jupiter.api.Test)

Example 8 with TemporaryPath

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());
    }
}
Also used : Secret(com.walmartlabs.concord.sdk.Secret) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) Test(org.junit.jupiter.api.Test)

Example 9 with TemporaryPath

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());
    }
}
Also used : TemporaryPath(com.walmartlabs.concord.common.TemporaryPath)

Example 10 with TemporaryPath

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;
    }
}
Also used : Git(org.eclipse.jgit.api.Git) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

TemporaryPath (com.walmartlabs.concord.common.TemporaryPath)20 Path (java.nio.file.Path)10 Test (org.junit.jupiter.api.Test)8 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 ZipArchiveOutputStream (org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream)4 UUID (java.util.UUID)3 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)2 State (com.walmartlabs.concord.svm.State)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Git (org.eclipse.jgit.api.Git)2 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)2 Repository (com.walmartlabs.concord.repository.Repository)1 Secret (com.walmartlabs.concord.sdk.Secret)1 RepositoryUtils.assertRepository (com.walmartlabs.concord.server.org.project.RepositoryUtils.assertRepository)1 ProcessEntry (com.walmartlabs.concord.server.process.ProcessEntry)1 RepositoryRefreshListener (com.walmartlabs.concord.server.repository.listeners.RepositoryRefreshListener)1 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)1 ExecutionException (io.takari.bpm.api.ExecutionException)1 URI (java.net.URI)1