diff options
Diffstat (limited to 'c/cursor_test.go')
-rw-r--r-- | c/cursor_test.go | 100 |
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. |