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

Function TestRevertMetaPage

internal/surgeon/surgeon_test.go:14–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestRevertMetaPage(t *testing.T) {
15 db := btesting.MustCreateDB(t)
16 assert.NoError(t,
17 db.Fill([]byte("data"), 1, 500,
18 func(tx int, k int) []byte { return []byte(fmt.Sprintf("%04d", k)) },
19 func(tx int, k int) []byte { return make([]byte, 100) },
20 ))
21 assert.NoError(t,
22 db.Update(
23 func(tx *bolt.Tx) error {
24 b := tx.Bucket([]byte("data"))
25 assert.NoError(t, b.Put([]byte("0123"), []byte("new Value for 123")))
26 assert.NoError(t, b.Put([]byte("1234b"), []byte("additional object")))
27 assert.NoError(t, b.Delete([]byte("0246")))
28 return nil
29 }))
30
31 assert.NoError(t,
32 db.View(
33 func(tx *bolt.Tx) error {
34 b := tx.Bucket([]byte("data"))
35 assert.Equal(t, []byte("new Value for 123"), b.Get([]byte("0123")))
36 assert.Equal(t, []byte("additional object"), b.Get([]byte("1234b")))
37 assert.Nil(t, b.Get([]byte("0246")))
38 return nil
39 }))
40
41 db.Close()
42
43 // This causes the whole tree to be linked to the previous state
44 assert.NoError(t, surgeon.RevertMetaPage(db.Path()))
45
46 db.MustReopen()
47 db.MustCheck()
48 assert.NoError(t,
49 db.View(
50 func(tx *bolt.Tx) error {
51 b := tx.Bucket([]byte("data"))
52 assert.Equal(t, make([]byte, 100), b.Get([]byte("0123")))
53 assert.Nil(t, b.Get([]byte("1234b")))
54 assert.Equal(t, make([]byte, 100), b.Get([]byte("0246")))
55 return nil
56 }))
57}

Callers

nothing calls this directly

Calls 13

MustCreateDBFunction · 0.92
RevertMetaPageFunction · 0.92
FillMethod · 0.80
UpdateMethod · 0.80
ViewMethod · 0.80
MustReopenMethod · 0.80
MustCheckMethod · 0.80
BucketMethod · 0.45
PutMethod · 0.45
DeleteMethod · 0.45
GetMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected