(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func 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 | } |
nothing calls this directly
no test coverage detected