mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
client: support PrevValue in SetOptions & DeleteOptions
This commit is contained in:
parent
0f31f403d1
commit
7ccf5eb476
@ -75,10 +75,12 @@ type KeysAPI interface {
|
||||
}
|
||||
|
||||
type SetOptions struct {
|
||||
PrevValue string
|
||||
PrevExist PrevExistType
|
||||
}
|
||||
|
||||
type DeleteOptions struct {
|
||||
PrevValue string
|
||||
Recursive bool
|
||||
}
|
||||
|
||||
@ -282,6 +284,9 @@ func (a *setAction) HTTPRequest(ep url.URL) *http.Request {
|
||||
u := v2KeysURL(ep, a.Prefix, a.Key)
|
||||
|
||||
params := u.Query()
|
||||
if a.Options.PrevValue != "" {
|
||||
params.Set("prevValue", a.Options.PrevValue)
|
||||
}
|
||||
if a.Options.PrevExist != PrevIgnore {
|
||||
params.Set("prevExist", string(a.Options.PrevExist))
|
||||
}
|
||||
@ -308,6 +313,9 @@ func (a *deleteAction) HTTPRequest(ep url.URL) *http.Request {
|
||||
u := v2KeysURL(ep, a.Prefix, a.Key)
|
||||
|
||||
params := u.Query()
|
||||
if a.Options.PrevValue != "" {
|
||||
params.Set("prevValue", a.Options.PrevValue)
|
||||
}
|
||||
if a.Options.Recursive {
|
||||
params.Set("recursive", "true")
|
||||
}
|
||||
|
@ -289,6 +289,18 @@ func TestSetAction(t *testing.T) {
|
||||
wantURL: "http://example.com/foo?prevExist=false",
|
||||
wantBody: "value=",
|
||||
},
|
||||
|
||||
// PrevValue is urlencoded
|
||||
{
|
||||
act: setAction{
|
||||
Key: "foo",
|
||||
Options: SetOptions{
|
||||
PrevValue: "bar baz",
|
||||
},
|
||||
},
|
||||
wantURL: "http://example.com/foo?prevValue=bar+baz",
|
||||
wantBody: "value=",
|
||||
},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
@ -375,6 +387,17 @@ func TestDeleteAction(t *testing.T) {
|
||||
},
|
||||
wantURL: "http://example.com/foo?recursive=true",
|
||||
},
|
||||
|
||||
// PrevValue is urlencoded
|
||||
{
|
||||
act: deleteAction{
|
||||
Key: "foo",
|
||||
Options: DeleteOptions{
|
||||
PrevValue: "bar baz",
|
||||
},
|
||||
},
|
||||
wantURL: "http://example.com/foo?prevValue=bar+baz",
|
||||
},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
|
Loading…
x
Reference in New Issue
Block a user