MCPcopy
hub / github.com/perkeep/perkeep / TestWriteFileMap

Function TestWriteFileMap

pkg/schema/filewriter_test.go:34–68  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

32)
33
34func TestWriteFileMap(t *testing.T) {
35 m := NewFileMap("test-file")
36 r := &randReader{seed: 123, length: 5 << 20}
37 sr := new(stats.Receiver)
38 var buf bytes.Buffer
39 br, err := WriteFileMap(ctxbg, sr, m, io.TeeReader(r, &buf))
40 if err != nil {
41 t.Fatal(err)
42 }
43 t.Logf("Got root file %v; %d blobs, %d bytes", br, sr.NumBlobs(), sr.SumBlobSize())
44 sizes := sr.Sizes()
45 t.Logf("Sizes are %v", sizes)
46
47 // TODO(bradfitz): these are fragile tests and mostly just a placeholder.
48 // Real tests to add:
49 // -- no "bytes" schema with a single "blobref"
50 // -- more seeds (including some that tickle the above)
51 // -- file reader reading back the root gets the same sha224 content back
52 // (will require keeping the full data in our stats receiver, not
53 // just the size)
54 // -- well-balanced tree
55 // -- nothing too big, nothing too small.
56 if g, w := br.String(), "sha224-4c6e23fe27b76bb61f433b5870b75828a4ab14d728333e1e201595e6"; g != w {
57 t.Errorf("root blobref = %v; want %v", g, w)
58 }
59 if g, w := sr.NumBlobs(), 84; g != w {
60 t.Errorf("num blobs = %v; want %v", g, w)
61 }
62 if g, w := sr.SumBlobSize(), int64(5253501); g != w {
63 t.Errorf("sum blob size = %v; want %v", g, w)
64 }
65 if g, w := sizes[len(sizes)-1], 262144; g != w {
66 t.Errorf("biggest blob is %d; want %d", g, w)
67 }
68}
69
70func TestWriteThenRead(t *testing.T) {
71 m := NewFileMap("test-file")

Callers

nothing calls this directly

Calls 8

NewFileMapFunction · 0.85
WriteFileMapFunction · 0.85
FatalMethod · 0.80
LogfMethod · 0.80
SizesMethod · 0.80
NumBlobsMethod · 0.45
SumBlobSizeMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected