From 7ccf5eb4760950233d0581131d89c78365467dca Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Thu, 22 Jan 2015 16:37:53 -0800 Subject: [PATCH] client: support PrevValue in SetOptions & DeleteOptions --- client/keys.go | 8 ++++++++ client/keys_test.go | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/client/keys.go b/client/keys.go index 86f89035f..758b1c9fe 100644 --- a/client/keys.go +++ b/client/keys.go @@ -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") } diff --git a/client/keys_test.go b/client/keys_test.go index 7f901a532..034566b6b 100644 --- a/client/keys_test.go +++ b/client/keys_test.go @@ -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 {