|
|
@@ -28,6 +28,64 @@ func TestV2DeleteKey(t *testing.T) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+// Ensures that a directory is deleted.
|
|
|
+//
|
|
|
+// $ curl -X PUT localhost:4001/v2/keys/foo/bar -d value=XXX
|
|
|
+// $ curl -X DELETE localhost:4001/v2/keys/foo?recursive=true
|
|
|
+//
|
|
|
+func TestV2DeleteDirectory(t *testing.T) {
|
|
|
+ tests.RunServer(func(s *server.Server) {
|
|
|
+ v := url.Values{}
|
|
|
+ v.Set("value", "XXX")
|
|
|
+ resp, err := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
+ tests.ReadBody(resp)
|
|
|
+ resp, err = tests.DeleteForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo?recursive=true"), url.Values{})
|
|
|
+ assert.Nil(t, err, "")
|
|
|
+ body := tests.ReadBodyJSON(resp)
|
|
|
+ assert.Equal(t, body["action"], "delete", "")
|
|
|
+ assert.Equal(t, body["dir"], true, "")
|
|
|
+ assert.Equal(t, body["modifiedIndex"], 2, "")
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// Ensures that a directory is deleted if the previous index matches
|
|
|
+//
|
|
|
+// $ curl -X PUT localhost:4001/v2/keys/foo/bar -d value=XXX
|
|
|
+// $ curl -X DELETE localhost:4001/v2/keys/foo?recursive=true&prevIndex=1
|
|
|
+//
|
|
|
+func TestV2DeleteDirectoryCADOnIndexSuccess(t *testing.T) {
|
|
|
+ tests.RunServer(func(s *server.Server) {
|
|
|
+ v := url.Values{}
|
|
|
+ v.Set("value", "XXX")
|
|
|
+ resp, err := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
+ tests.ReadBody(resp)
|
|
|
+ resp, err = tests.DeleteForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo?recursive=true&prevIndex=1"), url.Values{})
|
|
|
+ assert.Nil(t, err, "")
|
|
|
+ body := tests.ReadBodyJSON(resp)
|
|
|
+ assert.Equal(t, body["action"], "compareAndDelete", "")
|
|
|
+ assert.Equal(t, body["dir"], true, "")
|
|
|
+ assert.Equal(t, body["modifiedIndex"], 2, "")
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// Ensures that a directory is not deleted if the previous index does not match
|
|
|
+//
|
|
|
+// $ curl -X PUT localhost:4001/v2/keys/foo/bar -d value=XXX
|
|
|
+// $ curl -X DELETE localhost:4001/v2/keys/foo?recursive=true&prevIndex=100
|
|
|
+//
|
|
|
+func TestV2DeleteDirectoryCADOnIndexFail(t *testing.T) {
|
|
|
+ tests.RunServer(func(s *server.Server) {
|
|
|
+ v := url.Values{}
|
|
|
+ v.Set("value", "XXX")
|
|
|
+ resp, err := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
+ tests.ReadBody(resp)
|
|
|
+ resp, err = tests.DeleteForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo?recursive=true&prevIndex=100"), url.Values{})
|
|
|
+ assert.Nil(t, err, "")
|
|
|
+ body := tests.ReadBodyJSON(resp)
|
|
|
+ assert.Equal(t, body["errorCode"], 101)
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
// Ensures that a key is deleted only if the previous index matches.
|
|
|
//
|
|
|
// $ curl -X PUT localhost:4001/v2/keys/foo/bar -d value=XXX
|
|
|
@@ -60,7 +118,6 @@ func TestV2DeleteKeyCADOnIndexFail(t *testing.T) {
|
|
|
tests.ReadBody(resp)
|
|
|
resp, _ = tests.DeleteForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar?prevIndex=100"), v)
|
|
|
body := tests.ReadBodyJSON(resp)
|
|
|
- fmt.Println(body)
|
|
|
assert.Equal(t, body["errorCode"], 101)
|
|
|
})
|
|
|
}
|