Fast implementation of Git in pure Go
at master 30 lines 762 B view raw
1package object_test 2 3import ( 4 "testing" 5 6 "codeberg.org/lindenii/furgit/internal/testgit" 7 "codeberg.org/lindenii/furgit/object" 8 "codeberg.org/lindenii/furgit/objectid" 9) 10 11func TestBlobSerialize(t *testing.T) { 12 t.Parallel() 13 testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { //nolint:thelper 14 testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) 15 body := []byte("hello\nblob\n") 16 wantID := testRepo.HashObject(t, "blob", body) 17 18 blob := &object.Blob{Data: body} 19 20 rawObj, err := blob.SerializeWithHeader() 21 if err != nil { 22 t.Fatalf("SerializeWithHeader: %v", err) 23 } 24 25 gotID := algo.Sum(rawObj) 26 if gotID != wantID { 27 t.Fatalf("object id mismatch: got %s want %s", gotID, wantID) 28 } 29 }) 30}