diff options
| author | 2026-02-20 21:33:39 +0800 | |
|---|---|---|
| committer | 2026-02-20 21:51:03 +0800 | |
| commit | d26449f260cb4a02bb6949c315580ea31bc29de8 (patch) | |
| tree | 678eb4f391c9b84f712d4946115aac5e45de095c /object/commit_serialize_test.go | |
| parent | object: Add basic object code (diff) | |
| signature | No signature | |
object: Add tests
Diffstat (limited to 'object/commit_serialize_test.go')
| -rw-r--r-- | object/commit_serialize_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/object/commit_serialize_test.go b/object/commit_serialize_test.go new file mode 100644 index 00000000..3f6eb4aa --- /dev/null +++ b/object/commit_serialize_test.go @@ -0,0 +1,31 @@ +package object_test + +import ( + "testing" + + "codeberg.org/lindenii/furgit/internal/testgit" + "codeberg.org/lindenii/furgit/object" + "codeberg.org/lindenii/furgit/oid" +) + +func TestCommitSerialize(t *testing.T) { + testgit.ForEachAlgorithm(t, func(t *testing.T, algo oid.Algorithm) { + repo := testgit.NewBareRepo(t, algo) + _, _, commitID := repo.MakeCommit(t, "subject\n\nbody") + + rawBody := repo.CatFile(t, "commit", commitID) + commit, err := object.ParseCommit(rawBody, algo) + if err != nil { + t.Fatalf("ParseCommit: %v", err) + } + + rawObj, err := commit.Serialize() + if err != nil { + t.Fatalf("Serialize: %v", err) + } + gotID := algo.Sum(rawObj) + if gotID != commitID { + t.Fatalf("commit id mismatch: got %s want %s", gotID, commitID) + } + }) +} |
