mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
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:
parent
7a1cecd5fa
commit
8637c54bcc
@ -389,12 +389,12 @@ func getPrefix(key []byte) []byte {
|
||||
// can return 'foo1', 'foo2', and so on.
|
||||
func WithPrefix() OpOption {
|
||||
return func(op *Op) {
|
||||
op.isOptsWithPrefix = true
|
||||
if len(op.key) == 0 {
|
||||
op.key, op.end = []byte{0}, []byte{0}
|
||||
return
|
||||
}
|
||||
op.end = getPrefix(op.key)
|
||||
op.isOptsWithPrefix = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user