(t *testing.T)
| 26 | ) |
| 27 | |
| 28 | func 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, |
nothing calls this directly
no test coverage detected
searching dependent graphs…