shithub: furgit

ref: a96abc307995afc09f637c905807c0c5203ab874
dir: /object/blob_parse_test.go/

View raw version
package object_test

import (
	"bytes"
	"testing"

	"codeberg.org/lindenii/furgit/internal/testgit"
	"codeberg.org/lindenii/furgit/object"
	"codeberg.org/lindenii/furgit/objectid"
)

func TestBlobParseFromGit(t *testing.T) {
	testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) {
		testRepo := testgit.NewBareRepo(t, algo)
		body := []byte("hello\nblob\n")
		blobID := testRepo.HashObject(t, "blob", body)

		rawBody := testRepo.CatFile(t, "blob", blobID)
		blob, err := object.ParseBlob(rawBody)
		if err != nil {
			t.Fatalf("ParseBlob: %v", err)
		}
		if !bytes.Equal(blob.Data, body) {
			t.Fatalf("blob body mismatch")
		}
	})
}