diff options
author | Martin Kobetic <mkobetic@gmail.com> | 2014-04-11 18:02:39 -0400 |
---|---|---|
committer | Steven Normore <snormore@gmail.com> | 2014-04-16 13:27:48 +0000 |
commit | fd4263d944f1e0bfef22c3f7a042c80d1a54972d (patch) | |
tree | b54450e437fe1ee321a0db6d4b39b20a1181b3ac /c/cursor_test.go | |
parent | Merge pull request #130 from benbjohnson/create-bucket-api (diff) | |
download | dedo-fd4263d944f1e0bfef22c3f7a042c80d1a54972d.tar.gz dedo-fd4263d944f1e0bfef22c3f7a042c80d1a54972d.tar.xz |
first draft
Diffstat (limited to 'c/cursor_test.go')
-rw-r--r-- | c/cursor_test.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/c/cursor_test.go b/c/cursor_test.go new file mode 100644 index 0000000..7c45346 --- /dev/null +++ b/c/cursor_test.go @@ -0,0 +1,55 @@ +package c + +import "C" +import ( + "github.com/boltdb/bolt" + "github.com/stretchr/testify/assert" + "testing" + "testing/quick" +) + +// 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 *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) + var k, v C.bolt_val + c := NewCursor(tx.Bucket("widgets")) + C.bolt_cursor_first(c, &k, &v) + key := C.GoBytes(k.data, k.size) + for key != nil && index < len(items) { + assert.Equal(t, key, items[index].Key) + assert.Equal(t, C.GoBytes(v.data, v.size), items[index].Value) + index++ + C.bolt_cursor_next(c, &k, &v) + key := C.GoBytes(k.data, k.size) + } + 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") +} |