MCPcopy
hub / github.com/perkeep/perkeep / TestBuffer

Function TestBuffer

pkg/sorted/buffer/buffer_test.go:28–85  ·  view source on GitHub ↗

TODO(adg): test batch mutations TODO(adg): test auto-flush behavior

(t *testing.T)

Source from the content-addressed store, hash-verified

26// TODO(adg): test auto-flush behavior
27
28func TestBuffer(t *testing.T) {
29 var (
30 toBack = []mod{
31 {false, "b", "b1"},
32 {false, "d", "d1"},
33 {false, "f", "f1"},
34 }
35 toBuf = []mod{
36 {false, "a", "a2"},
37 {false, "b", "b2"},
38 {false, "c", "c2"},
39 {false, "e", "e2"},
40 {true, "f", ""},
41 {false, "g", "g2"},
42 }
43 backBeforeFlush = []mod{
44 {false, "b", "b1"},
45 {false, "d", "d1"},
46 // f deleted
47 }
48 want = []mod{
49 {false, "a", "a2"},
50 {false, "b", "b2"},
51 {false, "c", "c2"},
52 {false, "d", "d1"},
53 {false, "e", "e2"},
54 // f deleted
55 {false, "g", "g2"},
56 }
57 )
58
59 // Populate backing storage.
60 backing := sorted.NewMemoryKeyValue()
61 for _, m := range toBack {
62 backing.Set(m.key, m.value)
63 }
64 // Wrap with buffered storage, populate.
65 buf := New(sorted.NewMemoryKeyValue(), backing, 1<<20)
66 for _, m := range toBuf {
67 if m.isDelete {
68 buf.Delete(m.key)
69 } else {
70 buf.Set(m.key, m.value)
71 }
72 }
73
74 // Check contents of buffered storage.
75 check(t, buf, "buffered", want)
76 check(t, backing, "backing before flush", backBeforeFlush)
77
78 // Flush.
79 if err := buf.Flush(); err != nil {
80 t.Fatal("flush error: ", err)
81 }
82
83 // Check contents of backing storage.
84 check(t, backing, "backing after flush", want)
85}

Callers

nothing calls this directly

Calls 7

NewMemoryKeyValueFunction · 0.92
FatalMethod · 0.80
NewFunction · 0.70
checkFunction · 0.70
SetMethod · 0.65
DeleteMethod · 0.65
FlushMethod · 0.45

Tested by

no test coverage detected