Browse Source

client: copy SetOptions onto setAction

Brian Waldon 11 years ago
parent
commit
025ee0379c
2 changed files with 28 additions and 34 deletions
  1. 18 14
      client/keys.go
  2. 10 20
      client/keys_test.go

+ 18 - 14
client/keys.go

@@ -121,10 +121,12 @@ type httpKeysAPI struct {
 
 
 func (k *httpKeysAPI) Set(ctx context.Context, key, val string, opts SetOptions) (*Response, error) {
 func (k *httpKeysAPI) Set(ctx context.Context, key, val string, opts SetOptions) (*Response, error) {
 	act := &setAction{
 	act := &setAction{
-		Prefix:  k.prefix,
-		Key:     key,
-		Value:   val,
-		Options: opts,
+		Prefix:    k.prefix,
+		Key:       key,
+		Value:     val,
+		PrevValue: opts.PrevValue,
+		PrevIndex: opts.PrevIndex,
+		PrevExist: opts.PrevExist,
 	}
 	}
 
 
 	resp, body, err := k.client.Do(ctx, act)
 	resp, body, err := k.client.Do(ctx, act)
@@ -268,24 +270,26 @@ func (w *waitAction) HTTPRequest(ep url.URL) *http.Request {
 }
 }
 
 
 type setAction struct {
 type setAction struct {
-	Prefix  string
-	Key     string
-	Value   string
-	Options SetOptions
+	Prefix    string
+	Key       string
+	Value     string
+	PrevValue string
+	PrevIndex uint64
+	PrevExist PrevExistType
 }
 }
 
 
 func (a *setAction) HTTPRequest(ep url.URL) *http.Request {
 func (a *setAction) HTTPRequest(ep url.URL) *http.Request {
 	u := v2KeysURL(ep, a.Prefix, a.Key)
 	u := v2KeysURL(ep, a.Prefix, a.Key)
 
 
 	params := u.Query()
 	params := u.Query()
-	if a.Options.PrevValue != "" {
-		params.Set("prevValue", a.Options.PrevValue)
+	if a.PrevValue != "" {
+		params.Set("prevValue", a.PrevValue)
 	}
 	}
-	if a.Options.PrevIndex != 0 {
-		params.Set("prevIndex", strconv.FormatUint(a.Options.PrevIndex, 10))
+	if a.PrevIndex != 0 {
+		params.Set("prevIndex", strconv.FormatUint(a.PrevIndex, 10))
 	}
 	}
-	if a.Options.PrevExist != PrevIgnore {
-		params.Set("prevExist", string(a.Options.PrevExist))
+	if a.PrevExist != PrevIgnore {
+		params.Set("prevExist", string(a.PrevExist))
 	}
 	}
 	u.RawQuery = params.Encode()
 	u.RawQuery = params.Encode()
 
 

+ 10 - 20
client/keys_test.go

@@ -257,10 +257,8 @@ func TestSetAction(t *testing.T) {
 		// PrevExist set, but still ignored
 		// PrevExist set, but still ignored
 		{
 		{
 			act: setAction{
 			act: setAction{
-				Key: "foo",
-				Options: SetOptions{
-					PrevExist: PrevIgnore,
-				},
+				Key:       "foo",
+				PrevExist: PrevIgnore,
 			},
 			},
 			wantURL:  "http://example.com/foo",
 			wantURL:  "http://example.com/foo",
 			wantBody: "value=",
 			wantBody: "value=",
@@ -269,10 +267,8 @@ func TestSetAction(t *testing.T) {
 		// PrevExist set to true
 		// PrevExist set to true
 		{
 		{
 			act: setAction{
 			act: setAction{
-				Key: "foo",
-				Options: SetOptions{
-					PrevExist: PrevExist,
-				},
+				Key:       "foo",
+				PrevExist: PrevExist,
 			},
 			},
 			wantURL:  "http://example.com/foo?prevExist=true",
 			wantURL:  "http://example.com/foo?prevExist=true",
 			wantBody: "value=",
 			wantBody: "value=",
@@ -281,10 +277,8 @@ func TestSetAction(t *testing.T) {
 		// PrevExist set to false
 		// PrevExist set to false
 		{
 		{
 			act: setAction{
 			act: setAction{
-				Key: "foo",
-				Options: SetOptions{
-					PrevExist: PrevNoExist,
-				},
+				Key:       "foo",
+				PrevExist: PrevNoExist,
 			},
 			},
 			wantURL:  "http://example.com/foo?prevExist=false",
 			wantURL:  "http://example.com/foo?prevExist=false",
 			wantBody: "value=",
 			wantBody: "value=",
@@ -293,10 +287,8 @@ func TestSetAction(t *testing.T) {
 		// PrevValue is urlencoded
 		// PrevValue is urlencoded
 		{
 		{
 			act: setAction{
 			act: setAction{
-				Key: "foo",
-				Options: SetOptions{
-					PrevValue: "bar baz",
-				},
+				Key:       "foo",
+				PrevValue: "bar baz",
 			},
 			},
 			wantURL:  "http://example.com/foo?prevValue=bar+baz",
 			wantURL:  "http://example.com/foo?prevValue=bar+baz",
 			wantBody: "value=",
 			wantBody: "value=",
@@ -305,10 +297,8 @@ func TestSetAction(t *testing.T) {
 		// PrevIndex is set
 		// PrevIndex is set
 		{
 		{
 			act: setAction{
 			act: setAction{
-				Key: "foo",
-				Options: SetOptions{
-					PrevIndex: uint64(12),
-				},
+				Key:       "foo",
+				PrevIndex: uint64(12),
 			},
 			},
 			wantURL:  "http://example.com/foo?prevIndex=12",
 			wantURL:  "http://example.com/foo?prevIndex=12",
 			wantBody: "value=",
 			wantBody: "value=",