MCPcopy
hub / github.com/etcd-io/bbolt / TestNode_put

Function TestNode_put

node_test.go:11–35  ·  view source on GitHub ↗

Ensure that a node can insert a key/value.

(t *testing.T)

Source from the content-addressed store, hash-verified

9
10// Ensure that a node can insert a key/value.
11func TestNode_put(t *testing.T) {
12 m := &common.Meta{}
13 m.SetPgid(1)
14 n := &node{inodes: make(common.Inodes, 0), bucket: &Bucket{tx: &Tx{meta: m}}}
15 n.put([]byte("baz"), []byte("baz"), []byte("2"), 0, 0)
16 n.put([]byte("foo"), []byte("foo"), []byte("0"), 0, 0)
17 n.put([]byte("bar"), []byte("bar"), []byte("1"), 0, 0)
18 n.put([]byte("foo"), []byte("foo"), []byte("3"), 0, common.LeafPageFlag)
19
20 if len(n.inodes) != 3 {
21 t.Fatalf("exp=3; got=%d", len(n.inodes))
22 }
23 if k, v := n.inodes[0].Key(), n.inodes[0].Value(); string(k) != "bar" || string(v) != "1" {
24 t.Fatalf("exp=<bar,1>; got=<%s,%s>", k, v)
25 }
26 if k, v := n.inodes[1].Key(), n.inodes[1].Value(); string(k) != "baz" || string(v) != "2" {
27 t.Fatalf("exp=<baz,2>; got=<%s,%s>", k, v)
28 }
29 if k, v := n.inodes[2].Key(), n.inodes[2].Value(); string(k) != "foo" || string(v) != "3" {
30 t.Fatalf("exp=<foo,3>; got=<%s,%s>", k, v)
31 }
32 if n.inodes[2].Flags() != uint32(common.LeafPageFlag) {
33 t.Fatalf("not a leaf: %d", n.inodes[2].Flags())
34 }
35}
36
37// Ensure that a node can deserialize from a leaf page.
38func TestNode_read_LeafPage(t *testing.T) {

Callers

nothing calls this directly

Calls 6

SetPgidMethod · 0.95
putMethod · 0.95
FatalfMethod · 0.65
KeyMethod · 0.45
ValueMethod · 0.45
FlagsMethod · 0.45

Tested by

no test coverage detected