kvdb/test: fix cursor tests to match bbolt semantics
From bbolt docs: // Seek positions the cursor at the passed seek key. If the key does not exist, // the cursor is moved to the next key after seek. Returns the new pair.
This commit is contained in:
parent
84490466be
commit
f592375d1b
@ -96,11 +96,6 @@ func (c *readWriteCursor) Prev() (key, value []byte) {
|
|||||||
// not exist, the cursor is moved to the next key after seek. Returns
|
// not exist, the cursor is moved to the next key after seek. Returns
|
||||||
// the new pair.
|
// the new pair.
|
||||||
func (c *readWriteCursor) Seek(seek []byte) (key, value []byte) {
|
func (c *readWriteCursor) Seek(seek []byte) (key, value []byte) {
|
||||||
// Return nil if trying to seek to an empty key.
|
|
||||||
if seek == nil {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Seek to the first key with prefix + seek. If that key is not present
|
// Seek to the first key with prefix + seek. If that key is not present
|
||||||
// STM will seek to the next matching key with prefix.
|
// STM will seek to the next matching key with prefix.
|
||||||
kv, err := c.bucket.tx.stm.Seek(c.prefix, c.prefix+string(seek))
|
kv, err := c.bucket.tx.stm.Seek(c.prefix, c.prefix+string(seek))
|
||||||
|
@ -99,8 +99,8 @@ func testReadCursorNonEmptyInterval(t *testing.T, db walletdb.DB) {
|
|||||||
|
|
||||||
// Seek to nonexisting key.
|
// Seek to nonexisting key.
|
||||||
k, v = cursor.Seek(nil)
|
k, v = cursor.Seek(nil)
|
||||||
require.Nil(t, k)
|
require.Equal(t, "b", string(k))
|
||||||
require.Nil(t, v)
|
require.Equal(t, "1", string(v))
|
||||||
|
|
||||||
k, v = cursor.Seek([]byte("x"))
|
k, v = cursor.Seek([]byte("x"))
|
||||||
require.Nil(t, k)
|
require.Nil(t, k)
|
||||||
@ -113,7 +113,6 @@ func testReadCursorNonEmptyInterval(t *testing.T, db walletdb.DB) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testReadWriteCursor(t *testing.T, db walletdb.DB) {
|
func testReadWriteCursor(t *testing.T, db walletdb.DB) {
|
||||||
|
|
||||||
testKeyValues := []KV{
|
testKeyValues := []KV{
|
||||||
{"b", "1"},
|
{"b", "1"},
|
||||||
{"c", "2"},
|
{"c", "2"},
|
||||||
|
Loading…
Reference in New Issue
Block a user