MCPcopy
hub / github.com/perkeep/perkeep / testPack

Function testPack

pkg/blobserver/blobpacked/blobpacked_test.go:577–732  ·  view source on GitHub ↗
(t *testing.T,
	write func(sto blobserver.Storage) error,
	checks ...func(*packTest),
)

Source from the content-addressed store, hash-verified

575}
576
577func testPack(t *testing.T,
578 write func(sto blobserver.Storage) error,
579 checks ...func(*packTest),
580) *packTest {
581 ctx, cancel := context.WithCancel(context.TODO())
582 defer cancel()
583
584 logical := new(test.Fetcher)
585 small, large := new(test.Fetcher), new(test.Fetcher)
586 pt := &packTest{
587 logical: logical,
588 small: small,
589 large: large,
590 }
591 // Figure out the logical baseline blobs we'll later expect in the packed storage.
592 if err := write(logical); err != nil {
593 t.Fatal(err)
594 }
595 t.Logf("items in logical storage: %d", logical.NumBlobs())
596
597 pt.sto = &storage{
598 small: small,
599 large: large,
600 meta: sorted.NewMemoryKeyValue(),
601 log: test.NewLogger(t, "blobpacked: "),
602 }
603 pt.sto.init()
604
605 for _, setOpt := range checks {
606 setOpt(pt)
607 }
608
609 if err := write(pt.sto); err != nil {
610 t.Fatal(err)
611 }
612
613 t.Logf("items in small: %v", small.NumBlobs())
614 t.Logf("items in large: %v", large.NumBlobs())
615
616 if want, ok := pt.wantLargeBlobs.(int); ok && want != large.NumBlobs() {
617 t.Fatalf("num large blobs = %d; want %d", large.NumBlobs(), want)
618 }
619 if want, ok := pt.wantSmallBlobs.(int); ok && want != small.NumBlobs() {
620 t.Fatalf("num small blobs = %d; want %d", small.NumBlobs(), want)
621 }
622
623 var zipRefs []blob.Ref
624 var zipSeen = map[blob.Ref]bool{}
625 blobserver.EnumerateAll(ctx, large, func(sb blob.SizedRef) error {
626 zipRefs = append(zipRefs, sb.Ref)
627 zipSeen[sb.Ref] = true
628 return nil
629 })
630 if len(zipRefs) != large.NumBlobs() {
631 t.Fatalf("Enumerated only %d zip files; expected %d", len(zipRefs), large.NumBlobs())
632 }
633
634 bytesOfZip := map[blob.Ref][]byte{}

Callers 6

TestPackNormalFunction · 0.85
TestPackNoDeleteFunction · 0.85
TestPackLargeFunction · 0.85
TestReindexFunction · 0.85
TestForeachZipBlobFunction · 0.85

Calls 15

NewMemoryKeyValueFunction · 0.92
NewLoggerFunction · 0.92
EnumerateAllFunction · 0.92
parseMetaRowFunction · 0.85
FatalMethod · 0.80
LogfMethod · 0.80
initMethod · 0.80
ReadAllMethod · 0.80
FatalfMethod · 0.65
FetchMethod · 0.65
CloseMethod · 0.65
OpenMethod · 0.65

Tested by

no test coverage detected