|
|
@ -5,6 +5,7 @@ import ( |
|
|
|
"testing" |
|
|
|
) |
|
|
|
|
|
|
|
// empty iterator for empty db
|
|
|
|
func TestPrefixIteratorNoMatchNil(t *testing.T) { |
|
|
|
for backend, _ := range backends { |
|
|
|
t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { |
|
|
@ -16,6 +17,7 @@ func TestPrefixIteratorNoMatchNil(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// empty iterator for db populated after iterator created
|
|
|
|
func TestPrefixIteratorNoMatch1(t *testing.T) { |
|
|
|
for backend, _ := range backends { |
|
|
|
t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { |
|
|
@ -28,24 +30,8 @@ func TestPrefixIteratorNoMatch1(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TestPrefixIteratorMatch2(t *testing.T) { |
|
|
|
for backend, _ := range backends { |
|
|
|
t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { |
|
|
|
db := newTempDB(t, backend) |
|
|
|
db.SetSync(bz("2"), bz("value_2")) |
|
|
|
itr := IteratePrefix(db, []byte("2")) |
|
|
|
|
|
|
|
checkValid(t, itr, true) |
|
|
|
checkItem(t, itr, bz("2"), bz("value_2")) |
|
|
|
checkNext(t, itr, false) |
|
|
|
|
|
|
|
// Once invalid...
|
|
|
|
checkInvalid(t, itr) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TestPrefixIteratorMatch3(t *testing.T) { |
|
|
|
// empty iterator for prefix starting above db entry
|
|
|
|
func TestPrefixIteratorNoMatch2(t *testing.T) { |
|
|
|
for backend, _ := range backends { |
|
|
|
t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { |
|
|
|
db := newTempDB(t, backend) |
|
|
@ -58,21 +44,16 @@ func TestPrefixIteratorMatch3(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Search for a/1, fail by too much Next()
|
|
|
|
func TestPrefixIteratorMatches1N(t *testing.T) { |
|
|
|
// iterator with single val for db with single val, starting from that val
|
|
|
|
func TestPrefixIteratorMatch1(t *testing.T) { |
|
|
|
for backend, _ := range backends { |
|
|
|
t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { |
|
|
|
db := newTempDB(t, backend) |
|
|
|
db.SetSync(bz("a/1"), bz("value_1")) |
|
|
|
db.SetSync(bz("a/3"), bz("value_3")) |
|
|
|
itr := IteratePrefix(db, []byte("a/")) |
|
|
|
db.SetSync(bz("2"), bz("value_2")) |
|
|
|
itr := IteratePrefix(db, bz("2")) |
|
|
|
|
|
|
|
checkValid(t, itr, true) |
|
|
|
checkItem(t, itr, bz("a/1"), bz("value_1")) |
|
|
|
checkNext(t, itr, true) |
|
|
|
checkItem(t, itr, bz("a/3"), bz("value_3")) |
|
|
|
|
|
|
|
// Bad!
|
|
|
|
checkItem(t, itr, bz("2"), bz("value_2")) |
|
|
|
checkNext(t, itr, false) |
|
|
|
|
|
|
|
// Once invalid...
|
|
|
@ -81,38 +62,22 @@ func TestPrefixIteratorMatches1N(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Search for a/2, fail by too much Next()
|
|
|
|
func TestPrefixIteratorMatches2N(t *testing.T) { |
|
|
|
// iterator with prefix iterates over everything with same prefix
|
|
|
|
func TestPrefixIteratorMatches1N(t *testing.T) { |
|
|
|
for backend, _ := range backends { |
|
|
|
t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { |
|
|
|
db := newTempDB(t, backend) |
|
|
|
db.SetSync(bz("a/1"), bz("value_1")) |
|
|
|
db.SetSync(bz("a/3"), bz("value_3")) |
|
|
|
itr := IteratePrefix(db, []byte("a/")) |
|
|
|
|
|
|
|
checkValid(t, itr, true) |
|
|
|
checkItem(t, itr, bz("a/1"), bz("value_1")) |
|
|
|
checkNext(t, itr, true) |
|
|
|
checkValid(t, itr, true) |
|
|
|
checkItem(t, itr, bz("a/3"), bz("value_3")) |
|
|
|
|
|
|
|
// Bad!
|
|
|
|
checkNext(t, itr, false) |
|
|
|
|
|
|
|
// Once invalid...
|
|
|
|
checkInvalid(t, itr) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Search for a/3, fail by too much Next()
|
|
|
|
func TestPrefixIteratorMatches3N(t *testing.T) { |
|
|
|
for backend, _ := range backends { |
|
|
|
t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { |
|
|
|
db := newTempDB(t, backend) |
|
|
|
// prefixed
|
|
|
|
db.SetSync(bz("a/1"), bz("value_1")) |
|
|
|
db.SetSync(bz("a/3"), bz("value_3")) |
|
|
|
itr := IteratePrefix(db, []byte("a/")) |
|
|
|
|
|
|
|
// not
|
|
|
|
db.SetSync(bz("b/3"), bz("value_3")) |
|
|
|
db.SetSync(bz("a-3"), bz("value_3")) |
|
|
|
db.SetSync(bz("a.3"), bz("value_3")) |
|
|
|
db.SetSync(bz("abcdefg"), bz("value_3")) |
|
|
|
itr := IteratePrefix(db, bz("a/")) |
|
|
|
|
|
|
|
checkValid(t, itr, true) |
|
|
|
checkItem(t, itr, bz("a/1"), bz("value_1")) |
|
|
@ -122,7 +87,7 @@ func TestPrefixIteratorMatches3N(t *testing.T) { |
|
|
|
// Bad!
|
|
|
|
checkNext(t, itr, false) |
|
|
|
|
|
|
|
// Once invalid...
|
|
|
|
//Once invalid...
|
|
|
|
checkInvalid(t, itr) |
|
|
|
}) |
|
|
|
} |
|
|
|