Ensure that an error is returned when a tx.ForEach function returns an error.
(t *testing.T)
| 459 | |
| 460 | // Ensure that an error is returned when a tx.ForEach function returns an error. |
| 461 | func TestTx_ForEach_WithError(t *testing.T) { |
| 462 | db := btesting.MustCreateDB(t) |
| 463 | if err := db.Update(func(tx *bolt.Tx) error { |
| 464 | b, err := tx.CreateBucket([]byte("widgets")) |
| 465 | if err != nil { |
| 466 | t.Fatal(err) |
| 467 | } |
| 468 | if err := b.Put([]byte("foo"), []byte("bar")); err != nil { |
| 469 | t.Fatal(err) |
| 470 | } |
| 471 | |
| 472 | marker := errors.New("marker") |
| 473 | if err := tx.ForEach(func(name []byte, b *bolt.Bucket) error { |
| 474 | return marker |
| 475 | }); err != marker { |
| 476 | t.Fatalf("unexpected error: %s", err) |
| 477 | } |
| 478 | return nil |
| 479 | }); err != nil { |
| 480 | t.Fatal(err) |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | // Ensure that Tx commit handlers are called after a transaction successfully commits. |
| 485 | func TestTx_OnCommit(t *testing.T) { |
nothing calls this directly
no test coverage detected