fix(store): make NodeExtern.Value a *string

Before this change if the value of a Node was "" it would get dropped from the json
encoding and the Node.Value field would be missing. Fix this problem by making
NodeExtern.Value a *string so that an empty string will be encoded but a nil value
will drop the field.
This commit is contained in:
evan-gu
2014-02-03 20:12:36 -05:00
committed by Yifan Gu
parent a00bf38f16
commit 9cfd8c5f0b
9 changed files with 86 additions and 52 deletions

View File

@@ -329,3 +329,18 @@ func TestV2SetKeyCASWithMissingValueFails(t *testing.T) {
assert.Equal(t, body["cause"], "CompareAndSwap", "")
})
}
// Ensure that we can set an empty value
//
// $ curl -X PUT localhost:4001/v2/keys/foo/bar -d value=
//
func TestV2SetKeyCASWithEmptyValueSuccess(t *testing.T) {
tests.RunServer(func(s *server.Server) {
v := url.Values{}
v.Set("value", "")
resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
assert.Equal(t, resp.StatusCode, http.StatusCreated)
body := tests.ReadBody(resp)
assert.Equal(t, string(body), `{"action":"set","node":{"key":"/foo/bar","value":"","modifiedIndex":2,"createdIndex":2}}`)
})
}