(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestTx_RecursivelyCheckPages_MisplacedPage(t *testing.T) { |
| 16 | db := btesting.MustCreateDB(t) |
| 17 | db.ForceDisableStrictMode() |
| 18 | require.NoError(t, |
| 19 | db.Fill([]byte("data"), 1, 10000, |
| 20 | func(tx int, k int) []byte { return []byte(fmt.Sprintf("%04d", k)) }, |
| 21 | func(tx int, k int) []byte { return make([]byte, 100) }, |
| 22 | )) |
| 23 | require.NoError(t, db.Close()) |
| 24 | |
| 25 | xRay := surgeon.NewXRay(db.Path()) |
| 26 | |
| 27 | path1, err := xRay.FindPathsToKey([]byte("0451")) |
| 28 | require.NoError(t, err, "cannot find page that contains key:'0451'") |
| 29 | require.Len(t, path1, 1, "Expected only one page that contains key:'0451'") |
| 30 | |
| 31 | path2, err := xRay.FindPathsToKey([]byte("7563")) |
| 32 | require.NoError(t, err, "cannot find page that contains key:'7563'") |
| 33 | require.Len(t, path2, 1, "Expected only one page that contains key:'7563'") |
| 34 | |
| 35 | srcPage := path1[0][len(path1[0])-1] |
| 36 | targetPage := path2[0][len(path2[0])-1] |
| 37 | require.NoError(t, surgeon.CopyPage(db.Path(), srcPage, targetPage)) |
| 38 | |
| 39 | db.MustReopen() |
| 40 | db.ForceDisableStrictMode() |
| 41 | require.NoError(t, db.Update(func(tx *bolt.Tx) error { |
| 42 | // Collect all the errors. |
| 43 | var errors []error |
| 44 | for err := range tx.Check() { |
| 45 | errors = append(errors, err) |
| 46 | } |
| 47 | require.Len(t, errors, 1) |
| 48 | require.ErrorContains(t, errors[0], fmt.Sprintf("leaf page(%v) needs to be >= the key in the ancestor", targetPage)) |
| 49 | return nil |
| 50 | })) |
| 51 | require.NoError(t, db.Close()) |
| 52 | } |
| 53 | |
| 54 | func TestTx_RecursivelyCheckPages_CorruptedLeaf(t *testing.T) { |
| 55 | db := btesting.MustCreateDB(t) |
nothing calls this directly
no test coverage detected