MCPcopy Create free account
hub / github.com/libgit2/git2go / TestIndexerOutOfOrder

Function TestIndexerOutOfOrder

indexer_test.go:28–93  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func TestIndexerOutOfOrder(t *testing.T) {
29 t.Parallel()
30
31 tmpPath, err := ioutil.TempDir("", "git2go")
32 checkFatal(t, err)
33 defer os.RemoveAll(tmpPath)
34
35 var finalStats TransferProgress
36 idx, err := NewIndexer(tmpPath, nil, func(stats TransferProgress) error {
37 finalStats = stats
38 return nil
39 })
40 checkFatal(t, err)
41 defer idx.Free()
42
43 _, err = idx.Write(outOfOrderPack)
44 checkFatal(t, err)
45 oid, err := idx.Commit()
46 checkFatal(t, err)
47
48 // The packfile contains the hash as the last 20 bytes.
49 expectedOid := NewOidFromBytes(outOfOrderPack[len(outOfOrderPack)-20:])
50 if !expectedOid.Equal(oid) {
51 t.Errorf("mismatched packfile hash, expected %v, got %v", expectedOid, oid)
52 }
53 if finalStats.TotalObjects != 3 {
54 t.Errorf("mismatched transferred objects, expected 3, got %v", finalStats.TotalObjects)
55 }
56 if finalStats.ReceivedObjects != 3 {
57 t.Errorf("mismatched received objects, expected 3, got %v", finalStats.ReceivedObjects)
58 }
59 if finalStats.IndexedObjects != 3 {
60 t.Errorf("mismatched indexed objects, expected 3, got %v", finalStats.IndexedObjects)
61 }
62
63 odb, err := NewOdb()
64 checkFatal(t, err)
65 defer odb.Free()
66
67 backend, err := NewOdbBackendOnePack(path.Join(tmpPath, fmt.Sprintf("pack-%s.idx", oid.String())))
68 checkFatal(t, err)
69 // Transfer the ownership of the backend to the odb, no freeing needed.
70 err = odb.AddBackend(backend, 1)
71 checkFatal(t, err)
72
73 packfileObjects := 0
74 err = odb.ForEach(func(id *Oid) error {
75 packfileObjects += 1
76 return nil
77 })
78 checkFatal(t, err)
79 if packfileObjects != 3 {
80 t.Errorf("mismatched packfile objects, expected 3, got %v", packfileObjects)
81 }
82
83 // Inspect one of the well-known objects in the packfile.
84 obj, err := odb.Read(NewOidFromBytes([]byte{
85 0x19, 0x10, 0x28, 0x15, 0x66, 0x3d, 0x23, 0xf8, 0xb7, 0x5a, 0x47, 0xe7,

Callers

nothing calls this directly

Calls 15

FreeMethod · 0.95
WriteMethod · 0.95
CommitMethod · 0.95
FreeMethod · 0.95
AddBackendMethod · 0.95
ForEachMethod · 0.95
ReadMethod · 0.95
checkFatalFunction · 0.85
NewIndexerFunction · 0.85
NewOidFromBytesFunction · 0.85
NewOdbFunction · 0.85
NewOdbBackendOnePackFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…