Пример #1
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())
}
Пример #2
0
func Test_parseValidBlob(t *testing.T) {
	for _, v := range testCasesBlobs {
		tb := makeTestBlob(v)
		p := ObjectParserForString(tb)
		hdr, err := p.ParseHeader()
		util.AssertNoErr(t, err)
		util.Assert(t, hdr.Type() == objects.ObjectBlob)
		util.Assert(t, hdr.Size() == int64(len(v)))

		o, err := p.ParsePayload()
		util.AssertNoErr(t, err)
		util.Assert(t, o.Header().Type() == objects.ObjectBlob)
		util.Assert(t, o.Header().Size() == int64(len(v)))
		util.Assert(t, o.ObjectId() == nil) // wasn't set in the test scenario

		var b *objects.Blob
		util.AssertPanicFree(t, func() {
			b = o.(*objects.Blob)
		})
		util.AssertEqualString(t, string(b.Data()), v)
	}
}