aboutsummaryrefslogtreecommitdiff
path: root/object/blob/serialize_test.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-05-24 07:19:19 +0000
committerGravatar Runxi Yu2026-05-24 07:19:19 +0000
commit2aae0e0e0beca49b3d9b7fb051986a425ce91643 (patch)
treecefb6cae76f6cd3463c4150851ac6c65b8f14e6f /object/blob/serialize_test.go
parentREFACTOR: update progress (diff)
signatureNo signature
object/blob: Start
Diffstat (limited to 'object/blob/serialize_test.go')
-rw-r--r--object/blob/serialize_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/object/blob/serialize_test.go b/object/blob/serialize_test.go
new file mode 100644
index 00000000..62a0b9a9
--- /dev/null
+++ b/object/blob/serialize_test.go
@@ -0,0 +1,30 @@
+package blob_test
+
+import (
+ "testing"
+
+ "codeberg.org/lindenii/furgit/internal/testgit"
+ "codeberg.org/lindenii/furgit/object/blob"
+ objectid "codeberg.org/lindenii/furgit/object/id"
+)
+
+func TestBlobSerialize(t *testing.T) {
+ t.Parallel()
+ testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { //nolint:thelper
+ testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true})
+ body := []byte("hello\nblob\n")
+ wantID := testRepo.HashObject(t, "blob", body)
+
+ obj := &blob.Blob{Data: body}
+
+ rawObj, err := obj.AppendWithHeader([]byte(nil))
+ if err != nil {
+ t.Fatalf("BytesWithHeader: %v", err)
+ }
+
+ gotID := algo.Sum(rawObj)
+ if gotID != wantID {
+ t.Fatalf("object id mismatch: got %s want %s", gotID, wantID)
+ }
+ })
+}