Skip to content

Commit

Permalink
Client: fix check for WithPrefix op
Browse files Browse the repository at this point in the history
Make sure that WithPrefix correctly set the flag, and add test.
Also, add test for WithFromKey.

fixes #14056
  • Loading branch information
spzala committed Jun 29, 2022
1 parent 7a1cecd commit daaab7a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions client/v3/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ func WithPrefix() OpOption {
return func(op *Op) {
if len(op.key) == 0 {
op.key, op.end = []byte{0}, []byte{0}
op.isOptsWithPrefix = true
return
}
op.end = getPrefix(op.key)
Expand Down
24 changes: 24 additions & 0 deletions client/v3/op_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit daaab7a

Please sign in to comment.