delete_handler_test.go 899 B

12345678910111213141516171819202122232425262728293031
  1. package v1
  2. import (
  3. "fmt"
  4. "net/http"
  5. "net/url"
  6. "testing"
  7. "github.com/coreos/etcd/server"
  8. "github.com/coreos/etcd/tests"
  9. "github.com/coreos/etcd/third_party/github.com/stretchr/testify/assert"
  10. )
  11. // Ensures that a key is deleted.
  12. //
  13. // $ curl -X PUT localhost:4001/v1/keys/foo/bar -d value=XXX
  14. // $ curl -X DELETE localhost:4001/v1/keys/foo/bar
  15. //
  16. func TestV1DeleteKey(t *testing.T) {
  17. tests.RunServer(func(s *server.Server) {
  18. v := url.Values{}
  19. v.Set("value", "XXX")
  20. resp, err := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v1/keys/foo/bar"), v)
  21. tests.ReadBody(resp)
  22. resp, err = tests.DeleteForm(fmt.Sprintf("%s%s", s.URL(), "/v1/keys/foo/bar"), url.Values{})
  23. assert.Equal(t, resp.StatusCode, http.StatusOK)
  24. body := tests.ReadBody(resp)
  25. assert.Nil(t, err, "")
  26. assert.Equal(t, string(body), `{"action":"delete","key":"/foo/bar","prevValue":"XXX","index":4}`, "")
  27. })
  28. }