diff options
Diffstat (limited to 'object/commit/append_test.go')
| -rw-r--r-- | object/commit/append_test.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/object/commit/append_test.go b/object/commit/append_test.go new file mode 100644 index 00000000..46b53c69 --- /dev/null +++ b/object/commit/append_test.go @@ -0,0 +1,34 @@ +package commit_test + +import ( + "testing" + + "codeberg.org/lindenii/furgit/internal/testgit" + "codeberg.org/lindenii/furgit/object/commit" + "codeberg.org/lindenii/furgit/object/id" +) + +func TestCommitSerialize(t *testing.T) { + t.Parallel() + testgit.ForEachAlgorithm(t, func(t *testing.T, algo id.Algorithm) { //nolint:thelper + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) + _, _, commitID := testRepo.MakeCommit(t, "subject\n\nbody") + + rawBody := testRepo.CatFile(t, "commit", commitID) + + parsed, err := commit.Parse(rawBody, algo) + if err != nil { + t.Fatalf("ParseCommit: %v", err) + } + + rawObj, err := parsed.AppendWithHeader([]byte(nil)) + if err != nil { + t.Fatalf("BytesWithHeader: %v", err) + } + + gotID := algo.Sum(rawObj) + if gotID != commitID { + t.Fatalf("commit id mismatch: got %s want %s", gotID, commitID) + } + }) +} |
