Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.5] Fix Client: IsOptsWithPrefix returns false even if WithPrefix() is included #14187

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/v3/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

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 @@ -36,3 +36,27 @@ func TestOpWithSort(t *testing.T) {
t.Fatalf("expected %+v, got %+v", wreq, req)
}
}

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")
}
}