diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-05 21:50:15 -0700 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-05 21:50:15 -0700 |
commit | 4820312de29f446152fce216c17a696576e89d78 (patch) | |
tree | 31e748c7f977071af779aaa42a80ff728b495da6 /db_test.go | |
parent | Add pre-alpha badge. (diff) | |
parent | Fix quick tests. (diff) | |
download | dedo-4820312de29f446152fce216c17a696576e89d78.tar.gz dedo-4820312de29f446152fce216c17a696576e89d78.tar.xz |
Merge pull request #7 from benbjohnson/delete
RWTransaction.Delete()
Diffstat (limited to 'db_test.go')
-rw-r--r-- | db_test.go | 48 |
1 files changed, 12 insertions, 36 deletions
@@ -1,14 +1,11 @@ package bolt import ( - "bytes" - "fmt" "io" "io/ioutil" "os" "syscall" "testing" - "testing/quick" "time" "unsafe" @@ -156,39 +153,18 @@ func TestDBPut(t *testing.T) { }) } -// Ensure that a bucket can write random keys and values across multiple txns. -func TestDBPutRandom(t *testing.T) { - f := func(items testKeyValuePairs) bool { - withOpenDB(func(db *DB, path string) { - db.CreateBucket("widgets") - for _, item := range items { - if len(item.Key) == 0 { - continue - } - if err := db.Put("widgets", item.Key, item.Value); err != nil { - panic("put error: " + err.Error()) - } - } - for _, item := range items { - if len(item.Key) == 0 { - continue - } - value, err := db.Get("widgets", item.Key) - if err != nil { - panic("get error: " + err.Error()) - } - if !bytes.Equal(value, []byte(item.Value)) { - // db.CopyFile("/tmp/bolt.random.db") - t.Fatalf("value mismatch:\n%x\n%x", item.Value, value) - } - } - fmt.Fprint(os.Stderr, ".") - }) - return true - } - if err := quick.Check(f, qc()); err != nil { - t.Error(err) - } +// Ensure that a bucket can delete an existing key. +func TestDBDelete(t *testing.T) { + withOpenDB(func(db *DB, path string) { + db.CreateBucket("widgets") + db.Put("widgets", []byte("foo"), []byte("bar")) + err := db.Delete("widgets", []byte("foo")) + assert.NoError(t, err) + value, err := db.Get("widgets", []byte("foo")) + if assert.NoError(t, err) { + assert.Nil(t, value) + } + }) } // withDB executes a function with a database reference. |