client: support PrevValue in SetOptions & DeleteOptions

This commit is contained in:
Brian Waldon 2015-01-22 16:37:53 -08:00 committed by Yicheng Qin
parent 0f31f403d1
commit 7ccf5eb476
2 changed files with 31 additions and 0 deletions

View File

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

View File

@ -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 {