aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2015-06-03 13:21:39 -0600
committerBen Johnson <benbjohnson@yahoo.com>2015-06-03 13:21:39 -0600
commit764b4844e99e982af55d44220e676b96ef8502c2 (patch)
tree5c242b62f17ffb41edd4e2704b41c8ad95cc900e
parentMerge pull request #383 from benbjohnson/madvise (diff)
parenttx_test: add tests for two tx.ForEach cases (diff)
downloaddedo-764b4844e99e982af55d44220e676b96ef8502c2.tar.gz
dedo-764b4844e99e982af55d44220e676b96ef8502c2.tar.xz
Merge pull request #368 from mdlayher/test_tx_foreach
tx_test: add tests for two tx.ForEach cases
-rw-r--r--tx_test.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/tx_test.go b/tx_test.go
index 39f50c4..6c8271a 100644
--- a/tx_test.go
+++ b/tx_test.go
@@ -252,6 +252,38 @@ func TestTx_DeleteBucket_NotFound(t *testing.T) {
})
}
+// Ensure that no error is returned when a tx.ForEach function does not return
+// an error.
+func TestTx_ForEach_NoError(t *testing.T) {
+ db := NewTestDB()
+ defer db.Close()
+ db.Update(func(tx *bolt.Tx) error {
+ tx.CreateBucket([]byte("widgets"))
+ tx.Bucket([]byte("widgets")).Put([]byte("foo"), []byte("bar"))
+
+ equals(t, nil, tx.ForEach(func(name []byte, b *bolt.Bucket) error {
+ return nil
+ }))
+ return nil
+ })
+}
+
+// Ensure that an error is returned when a tx.ForEach function returns an error.
+func TestTx_ForEach_WithError(t *testing.T) {
+ db := NewTestDB()
+ defer db.Close()
+ db.Update(func(tx *bolt.Tx) error {
+ tx.CreateBucket([]byte("widgets"))
+ tx.Bucket([]byte("widgets")).Put([]byte("foo"), []byte("bar"))
+
+ err := errors.New("foo")
+ equals(t, err, tx.ForEach(func(name []byte, b *bolt.Bucket) error {
+ return err
+ }))
+ return nil
+ })
+}
+
// Ensure that Tx commit handlers are called after a transaction successfully commits.
func TestTx_OnCommit(t *testing.T) {
var x int