aboutsummaryrefslogtreecommitdiff
path: root/c/cursor_test.go
diff options
context:
space:
mode:
authorSteven Normore <snormore@gmail.com>2014-04-16 15:00:26 +0000
committerSteven Normore <snormore@gmail.com>2014-04-16 15:00:26 +0000
commit32937280c36f9af3755472c4e8c825ec3a9d7539 (patch)
tree22a354d16608f740369c721c059f72b49a4da4ff /c/cursor_test.go
parentbuild c/cursor and running tests (diff)
downloaddedo-32937280c36f9af3755472c4e8c825ec3a9d7539.tar.gz
dedo-32937280c36f9af3755472c4e8c825ec3a9d7539.tar.xz
wip
Diffstat (limited to 'c/cursor_test.go')
-rw-r--r--c/cursor_test.go100
1 files changed, 60 insertions, 40 deletions
diff --git a/c/cursor_test.go b/c/cursor_test.go
index 3208757..f938881 100644
--- a/c/cursor_test.go
+++ b/c/cursor_test.go
@@ -4,9 +4,9 @@ import (
"fmt"
"io/ioutil"
"os"
- "sort"
+ // "sort"
"testing"
- "testing/quick"
+ // "testing/quick"
"github.com/boltdb/bolt"
"github.com/stretchr/testify/assert"
@@ -16,44 +16,64 @@ import (
// Implement seek; binary search within the page (branch page and element page)
// Ensure that a cursor can iterate over all elements in a bucket.
-func TestIterate(t *testing.T) {
- if testing.Short() {
- t.Skip("skipping test in short mode.")
- }
-
- f := func(items testdata) bool {
- withOpenDB(func(db *bolt.DB, path string) {
- // Bulk insert all values.
- tx, _ := db.Begin(true)
- tx.CreateBucket("widgets")
- b := tx.Bucket("widgets")
- for _, item := range items {
- assert.NoError(t, b.Put(item.Key, item.Value))
- }
- assert.NoError(t, tx.Commit())
-
- // Sort test data.
- sort.Sort(items)
-
- // Iterate over all items and check consistency.
- var index = 0
- tx, _ = db.Begin(false)
- c := NewCursor(tx.Bucket("widgets"))
- for key, value := first(c); key != nil && index < len(items); key, value = next(c) {
- assert.Equal(t, key, items[index].Key)
- assert.Equal(t, value, items[index].Value)
- index++
- }
- assert.Equal(t, len(items), index)
- assert.Equal(t, len(items), index)
- tx.Rollback()
- })
- return true
- }
- if err := quick.Check(f, qconfig()); err != nil {
- t.Error(err)
- }
- fmt.Fprint(os.Stderr, "\n")
+// func TestIterate(t *testing.T) {
+// if testing.Short() {
+// t.Skip("skipping test in short mode.")
+// }
+
+// f := func(items testdata) bool {
+// withOpenDB(func(db *bolt.DB, path string) {
+// // Bulk insert all values.
+// tx, _ := db.Begin(true)
+// tx.CreateBucket("widgets")
+// b := tx.Bucket("widgets")
+// for _, item := range items {
+// assert.NoError(t, b.Put(item.Key, item.Value))
+// }
+// assert.NoError(t, tx.Commit())
+
+// // Sort test data.
+// sort.Sort(items)
+
+// // Iterate over all items and check consistency.
+// var index = 0
+// tx, _ = db.Begin(false)
+// c := NewCursor(tx.Bucket("widgets"))
+// for key, value := first(c); key != nil && index < len(items); key, value = next(c) {
+// assert.Equal(t, key, items[index].Key)
+// assert.Equal(t, value, items[index].Value)
+// index++
+// }
+// assert.Equal(t, len(items), index)
+// assert.Equal(t, len(items), index)
+// tx.Rollback()
+// })
+// return true
+// }
+// if err := quick.Check(f, qconfig()); err != nil {
+// t.Error(err)
+// }
+// fmt.Fprint(os.Stderr, "\n")
+// }
+
+func TestCursorFirst(t *testing.T) {
+ withOpenDB(func(db *bolt.DB, path string) {
+
+ // Bulk insert all values.
+ tx, _ := db.Begin(true)
+ b, _ := tx.CreateBucket([]byte("widgets"))
+ assert.NoError(t, b.Put([]byte("foo"), []byte("bar")))
+ assert.NoError(t, tx.Commit())
+
+ // Get first and check consistency
+ tx, _ = db.Begin(false)
+ c := NewCursor(tx.Bucket([]byte("widgets")))
+ key, value := first(c)
+ assert.Equal(t, key, []byte("foo"))
+ assert.Equal(t, value, []byte("bar"))
+
+ tx.Rollback()
+ })
}
// withTempPath executes a function with a database reference.