|
50 | 50 | import org.apache.commons.lang3.StringUtils; |
51 | 51 | import org.apache.commons.lang3.SystemUtils; |
52 | 52 | import org.junit.jupiter.api.AfterEach; |
| 53 | +import org.junit.jupiter.api.Assumptions; |
53 | 54 | import org.junit.jupiter.api.BeforeEach; |
54 | 55 | import org.junit.jupiter.api.Test; |
| 56 | +import org.junit.jupiter.api.io.TempDir; |
55 | 57 | import org.junit.jupiter.params.ParameterizedTest; |
56 | 58 | import org.junit.jupiter.params.provider.Arguments; |
57 | 59 | import org.junit.jupiter.params.provider.MethodSource; |
@@ -517,6 +519,24 @@ void testGitBlobPath(final String resourceName, final String expectedSha1Hex) th |
517 | 519 | assertArrayEquals(Hex.decodeHex(expectedSha1Hex), DigestUtils.gitBlob(DigestUtils.getSha1Digest(), resourcePath(resourceName))); |
518 | 520 | } |
519 | 521 |
|
| 522 | + @Test |
| 523 | + void testGitBlobSymlink(@TempDir final Path tempDir) throws Exception { |
| 524 | + final Path subDir = Files.createDirectory(tempDir.resolve("subdir")); |
| 525 | + Files.write(subDir.resolve("file.txt"), "hello".getBytes(StandardCharsets.UTF_8)); |
| 526 | + final Path linkToDir; |
| 527 | + final Path linkToFile; |
| 528 | + try { |
| 529 | + linkToDir = Files.createSymbolicLink(tempDir.resolve("link-to-dir"), Paths.get("subdir")); |
| 530 | + linkToFile = Files.createSymbolicLink(tempDir.resolve("link-to-file"), Paths.get("subdir/file.txt")); |
| 531 | + } catch (final UnsupportedOperationException e) { |
| 532 | + Assumptions.assumeTrue(false, "Symbolic links not supported on this filesystem"); |
| 533 | + return; |
| 534 | + } |
| 535 | + final MessageDigest sha1 = DigestUtils.getSha1Digest(); |
| 536 | + assertArrayEquals(Hex.decodeHex("8bbe8a53790056316b23b7c270f10ab6bf6bb1b4"), DigestUtils.gitBlob(sha1, linkToDir)); |
| 537 | + assertArrayEquals(Hex.decodeHex("dfe6ef8392ae13a11ff85419b4fd906d997b6cb7"), DigestUtils.gitBlob(sha1, linkToFile)); |
| 538 | + } |
| 539 | + |
520 | 540 | @ParameterizedTest |
521 | 541 | @ValueSource(strings = {MessageDigestAlgorithms.SHA_1, MessageDigestAlgorithms.SHA_256}) |
522 | 542 | void testGitTreeCollection(final String algorithm) throws Exception { |
|
0 commit comments