MCPcopy
hub / github.com/etcd-io/bbolt / TestTx_ForEach_WithError

Function TestTx_ForEach_WithError

tx_test.go:461–482  ·  view source on GitHub ↗

Ensure that an error is returned when a tx.ForEach function returns an error.

(t *testing.T)

Source from the content-addressed store, hash-verified

459
460// Ensure that an error is returned when a tx.ForEach function returns an error.
461func 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.
485func TestTx_OnCommit(t *testing.T) {

Callers

nothing calls this directly

Calls 7

MustCreateDBFunction · 0.92
UpdateMethod · 0.80
FatalMethod · 0.65
FatalfMethod · 0.65
CreateBucketMethod · 0.45
PutMethod · 0.45
ForEachMethod · 0.45

Tested by

no test coverage detected