Merge pull request #1164 from jonboulle/1164_dirs

Unable to create directories
release-2.0
Jonathan Boulle 2014-09-24 17:16:04 -07:00
commit db3afb18df
2 changed files with 38 additions and 2 deletions

View File

@ -188,7 +188,7 @@ func parseRequest(r *http.Request, id int64) (etcdserverpb.Request, error) {
}
}
var rec, sort, wait, stream bool
var rec, sort, wait, dir, stream bool
if rec, err = getBool(r.Form, "recursive"); err != nil {
return emptyReq, etcdErr.NewRequestError(
etcdErr.EcodeInvalidField,
@ -207,6 +207,13 @@ func parseRequest(r *http.Request, id int64) (etcdserverpb.Request, error) {
`invalid value for "wait"`,
)
}
// TODO(jonboulle): define what parameters dir is/isn't compatible with?
if dir, err = getBool(r.Form, "dir"); err != nil {
return emptyReq, etcdErr.NewRequestError(
etcdErr.EcodeInvalidField,
`invalid value for "dir"`,
)
}
if stream, err = getBool(r.Form, "stream"); err != nil {
return emptyReq, etcdErr.NewRequestError(
etcdErr.EcodeInvalidField,
@ -247,6 +254,7 @@ func parseRequest(r *http.Request, id int64) (etcdserverpb.Request, error) {
Method: r.Method,
Path: p,
Val: r.FormValue("value"),
Dir: dir,
PrevValue: pV,
PrevIndex: pIdx,
PrevExist: pe,

View File

@ -102,7 +102,7 @@ func TestBadParseRequest(t *testing.T) {
mustNewForm(t, "foo", url.Values{"ttl": []string{"-1"}}),
etcdErr.EcodeTTLNaN,
},
// bad values for recursive, sorted, wait, prevExist, stream
// bad values for recursive, sorted, wait, prevExist, dir, stream
{
mustNewForm(t, "foo", url.Values{"recursive": []string{"hahaha"}}),
etcdErr.EcodeInvalidField,
@ -139,6 +139,14 @@ func TestBadParseRequest(t *testing.T) {
mustNewForm(t, "foo", url.Values{"prevExist": []string{"#2"}}),
etcdErr.EcodeInvalidField,
},
{
mustNewForm(t, "foo", url.Values{"dir": []string{"no"}}),
etcdErr.EcodeInvalidField,
},
{
mustNewForm(t, "foo", url.Values{"dir": []string{"file"}}),
etcdErr.EcodeInvalidField,
},
{
mustNewForm(t, "foo", url.Values{"stream": []string{"zzz"}}),
etcdErr.EcodeInvalidField,
@ -305,6 +313,26 @@ func TestGoodParseRequest(t *testing.T) {
Expiration: 0,
},
},
{
// dir specified
mustNewRequest(t, "foo?dir=true"),
etcdserverpb.Request{
Id: 1234,
Method: "GET",
Dir: true,
Path: "/foo",
},
},
{
// dir specified negatively
mustNewRequest(t, "foo?dir=false"),
etcdserverpb.Request{
Id: 1234,
Method: "GET",
Dir: false,
Path: "/foo",
},
},
{
// prevExist should be non-null if specified
mustNewForm(