MCPcopy Create free account
hub / github.com/evilsocket/sum / TestIndexDeleteRecord

Function TestIndexDeleteRecord

storage/index_test.go:288–313  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

286}
287
288func TestIndexDeleteRecord(t *testing.T) {
289 setupRecords(t, true, false)
290 defer teardownRecords(t)
291
292 i := setupIndex(testFolder)
293 if err := i.Load(); err != nil {
294 t.Fatal(err)
295 }
296
297 for n := 0; n < testRecords; n++ {
298 id := uint64(n + 1)
299 if m := i.Delete(id); m == nil {
300 t.Fatalf("record with id %d not found", id)
301 } else if deleted := m.(*pb.Record); deleted.Id != id {
302 t.Fatalf("should have deleted record with id %d, id is %d instead", id, deleted.Id)
303 } else if i.Size() != testRecords-int(id) {
304 t.Fatalf("inconsistent index size of %d", i.Size())
305 } else if _, err := os.Stat(i.pathFor(deleted)); err == nil {
306 t.Fatalf("record %d data file was not deleted", deleted.Id)
307 }
308 }
309
310 if i.Size() != 0 {
311 t.Fatalf("expected empty index, found %d elements instead", i.Size())
312 }
313}
314
315func TestIndexDeleteRecordWithInvalidId(t *testing.T) {
316 setupRecords(t, false, false)

Callers

nothing calls this directly

Calls 7

setupIndexFunction · 0.85
LoadMethod · 0.80
SizeMethod · 0.80
pathForMethod · 0.80
setupRecordsFunction · 0.70
teardownRecordsFunction · 0.70
DeleteMethod · 0.45

Tested by

no test coverage detected