Merge pull request #524 from yifan-gu/remove_omitempty_on_value

remove omitempty on value
This commit is contained in:
Brandon Philips
2014-02-18 07:08:00 -08:00
9 changed files with 86 additions and 52 deletions

View File

@@ -180,7 +180,7 @@ func (r *Registry) load(name string) {
}
// Parse as a query string.
m, err := url.ParseQuery(e.Node.Value)
m, err := url.ParseQuery(*e.Node.Value)
if err != nil {
panic(fmt.Sprintf("Failed to parse peers entry: %s", name))
}

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}}`)
})
}