func testPackedTagDerefInfo(t *testing.T, repo Repository, spec string, oid *objects.ObjectId) { ref, err := repo.Ref(spec) util.AssertNoErr(t, err) util.AssertEqualString(t, ref.Name(), spec) // make sure target is symbolic and matches symbolic, target := ref.Target() util.Assert(t, !symbolic) if target == nil || ref.Commit() == nil { t.Fatalf("nil target or commit") } util.AssertEqualString(t, ref.Commit().String(), oid.String()) }
func assertPeeledRef(t *testing.T, peeledRef objects.Ref, oid *objects.ObjectId) { symbolic, target := peeledRef.Target() util.Assert(t, !symbolic) if target == nil { t.Fatalf("nil target") } util.AssertEqualString(t, target.(*objects.ObjectId).String(), oid.String()) util.AssertEqualString(t, peeledRef.ObjectId().String(), oid.String()) util.AssertPanic(t, func() { s := target.(string) s += "" // for compilation }) }
func testRefPathSymbolic(t *testing.T, repo Repository, spec string, tget string) { symbolicRef, err := repo.Ref(spec) util.AssertNoErr(t, err) util.AssertEqualString(t, symbolicRef.Name(), spec) // make sure target is symbolic and matches assertSymbolicRef(t, symbolicRef, tget) }
// testShortOid retrives the object by all possible combinations of // shortening its id. func testShortOid(t *testing.T, repo Repository, oid *objects.ObjectId) { rev := oid.String() for i := 4; i <= 40; i++ { o, err := ObjectFromRevision(repo, rev[:i]) util.AssertNoErr(t, err) util.AssertEqualString(t, o.ObjectId().String(), oid.String()) } }
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()) } }
func Test_OidFromString(t *testing.T) { ids := getTestOids(numTests) for _, id := range ids { oid, err := OidFromString(id) util.AssertNoErr(t, err) util.AssertEqualString(t, oid.String(), id) } }
// 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()) }
func assertSymbolicRef(t *testing.T, symbolicRef objects.Ref, tget string) { symbolic, target := symbolicRef.Target() util.Assert(t, symbolic) if target == nil { t.Fatalf("nil target") } util.AssertEqualString(t, target.(string), tget) util.AssertPanic(t, func() { oid := target.(*objects.ObjectId) oid.String() // for compilation }) util.AssertPanic(t, func() { oid := symbolicRef.ObjectId() oid.String() // for compilation }) }
func testPeelRef(t *testing.T, repo Repository, spec string, oid *objects.ObjectId) { // first peel it manually ref, err := repo.Ref(spec) util.AssertNoErr(t, err) util.AssertEqualString(t, ref.Name(), spec) peeledRef, err := PeelRef(repo, ref) util.AssertNoErr(t, err) assertPeeledRef(t, peeledRef, oid) // now, peel it automatically ref, err = PeeledRefFromSpec(repo, spec) util.AssertNoErr(t, err) peeledRef, err = PeelRef(repo, ref) util.AssertNoErr(t, err) assertPeeledRef(t, peeledRef, oid) }
// 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)) } }
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) } }
// testObjectExpected retrieves the commit with the given revision specification // from the given repository and ensures that this operation went well and the // returned object in fact has the expected oid. func testObjectExpected(t *testing.T, repo Repository, rev string, expOid *objects.ObjectId, expType objects.ObjectType) { parent, err := ObjectFromRevision(repo, rev) util.AssertNoErr(t, err) util.Assert(t, parent.Header().Type() == expType) util.AssertEqualString(t, parent.ObjectId().String(), expOid.String()) }
func testRefPathPeeled(t *testing.T, repo Repository, spec string, oid *objects.ObjectId) { ref, err := repo.Ref(spec) util.AssertNoErr(t, err) util.AssertEqualString(t, ref.Name(), spec) assertPeeledRef(t, ref, oid) }