mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
We weren't checking for PrevNode being nil in the v1 code path. Do this and add a test. Fixes #557
30 lines
746 B
Go
30 lines
746 B
Go
package v2
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/coreos/etcd/server"
|
|
"github.com/coreos/etcd/tests"
|
|
"github.com/coreos/etcd/third_party/github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// Ensures that a key is set to a given value.
|
|
//
|
|
// $ curl -X PUT localhost:4001/v1/keys/foo/bar -d value=XXX
|
|
//
|
|
func TestV1SetKey(t *testing.T) {
|
|
tests.RunServer(func(s *server.Server) {
|
|
v := url.Values{}
|
|
v.Set("value", "XXX")
|
|
resp, err := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v1/keys/foo/bar"), v)
|
|
assert.Equal(t, resp.StatusCode, http.StatusOK)
|
|
body := tests.ReadBody(resp)
|
|
assert.Nil(t, err, "")
|
|
|
|
assert.Equal(t, string(body), `{"action":"set","key":"/foo/bar","value":"XXX","newKey":true,"index":2}`, "")
|
|
})
|
|
}
|