(t *testing.T)
| 121 | } |
| 122 | |
| 123 | func TestTx_Check_Panic(t *testing.T) { |
| 124 | bucketName := []byte("data") |
| 125 | t.Log("Creating db file.") |
| 126 | db := btesting.MustCreateDBWithOption(t, &bbolt.Options{PageSize: 4096}) |
| 127 | |
| 128 | // Each page can hold roughly 20 key/values pair, so 100 such |
| 129 | // key/value pairs will consume about 5 leaf pages. |
| 130 | err := db.Fill(bucketName, 1, 100, |
| 131 | func(tx int, k int) []byte { return []byte(fmt.Sprintf("%04d", k)) }, |
| 132 | func(tx int, k int) []byte { return make([]byte, 100) }, |
| 133 | ) |
| 134 | require.NoError(t, err) |
| 135 | |
| 136 | corruptRootPage(t, db.DB, bucketName) |
| 137 | |
| 138 | path := db.Path() |
| 139 | |
| 140 | require.NoError(t, db.Close()) |
| 141 | |
| 142 | db = btesting.MustOpenDBWithOption(t, path, &bbolt.Options{PageSize: 4096}) |
| 143 | |
| 144 | vErr := db.View(func(tx *bbolt.Tx) error { |
| 145 | errChan := tx.Check() |
| 146 | for cErr := range errChan { |
| 147 | fmt.Println("cErr", cErr) |
| 148 | return cErr |
| 149 | } |
| 150 | return nil |
| 151 | }) |
| 152 | require.Error(t, vErr) |
| 153 | require.ErrorContains(t, vErr, "has unexpected type/flags: 0") |
| 154 | |
| 155 | // Manually close the db, otherwise the PostTestCleanup will |
| 156 | // check the db again and accordingly fail the test. |
| 157 | db.MustClose() |
| 158 | } |
| 159 | |
| 160 | // corruptRandomLeafPage corrupts one random leaf page. |
| 161 | func corruptRandomLeafPageInBucket(t testing.TB, db *bbolt.DB, bucketName []byte) (victimPageId common.Pgid, validPageIds []common.Pgid) { |
nothing calls this directly
no test coverage detected