Remove leading slash from handlers.

This commit is contained in:
Ben Johnson 2013-11-04 14:36:20 -07:00
parent 35d9719707
commit d3bfc49b7c
9 changed files with 56 additions and 10 deletions

View File

@ -8,7 +8,7 @@ import (
// Removes a key from the store.
func DeleteKeyHandler(w http.ResponseWriter, req *http.Request, s Server) error {
vars := mux.Vars(req)
key := "/" + vars["key"]
key := vars["key"]
c := s.Store().CommandFactory().CreateDeleteCommand(key, false)
return s.Dispatch(c, w, req)
}

View File

@ -10,7 +10,7 @@ import (
// Retrieves the value for a given key.
func GetKeyHandler(w http.ResponseWriter, req *http.Request, s Server) error {
vars := mux.Vars(req)
key := "/" + vars["key"]
key := vars["key"]
// Retrieve the key from the store.
event, err := s.Store().Get(key, false, false, s.CommitIndex(), s.Term())

View File

@ -12,7 +12,7 @@ import (
// Sets the value for a given key.
func SetKeyHandler(w http.ResponseWriter, req *http.Request, s Server) error {
vars := mux.Vars(req)
key := "/" + vars["key"]
key := vars["key"]
req.ParseForm()

View File

@ -14,7 +14,7 @@ import (
func WatchKeyHandler(w http.ResponseWriter, req *http.Request, s Server) error {
var err error
vars := mux.Vars(req)
key := "/" + vars["key"]
key := vars["key"]
// Create a command to watch from a given index (default 0).
var sinceIndex uint64 = 0

View File

@ -8,7 +8,7 @@ import (
func DeleteHandler(w http.ResponseWriter, req *http.Request, s Server) error {
vars := mux.Vars(req)
key := "/" + vars["key"]
key := vars["key"]
recursive := (req.FormValue("recursive") == "true")
c := s.Store().CommandFactory().CreateDeleteCommand(key, recursive)

View File

@ -18,7 +18,7 @@ func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error {
var event *store.Event
vars := mux.Vars(req)
key := "/" + vars["key"]
key := vars["key"]
// Help client to redirect the request to the current leader
if req.FormValue("consistent") == "true" && s.State() != raft.Leader {

View File

@ -10,7 +10,7 @@ import (
func PostHandler(w http.ResponseWriter, req *http.Request, s Server) error {
vars := mux.Vars(req)
key := "/" + vars["key"]
key := vars["key"]
value := req.FormValue("value")
expireTime, err := store.TTL(req.FormValue("ttl"))

View File

@ -15,7 +15,7 @@ func PutHandler(w http.ResponseWriter, req *http.Request, s Server) error {
var c raft.Command
vars := mux.Vars(req)
key := "/" + vars["key"]
key := vars["key"]
req.ParseForm()

View File

@ -14,7 +14,53 @@ import (
)
// Ensure that we can start a v2 node from the log of a v1 node.
func TestV1Migration(t *testing.T) {
func TestV1SoloMigration(t *testing.T) {
path, _ := ioutil.TempDir("", "etcd-")
os.MkdirAll(path, 0777)
defer os.RemoveAll(path)
nodepath := filepath.Join(path, "node0")
fixturepath, _ := filepath.Abs("../fixtures/v1.solo/node0")
// Copy over fixture files.
c := exec.Command("cp", "-rf", fixturepath, nodepath)
if out, err := c.CombinedOutput(); err != nil {
fmt.Println(">>>>>>\n", string(out), "<<<<<<")
panic("Fixture initialization error:" + err.Error())
}
procAttr := new(os.ProcAttr)
procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
args := []string{"etcd", fmt.Sprintf("-d=%s", nodepath)}
args = append(args, "-c", "127.0.0.1:4001")
args = append(args, "-s", "127.0.0.1:7001")
process, err := os.StartProcess(EtcdBinPath, args, procAttr)
if err != nil {
t.Fatal("start process failed:" + err.Error())
return
}
defer process.Kill()
time.Sleep(time.Second)
time.Sleep(120 * time.Second)
// Ensure deleted message is removed.
resp, err := tests.Get("http://localhost:4001/v2/keys/message")
tests.ReadBody(resp)
assert.Nil(t, err, "")
assert.Equal(t, resp.StatusCode, 404, "")
// Ensure TTL'd message is removed.
resp, err = tests.Get("http://localhost:4001/v2/keys/foo")
tests.ReadBody(resp)
assert.Nil(t, err, "")
assert.Equal(t, resp.StatusCode, 404, "")
}
// Ensure that we can start a v2 cluster from the logs of a v1 cluster.
func TestV1ClusterMigration(t *testing.T) {
path, _ := ioutil.TempDir("", "etcd-")
os.RemoveAll(path)
defer os.RemoveAll(path)
@ -22,7 +68,7 @@ func TestV1Migration(t *testing.T) {
nodes := []string{"node0", "node2"}
for i, node := range nodes {
nodepath := filepath.Join(path, node)
fixturepath, _ := filepath.Abs(filepath.Join("../fixtures/v1/", node))
fixturepath, _ := filepath.Abs(filepath.Join("../fixtures/v1.cluster/", node))
fmt.Println("FIXPATH =", fixturepath)
fmt.Println("NODEPATH =", nodepath)
os.MkdirAll(filepath.Dir(nodepath), 0777)