Ensure that a cursor can iterate over an empty bucket without error.
(t *testing.T)
| 362 | |
| 363 | // Ensure that a cursor can iterate over an empty bucket without error. |
| 364 | func TestCursor_EmptyBucket(t *testing.T) { |
| 365 | db := btesting.MustCreateDB(t) |
| 366 | if err := db.Update(func(tx *bolt.Tx) error { |
| 367 | _, err := tx.CreateBucket([]byte("widgets")) |
| 368 | return err |
| 369 | }); err != nil { |
| 370 | t.Fatal(err) |
| 371 | } |
| 372 | |
| 373 | if err := db.View(func(tx *bolt.Tx) error { |
| 374 | c := tx.Bucket([]byte("widgets")).Cursor() |
| 375 | k, v := c.First() |
| 376 | if k != nil { |
| 377 | t.Fatalf("unexpected key: %v", k) |
| 378 | } else if v != nil { |
| 379 | t.Fatalf("unexpected value: %v", v) |
| 380 | } |
| 381 | return nil |
| 382 | }); err != nil { |
| 383 | t.Fatal(err) |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | // Ensure that a Tx cursor can reverse iterate over an empty bucket without error. |
| 388 | func TestCursor_EmptyBucketReverse(t *testing.T) { |
nothing calls this directly
no test coverage detected