func TestBucket_Delete_Large(t *testing.T) {
	withOpenDB(func(db *DB, path string) {
		db.Update(func(tx *Tx) error {
			var b, _ = tx.CreateBucket([]byte("widgets"))
			for i := 0; i < 100; i++ {
				assert.NoError(t, b.Put([]byte(strconv.Itoa(i)), []byte(strings.Repeat("*", 1024))))
			}
			return nil
		})
		db.Update(func(tx *Tx) error {
			var b = tx.Bucket([]byte("widgets"))
			for i := 0; i < 100; i++ {
				assert.NoError(t, b.Delete([]byte(strconv.Itoa(i))))
			}
			return nil
		})
		db.View(func(tx *Tx) error {
			var b = tx.Bucket([]byte("widgets"))
			for i := 0; i < 100; i++ {
				assert.Nil(t, b.Get([]byte(strconv.Itoa(i))))
			}
			return nil
		})
	})
}
Ensure that deleting a large set of keys will work correctly.
package bolt
import (
	"bytes"
	"errors"
	"fmt"
	"os"
	"strconv"
	"strings"
	"testing"
	"testing/quick"
	"github.com/stretchr/testify/assert"
)
func TestBucket_Get_NonExistent(t *testing.T) {
	withOpenDB(func(db *DB, path string) {
		db.Update(func(tx *Tx) error {
			tx.CreateBucket([]byte("widgets"))
			value := tx.Bucket([]byte("widgets")).Get([]byte("foo"))
			assert.Nil(t, value)
			return nil
		})
	})
}
func TestBucket_Get_FromNode(t *testing.T) {
	withOpenDB(func(db *DB, path string) {
		db.Update(func(tx *Tx) error {
			tx.CreateBucket([]byte("widgets"))
			b := tx.Bucket([]byte("widgets"))
			b.Put([]byte("foo"), []byte("bar"))
			value := b.Get([]byte("foo"))
			assert.Equal(t, value, []byte("bar"))
			return nil
		})
	})
}
func TestBucket_Get_IncompatibleValue(t *testing.T) {
	withOpenDB(func(db *DB, path string) {
		db.Update(func(tx *Tx) error {
			tx.CreateBucket([]byte("widgets"))
			_, err := tx.Bucket([]byte("widgets")).CreateBucket([]byte("foo"))
			assert.NoError(t, err)
			assert.Nil(t, tx.Bucket([]byte("widgets")).Get([]byte("foo")))
			return nil
		})
	})
}
func TestBucket_Put(t *testing.T) {
	withOpenDB(func(db *DB, path string) {
		db.Update(func(tx *Tx) error {
			tx.CreateBucket([]byte("widgets"))
			err := tx.Bucket([]byte("widgets")).Put([]byte("foo"), []byte("bar"))
			assert.NoError(t, err)
			value := tx.Bucket([]byte("widgets")).Get([]byte("foo"))
			assert.Equal(t, value, []byte("bar"))
			return nil
		})
	})
}
func TestBucket_Put_Repeat(t *testing.T) {
	withOpenDB(func(db *DB, path string) {
		db.Update(func(tx *Tx) error {
			tx.CreateBucket([]byte("widgets"))
			b := tx.Bucket([]byte("widgets"))
			assert.NoError(t, b.Put([]byte("foo"), []byte("bar")))
			assert.NoError(t, b.Put([]byte("foo"), []byte("baz")))
			value := tx.Bucket([]byte("widgets")).Get([]byte("foo"))
			assert.Equal(t, value, []byte("baz"))
			return nil
		})
	})
}
func TestBucket_Put_Large(t *testing.T) {
	var count = 100
	var factor = 200
	withOpenDB(func(db *DB, path string) {
		db.Update(func(tx *Tx) error {
			tx.CreateBucket([]byte("widgets"))
			b := tx.Bucket([]byte("widgets"))
			for i := 1; i < count; i++ {
				assert.NoError(t, b.Put([]byte(strings.Repeat("0", i*factor)), []byte(strings.Repeat("X", (count-i)*factor))))
			}
			return nil
		})
		db.View(func(tx *Tx) error {
			b := tx.Bucket([]byte("widgets"))
			for i := 1; i < count; i++ {
				value := b.Get([]byte(strings.Repeat("0", i*factor)))
				assert.Equal(t, []byte(strings.Repeat("X", (count-i)*factor)), value)
			}
			return nil
		})
	})
}
func TestBucket_Put_IncompatibleValue(t *testing.T) {
	withOpenDB(func(db *DB, path string) {
		db.Update(func(tx *Tx) error {
			tx.CreateBucket([]byte("widgets"))
			_, err := tx.Bucket([]byte("widgets")).CreateBucket([]byte("foo"))
			assert.NoError(t, err)
			assert.Equal(t, ErrIncompatibleValue, tx.Bucket([]byte("widgets")).Put([]byte("foo"), []byte("bar")))
			return nil
		})
	})
}
func TestBucket_Put_Closed(t *testing.T) {
	withOpenDB(func(db *DB, path string) {
		tx, _ := db.Begin(true)
		tx.CreateBucket([]byte("widgets"))
		b := tx.Bucket([]byte("widgets"))
		tx.Rollback()
		assert.Equal(t, ErrTxClosed, b.Put([]byte("foo"), []byte("bar")))
	})
}
func TestBucket_Put_ReadOnly(t *testing.T) {
	withOpenDB(func(db *DB, path string) {
		db.Update(func(tx *Tx) error {
			_, err := tx.CreateBucket([]byte("widgets"))
			assert.NoError(t, err)
			return nil
		})
		db.View(func(tx *Tx) error {
			b := tx.Bucket([]byte("widgets"))
			err := b.Put([]byte("foo"), []byte("bar"))
			assert.Equal(t, err, ErrTxNotWritable)
			return nil
		})
	})
}
func TestBucket_Delete(t *testing.T) {
	withOpenDB(func(db *DB, path string) {
		db.Update(func(tx *Tx) error {
			tx.CreateBucket([]byte("widgets"))
			tx.Bucket([]byte("widgets")).Put([]byte("foo"), []byte("bar"))
			err := tx.Bucket([]byte("widgets")).Delete([]byte("foo"))
			assert.NoError(t, err)
			value := tx.Bucket([]byte("widgets")).Get([]byte("foo"))
			assert.Nil(t, value)
			return nil
		})
	})
}