From 2aae0e0e0beca49b3d9b7fb051986a425ce91643 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 24 May 2026 07:19:19 +0000 Subject: object/blob: Start --- object/blob/serialize_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 object/blob/serialize_test.go (limited to 'object/blob/serialize_test.go') 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) + } + }) +} -- cgit v1.3.1-10-gc9f91