Search in sources :

Example 1 with TestingLog

use of org.jfrog.build.extractor.util.TestingLog in project build-info by JFrogDev.

the class GitUtilsTest method testExtractVcsWithSubmodule.

@Test
private void testExtractVcsWithSubmodule() throws IOException, URISyntaxException {
    String parentDotGitResource = "git_submodule_parent_.git_suffix";
    String submoduleDotGitResource = "git_submodule_.git_suffix";
    File testResourcesPath = new File(this.getClass().getResource("/gitutils").toURI()).getCanonicalFile();
    File parentDotGitFile = new File(testResourcesPath, ".git");
    String submoduleDotGitFilePath = testResourcesPath.toString() + File.separator + "subDir" + File.separator + "subModule" + File.separator + ".git";
    File submoduleDotGitFile = new File(submoduleDotGitFilePath);
    try {
        // Copy the parent folder and create .git.
        FileUtils.copyDirectory(new File(testResourcesPath, parentDotGitResource), parentDotGitFile);
        // Copy the submodule .git file to the correct path.
        FileUtils.copyFile(new File(testResourcesPath, submoduleDotGitResource), submoduleDotGitFile);
        // Get VCS info.
        Log testLog = new TestingLog();
        Vcs vcs = GitUtils.extractVcs((new File(submoduleDotGitFilePath)).getAbsoluteFile(), testLog);
        // Validate.
        Assert.assertNotNull(vcs);
        Assert.assertEquals(vcs.getUrl(), "https://github.com/jfrog/subModule.git");
        Assert.assertEquals(vcs.getRevision(), "thisIsADummyRevision");
    } finally {
        // Cleanup.
        FileUtils.forceDelete(submoduleDotGitFile);
        FileUtils.deleteDirectory(parentDotGitFile);
    }
}
Also used : Log(org.jfrog.build.api.util.Log) TestingLog(org.jfrog.build.extractor.util.TestingLog) Vcs(org.jfrog.build.extractor.ci.Vcs) TestingLog(org.jfrog.build.extractor.util.TestingLog) File(java.io.File) Test(org.testng.annotations.Test)

Example 2 with TestingLog

use of org.jfrog.build.extractor.util.TestingLog in project build-info by JFrogDev.

the class GitUtilsTest method testReadGitConfig.

/**
 * Tests extracting Vcs details manually by comparing results to those received from the git executable
 */
@Test
private void testReadGitConfig() throws IOException, InterruptedException, URISyntaxException {
    String gitResource = "git_simple_.git_suffix";
    File testResourcesPath = new File(this.getClass().getResource("/gitutils").toURI()).getCanonicalFile();
    File dotGitDir = new File(testResourcesPath, ".git").getAbsoluteFile();
    try {
        FileUtils.copyDirectory(new File(testResourcesPath, gitResource), dotGitDir);
        Log testLog = new TestingLog();
        Vcs vcs = GitUtils.extractVcs(dotGitDir, testLog);
        Assert.assertNotNull(vcs);
        Assert.assertEquals(vcs.getUrl(), getGitUrlWithExecutor(dotGitDir, testLog));
        Assert.assertEquals(vcs.getRevision(), getGitRevisionWithExecutor(dotGitDir, testLog));
        Assert.assertEquals(vcs.getBranch(), getGitBranchWithExecutor(dotGitDir, testLog));
        Assert.assertEquals(vcs.getMessage(), getGitMessageWithExecutor(dotGitDir, testLog));
    } finally {
        // Cleanup.
        FileUtils.deleteDirectory(dotGitDir);
    }
}
Also used : Log(org.jfrog.build.api.util.Log) TestingLog(org.jfrog.build.extractor.util.TestingLog) Vcs(org.jfrog.build.extractor.ci.Vcs) TestingLog(org.jfrog.build.extractor.util.TestingLog) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

File (java.io.File)2 Log (org.jfrog.build.api.util.Log)2 Vcs (org.jfrog.build.extractor.ci.Vcs)2 TestingLog (org.jfrog.build.extractor.util.TestingLog)2 Test (org.testng.annotations.Test)2