aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.lfs.test
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2021-02-25 10:29:07 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2021-02-28 00:58:04 +0100
commitf6597971991e3350df568b0cde05c014dcd69c47 (patch)
treecb61592af3f53da45174beed517b3284d7bd55c6 /org.eclipse.jgit.lfs.test
parent286ad23cb56ffeac77d4bfd03be575358fd5217c (diff)
parent789c0479a9294417db0375cce9f1949fe9052d8c (diff)
downloadjgit-f6597971991e3350df568b0cde05c014dcd69c47.tar.gz
jgit-f6597971991e3350df568b0cde05c014dcd69c47.zip
Merge branch 'master' into next
* master: (143 commits) Prepare 5.11.0-SNAPSHOT builds JGit v5.11.0.202102240950-m3 [releng] japicmp: update last release version IgnoreNode: include path to file for invalid .gitignore patterns FastIgnoreRule: include bad pattern in log message init: add config option to set default for the initial branch name init: allow specifying the initial branch name for the new repository Fail clone if initial branch doesn't exist in remote repository GPG: fix reading unprotected old-format secret keys Update Orbit to S20210216215844 Add missing bazel dependency for o.e.j.gpg.bc.test GPG: handle extended private key format dfs: handle short copies [GPG] Provide a factory for the BouncyCastleGpgSigner Fix boxing warnings GPG: compute the keygrip to find a secret key GPG signature verification via BouncyCastle Post commit hook failure should not cause commit failure Allow to define additional Hook classes outside JGit GitHook: use default charset for output and error streams ... Change-Id: I689f4070e79f4a0ac1c02b35698ccaab68ad2f34
Diffstat (limited to 'org.eclipse.jgit.lfs.test')
-rw-r--r--org.eclipse.jgit.lfs.test/.settings/org.eclipse.jdt.core.prefs4
-rw-r--r--org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java270
2 files changed, 269 insertions, 5 deletions
diff --git a/org.eclipse.jgit.lfs.test/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jgit.lfs.test/.settings/org.eclipse.jdt.core.prefs
index 3dd5840397..b853c6a7ed 100644
--- a/org.eclipse.jgit.lfs.test/.settings/org.eclipse.jdt.core.prefs
+++ b/org.eclipse.jgit.lfs.test/.settings/org.eclipse.jdt.core.prefs
@@ -51,8 +51,8 @@ org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=error
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=protected
-org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
-org.eclipse.jdt.core.compiler.problem.missingJavadocTags=error
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=no_tag
+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=private
diff --git a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java
index 7ee898fab2..da78b28d90 100644
--- a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java
+++ b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java
@@ -12,7 +12,13 @@ package org.eclipse.jgit.lfs.lib;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -23,17 +29,275 @@ import org.junit.Test;
* Test LfsPointer file abstraction
*/
public class LFSPointerTest {
+
+ private static final String TEST_SHA256 = "27e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+
@Test
public void testEncoding() throws IOException {
- final String s = "27e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
- AnyLongObjectId id = LongObjectId.fromString(s);
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
LfsPointer ptr = new LfsPointer(id, 4);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ptr.encode(baos);
assertEquals(
"version https://git-lfs.github.com/spec/v1\noid sha256:"
- + s + "\nsize 4\n",
+ + TEST_SHA256 + "\nsize 4\n",
baos.toString(UTF_8.name()));
}
}
+
+ @Test
+ public void testReadValidLfsPointer() throws Exception {
+ String ptr = "version https://git-lfs.github.com/spec/v1\n"
+ + "oid sha256:" + TEST_SHA256 + '\n'
+ + "size 4\n";
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ ptr.getBytes(UTF_8))) {
+ assertEquals(lfs, LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadValidLfsPointerUnordered() throws Exception {
+ // This is actually not allowed per the spec, but JGit accepts it
+ // anyway.
+ String ptr = "version https://git-lfs.github.com/spec/v1\n"
+ + "size 4\n"
+ + "oid sha256:" + TEST_SHA256 + '\n';
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ ptr.getBytes(UTF_8))) {
+ assertEquals(lfs, LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadValidLfsPointerVersionNotFirst() throws Exception {
+ // This is actually not allowed per the spec, but JGit accepts it
+ // anyway.
+ String ptr = "oid sha256:" + TEST_SHA256 + '\n'
+ + "size 4\n"
+ + "version https://git-lfs.github.com/spec/v1\n";
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ ptr.getBytes(UTF_8))) {
+ assertEquals(lfs, LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadInvalidLfsPointer() throws Exception {
+ String cSource = "size_t someFunction(void *ptr); // Fake C source\n";
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ cSource.getBytes(UTF_8))) {
+ assertNull("Is not a LFS pointer", LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadInvalidLfsPointer2() throws Exception {
+ String cSource = "size_t\nsomeFunction(void *ptr);\n// Fake C source\n";
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ cSource.getBytes(UTF_8))) {
+ assertNull("Is not a LFS pointer", LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadInValidLfsPointerVersionWrong() throws Exception {
+ String ptr = "version https://git-lfs.example.org/spec/v1\n"
+ + "oid sha256:" + TEST_SHA256 + '\n'
+ + "size 4\n";
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ ptr.getBytes(UTF_8))) {
+ assertNull("Is not a LFS pointer", LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadInValidLfsPointerVersionTwice() throws Exception {
+ String ptr = "version https://git-lfs.github.com/spec/v1\n"
+ + "version https://git-lfs.github.com/spec/v1\n"
+ + "oid sha256:" + TEST_SHA256 + '\n'
+ + "size 4\n";
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ ptr.getBytes(UTF_8))) {
+ assertNull("Is not a LFS pointer", LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadInValidLfsPointerVersionTwice2() throws Exception {
+ String ptr = "version https://git-lfs.github.com/spec/v1\n"
+ + "oid sha256:" + TEST_SHA256 + '\n'
+ + "version https://git-lfs.github.com/spec/v1\n"
+ + "size 4\n";
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ ptr.getBytes(UTF_8))) {
+ assertNull("Is not a LFS pointer", LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadInValidLfsPointerOidTwice() throws Exception {
+ String ptr = "version https://git-lfs.github.com/spec/v1\n"
+ + "oid sha256:" + TEST_SHA256 + '\n'
+ + "oid sha256:" + TEST_SHA256 + '\n'
+ + "size 4\n";
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ ptr.getBytes(UTF_8))) {
+ assertNull("Is not a LFS pointer", LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadInValidLfsPointerSizeTwice() throws Exception {
+ String ptr = "version https://git-lfs.github.com/spec/v1\n"
+ + "size 4\n"
+ + "size 4\n"
+ + "oid sha256:" + TEST_SHA256 + '\n';
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ ptr.getBytes(UTF_8))) {
+ assertNull("Is not a LFS pointer", LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testRoundtrip() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer ptr = new LfsPointer(id, 4);
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+ ptr.encode(baos);
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ baos.toByteArray())) {
+ assertEquals(ptr, LfsPointer.parseLfsPointer(in));
+ }
+ }
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ AnyLongObjectId id2 = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs2 = new LfsPointer(id2, 4);
+ assertTrue(lfs.equals(lfs2));
+ assertTrue(lfs2.equals(lfs));
+ }
+
+ @Test
+ public void testEqualsNull() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ assertFalse(lfs.equals(null));
+ }
+
+ @Test
+ public void testEqualsSame() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ assertTrue(lfs.equals(lfs));
+ }
+
+ @Test
+ public void testEqualsOther() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ assertFalse(lfs.equals(new Object()));
+ }
+
+ @Test
+ public void testNotEqualsOid() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ AnyLongObjectId id2 = LongObjectId
+ .fromString(TEST_SHA256.replace('7', '5'));
+ LfsPointer lfs2 = new LfsPointer(id2, 4);
+ assertFalse(lfs.equals(lfs2));
+ assertFalse(lfs2.equals(lfs));
+ }
+
+ @Test
+ public void testNotEqualsSize() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ AnyLongObjectId id2 = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs2 = new LfsPointer(id2, 5);
+ assertFalse(lfs.equals(lfs2));
+ assertFalse(lfs2.equals(lfs));
+ }
+
+ @Test
+ public void testCompareToEquals() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ AnyLongObjectId id2 = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs2 = new LfsPointer(id2, 4);
+ assertEquals(0, lfs.compareTo(lfs2));
+ assertEquals(0, lfs2.compareTo(lfs));
+ }
+
+ @Test
+ @SuppressWarnings("SelfComparison")
+ public void testCompareToSame() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ assertEquals(0, lfs.compareTo(lfs));
+ }
+
+ @Test
+ public void testCompareToNotEqualsOid() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ AnyLongObjectId id2 = LongObjectId
+ .fromString(TEST_SHA256.replace('7', '5'));
+ LfsPointer lfs2 = new LfsPointer(id2, 4);
+ assertNotEquals(0, lfs.compareTo(lfs2));
+ assertNotEquals(0, lfs2.compareTo(lfs));
+ }
+
+ @Test
+ public void testCompareToNotEqualsSize() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ AnyLongObjectId id2 = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs2 = new LfsPointer(id2, 5);
+ assertNotEquals(0, lfs.compareTo(lfs2));
+ assertNotEquals(0, lfs2.compareTo(lfs));
+ }
+
+ @Test
+ public void testCompareToNull() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ assertThrows(NullPointerException.class, () -> lfs.compareTo(null));
+ }
+
+ @Test
+ public void testHashcodeEquals() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ AnyLongObjectId id2 = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs2 = new LfsPointer(id2, 4);
+ assertEquals(lfs.hashCode(), lfs2.hashCode());
+ }
+
+ @Test
+ public void testHashcodeSame() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ assertEquals(lfs.hashCode(), lfs.hashCode());
+ }
+
+ @Test
+ public void testHashcodeNotEquals() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ AnyLongObjectId id2 = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs2 = new LfsPointer(id2, 5);
+ assertNotEquals(lfs.hashCode(), lfs2.hashCode());
+ }
}