Exemple #1
0
func testRefRetrieval(t *testing.T, repo Repository, f func() ([]objects.Ref, error), expected []string) {
	refs, err := f()
	util.AssertNoErr(t, err)
	util.AssertEqualInt(t, len(expected), len(refs))
	for i, r := range expected {
		util.AssertEqualString(t, r, refs[i].Name())
	}
}
Exemple #2
0
// Test_readCommits will compare the commit output of
// git and ggit for a string of commits.
func Test_readTree(t *testing.T) {
	testCase := test.Tree
	repo := Open(testCase.Repo())
	info := testCase.Info().(*test.InfoTree)
	f := format.NewStrFormat()

	var (
		oid = objects.OidNow(info.TreeOid)
	)
	o, err := repo.ObjectFromOid(oid)
	util.AssertNoErr(t, err)

	// check the id
	util.Assert(t, o.ObjectId().String() == info.TreeOid)

	// check the header
	util.Assert(t, o.Header().Type() == objects.ObjectTree)
	util.AssertEqualInt(t, int(o.Header().Size()), info.TreeSize)

	// get the tree
	// now convert to a tag and check the fields
	var tree *objects.Tree
	util.AssertPanicFree(t, func() {
		tree = o.(*objects.Tree)
	})

	// check entries
	entries := tree.Entries()
	util.AssertEqualInt(t, info.N, len(entries))
	util.Assert(t, info.N > 2)

	// check a file
	file := entries[0]
	util.AssertEqualString(t, info.File1Oid, file.ObjectId().String())
	util.Assert(t, file.Mode() == objects.ModeBlob)
	// TODO: add checks for type, etc.

	// check the output
	// check the whole representation, which will catch
	// most of the other stuff
	f.Reset()
	f.Object(o)
	util.AssertEqualString(t, info.TreeRepr, f.String())
}
Exemple #3
0
// this test implements basic blob reading from
// a git repository.
func Test_readBlobs(t *testing.T) {
	testRepo := test.Blobs

	repo := Open(testRepo.Repo())
	info := testRepo.Info().(*test.InfoBlobs)

	if len(info.Blobs) < 1 {
		fmt.Println("warning: no blobs to test")
	}

	for _, detail := range info.Blobs {
		// read the blob
		oid := objects.OidNow(detail.Oid)
		o, err := repo.ObjectFromOid(oid)
		util.AssertNoErr(t, err)
		util.Assert(t, o.Header().Type() == objects.ObjectBlob)
		b := o.(*objects.Blob)
		util.AssertEqualString(t, string(b.Data()), detail.Contents)
		util.AssertEqualInt(t, int(b.Header().Size()), len(detail.Contents))
	}

}