Client: fix check for WithPrefix op

Make sure that WithPrefix correctly set the flag, and add test.
Also, add test for WithFromKey.

fixes #14056

Signed-off-by: Sahdev Zala <spzala@us.ibm.com>
This commit is contained in:
Sahdev Zala 2022-06-29 16:39:13 -04:00
parent 7a1cecd5fa
commit 8637c54bcc
2 changed files with 25 additions and 1 deletions

View File

@ -389,12 +389,12 @@ func getPrefix(key []byte) []byte {
// can return 'foo1', 'foo2', and so on. // can return 'foo1', 'foo2', and so on.
func WithPrefix() OpOption { func WithPrefix() OpOption {
return func(op *Op) { return func(op *Op) {
op.isOptsWithPrefix = true
if len(op.key) == 0 { if len(op.key) == 0 {
op.key, op.end = []byte{0}, []byte{0} op.key, op.end = []byte{0}, []byte{0}
return return
} }
op.end = getPrefix(op.key) op.end = getPrefix(op.key)
op.isOptsWithPrefix = true
} }
} }

View File

@ -75,3 +75,27 @@ func TestIsSortOptionValid(t *testing.T) {
} }
} }
} }
func TestIsOptsWithPrefix(t *testing.T) {
optswithprefix := []OpOption{WithPrefix()}
if !IsOptsWithPrefix(optswithprefix) {
t.Errorf("IsOptsWithPrefix = false, expected true")
}
optswithfromkey := []OpOption{WithFromKey()}
if IsOptsWithPrefix(optswithfromkey) {
t.Errorf("IsOptsWithPrefix = true, expected false")
}
}
func TestIsOptsWithFromKey(t *testing.T) {
optswithfromkey := []OpOption{WithFromKey()}
if !IsOptsWithFromKey(optswithfromkey) {
t.Errorf("IsOptsWithFromKey = false, expected true")
}
optswithprefix := []OpOption{WithPrefix()}
if IsOptsWithFromKey(optswithprefix) {
t.Errorf("IsOptsWithFromKey = true, expected false")
}
}