From d26449f260cb4a02bb6949c315580ea31bc29de8 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Fri, 20 Feb 2026 21:33:39 +0800 Subject: object: Add tests --- object/blob_serialize_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 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..f0895556 --- /dev/null +++ b/object/blob_serialize_test.go @@ -0,0 +1,27 @@ +package object_test + +import ( + "testing" + + "codeberg.org/lindenii/furgit/internal/testgit" + "codeberg.org/lindenii/furgit/object" + "codeberg.org/lindenii/furgit/oid" +) + +func TestBlobSerialize(t *testing.T) { + testgit.ForEachAlgorithm(t, func(t *testing.T, algo oid.Algorithm) { + repo := testgit.NewBareRepo(t, algo) + body := []byte("hello\nblob\n") + wantID := repo.HashObject(t, "blob", body) + + blob := &object.Blob{Data: body} + rawObj, err := blob.Serialize() + if err != nil { + t.Fatalf("Serialize: %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