diff --git a/client/v3/op.go b/client/v3/op.go index e8c0c1e08c9..5251906322c 100644 --- a/client/v3/op.go +++ b/client/v3/op.go @@ -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 } } diff --git a/client/v3/op_test.go b/client/v3/op_test.go index 762044fc5e2..7c964639cb3 100644 --- a/client/v3/op_test.go +++ b/client/v3/op_test.go @@ -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") + } +}