diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-01-31 13:18:51 -0500 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-01 12:30:37 -0500 |
commit | 1a17a2cf1ee8b509dd00b7f29a01c13108acb2cc (patch) | |
tree | d6aa197560053444d76dce1bd198a584c051c7b9 /rwtransaction_test.go | |
parent | Merge pull request #4 from benbjohnson/api (diff) | |
download | dedo-1a17a2cf1ee8b509dd00b7f29a01c13108acb2cc.tar.gz dedo-1a17a2cf1ee8b509dd00b7f29a01c13108acb2cc.tar.xz |
Add RWTransaction.Put().
Diffstat (limited to 'rwtransaction_test.go')
-rw-r--r-- | rwtransaction_test.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/rwtransaction_test.go b/rwtransaction_test.go index b6e971e..4d256cc 100644 --- a/rwtransaction_test.go +++ b/rwtransaction_test.go @@ -1,6 +1,7 @@ package bolt import ( + "strings" "testing" "github.com/stretchr/testify/assert" @@ -28,3 +29,35 @@ func TestTransactionCreateBucket(t *testing.T) { assert.NoError(t, err) }) } + +// Ensure that a bucket cannot be created twice. +func TestTransactionRecreateBucket(t *testing.T) { + withOpenDB(func(db *DB, path string) { + // Create a bucket. + err := db.CreateBucket("widgets") + assert.NoError(t, err) + + // Create the same bucket again. + err = db.CreateBucket("widgets") + assert.Equal(t, err, &Error{"bucket already exists", nil}) + }) +} + +// Ensure that a bucket is created with a non-blank name. +func TestTransactionCreateBucketWithoutName(t *testing.T) { + withOpenDB(func(db *DB, path string) { + err := db.CreateBucket("") + assert.Equal(t, err, &Error{"bucket name cannot be blank", nil}) + }) +} + +// Ensure that a bucket name is not too long. +func TestTransactionCreateBucketWithLongName(t *testing.T) { + withOpenDB(func(db *DB, path string) { + err := db.CreateBucket(strings.Repeat("X", 255)) + assert.NoError(t, err) + + err = db.CreateBucket(strings.Repeat("X", 256)) + assert.Equal(t, err, &Error{"bucket name too long", nil}) + }) +} |