| 105 | } |
| 106 | |
| 107 | func newTestStorage(t *testing.T, packs ...pack) (s *storage, clean func()) { |
| 108 | restoreLogging := test.TLog(t) |
| 109 | dir := t.TempDir() |
| 110 | |
| 111 | for i, p := range packs { |
| 112 | writePack(t, dir, i, p) |
| 113 | } |
| 114 | |
| 115 | ctx, cancel := context.WithCancel(context.Background()) |
| 116 | err := Reindex(ctx, dir, true, nil) |
| 117 | cancel() |
| 118 | if err != nil { |
| 119 | t.Fatalf("Reindexing after writing pack files: %v", err) |
| 120 | } |
| 121 | s, err = newStorage(dir, 0, nil) |
| 122 | if err != nil { |
| 123 | t.Fatal(err) |
| 124 | } |
| 125 | |
| 126 | clean = func() { |
| 127 | s.Close() |
| 128 | restoreLogging() |
| 129 | } |
| 130 | return s, clean |
| 131 | } |
| 132 | |
| 133 | // It verifies the size and hash of each |
| 134 | // before returning and fails the test if any of the checks fail. It |