|
@@ -19,10 +19,10 @@ func TestV2SetKey(t *testing.T) {
|
|
|
tests.RunServer(func(s *server.Server) {
|
|
tests.RunServer(func(s *server.Server) {
|
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
|
v.Set("value", "XXX")
|
|
v.Set("value", "XXX")
|
|
|
- resp, err := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, err := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
body := tests.ReadBody(resp)
|
|
body := tests.ReadBody(resp)
|
|
|
assert.Nil(t, err, "")
|
|
assert.Nil(t, err, "")
|
|
|
- assert.Equal(t, string(body), `{"action":"set","node":{"key":"/foo/bar","value":"XXX","modifiedIndex":1,"createdIndex":1}}`, "")
|
|
|
|
|
|
|
+ assert.Equal(t, string(body), `{"action":"set","node":{"key":"/foo/bar","value":"XXX","modifiedIndex":2,"createdIndex":2}}`, "")
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -36,7 +36,7 @@ func TestV2SetKeyWithTTL(t *testing.T) {
|
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
|
v.Set("value", "XXX")
|
|
v.Set("value", "XXX")
|
|
|
v.Set("ttl", "20")
|
|
v.Set("ttl", "20")
|
|
|
- resp, _ := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
body := tests.ReadBodyJSON(resp)
|
|
body := tests.ReadBodyJSON(resp)
|
|
|
node := body["node"].(map[string]interface{})
|
|
node := body["node"].(map[string]interface{})
|
|
|
assert.Equal(t, node["ttl"], 20, "")
|
|
assert.Equal(t, node["ttl"], 20, "")
|
|
@@ -56,7 +56,7 @@ func TestV2SetKeyWithBadTTL(t *testing.T) {
|
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
|
v.Set("value", "XXX")
|
|
v.Set("value", "XXX")
|
|
|
v.Set("ttl", "bad_ttl")
|
|
v.Set("ttl", "bad_ttl")
|
|
|
- resp, _ := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
body := tests.ReadBodyJSON(resp)
|
|
body := tests.ReadBodyJSON(resp)
|
|
|
assert.Equal(t, body["errorCode"], 202, "")
|
|
assert.Equal(t, body["errorCode"], 202, "")
|
|
|
assert.Equal(t, body["message"], "The given TTL in POST form is not a number", "")
|
|
assert.Equal(t, body["message"], "The given TTL in POST form is not a number", "")
|
|
@@ -73,7 +73,7 @@ func TestV2CreateKeySuccess(t *testing.T) {
|
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
|
v.Set("value", "XXX")
|
|
v.Set("value", "XXX")
|
|
|
v.Set("prevExist", "false")
|
|
v.Set("prevExist", "false")
|
|
|
- resp, _ := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
body := tests.ReadBodyJSON(resp)
|
|
body := tests.ReadBodyJSON(resp)
|
|
|
node := body["node"].(map[string]interface{})
|
|
node := body["node"].(map[string]interface{})
|
|
|
assert.Equal(t, node["value"], "XXX", "")
|
|
assert.Equal(t, node["value"], "XXX", "")
|
|
@@ -90,9 +90,9 @@ func TestV2CreateKeyFail(t *testing.T) {
|
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
|
v.Set("value", "XXX")
|
|
v.Set("value", "XXX")
|
|
|
v.Set("prevExist", "false")
|
|
v.Set("prevExist", "false")
|
|
|
- resp, _ := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
tests.ReadBody(resp)
|
|
tests.ReadBody(resp)
|
|
|
- resp, _ = tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ = tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
body := tests.ReadBodyJSON(resp)
|
|
body := tests.ReadBodyJSON(resp)
|
|
|
assert.Equal(t, body["errorCode"], 105, "")
|
|
assert.Equal(t, body["errorCode"], 105, "")
|
|
|
assert.Equal(t, body["message"], "Already exists", "")
|
|
assert.Equal(t, body["message"], "Already exists", "")
|
|
@@ -110,12 +110,12 @@ func TestV2UpdateKeySuccess(t *testing.T) {
|
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
|
|
|
|
|
|
v.Set("value", "XXX")
|
|
v.Set("value", "XXX")
|
|
|
- resp, _ := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
tests.ReadBody(resp)
|
|
tests.ReadBody(resp)
|
|
|
|
|
|
|
|
v.Set("value", "YYY")
|
|
v.Set("value", "YYY")
|
|
|
v.Set("prevExist", "true")
|
|
v.Set("prevExist", "true")
|
|
|
- resp, _ = tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ = tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
body := tests.ReadBodyJSON(resp)
|
|
body := tests.ReadBodyJSON(resp)
|
|
|
assert.Equal(t, body["action"], "update", "")
|
|
assert.Equal(t, body["action"], "update", "")
|
|
|
|
|
|
|
@@ -131,11 +131,11 @@ func TestV2UpdateKeySuccess(t *testing.T) {
|
|
|
func TestV2UpdateKeyFailOnValue(t *testing.T) {
|
|
func TestV2UpdateKeyFailOnValue(t *testing.T) {
|
|
|
tests.RunServer(func(s *server.Server) {
|
|
tests.RunServer(func(s *server.Server) {
|
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
|
- resp, _ := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo"), v)
|
|
|
|
|
|
|
+ resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo"), v)
|
|
|
|
|
|
|
|
v.Set("value", "YYY")
|
|
v.Set("value", "YYY")
|
|
|
v.Set("prevExist", "true")
|
|
v.Set("prevExist", "true")
|
|
|
- resp, _ = tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ = tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
body := tests.ReadBodyJSON(resp)
|
|
body := tests.ReadBodyJSON(resp)
|
|
|
assert.Equal(t, body["errorCode"], 100, "")
|
|
assert.Equal(t, body["errorCode"], 100, "")
|
|
|
assert.Equal(t, body["message"], "Key Not Found", "")
|
|
assert.Equal(t, body["message"], "Key Not Found", "")
|
|
@@ -153,7 +153,7 @@ func TestV2UpdateKeyFailOnMissingDirectory(t *testing.T) {
|
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
|
v.Set("value", "YYY")
|
|
v.Set("value", "YYY")
|
|
|
v.Set("prevExist", "true")
|
|
v.Set("prevExist", "true")
|
|
|
- resp, _ := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
body := tests.ReadBodyJSON(resp)
|
|
body := tests.ReadBodyJSON(resp)
|
|
|
assert.Equal(t, body["errorCode"], 100, "")
|
|
assert.Equal(t, body["errorCode"], 100, "")
|
|
|
assert.Equal(t, body["message"], "Key Not Found", "")
|
|
assert.Equal(t, body["message"], "Key Not Found", "")
|
|
@@ -170,18 +170,17 @@ func TestV2SetKeyCASOnIndexSuccess(t *testing.T) {
|
|
|
tests.RunServer(func(s *server.Server) {
|
|
tests.RunServer(func(s *server.Server) {
|
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
|
v.Set("value", "XXX")
|
|
v.Set("value", "XXX")
|
|
|
- resp, _ := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
tests.ReadBody(resp)
|
|
tests.ReadBody(resp)
|
|
|
v.Set("value", "YYY")
|
|
v.Set("value", "YYY")
|
|
|
- v.Set("prevIndex", "1")
|
|
|
|
|
- resp, _ = tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ v.Set("prevIndex", "2")
|
|
|
|
|
+ resp, _ = tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
body := tests.ReadBodyJSON(resp)
|
|
body := tests.ReadBodyJSON(resp)
|
|
|
assert.Equal(t, body["action"], "compareAndSwap", "")
|
|
assert.Equal(t, body["action"], "compareAndSwap", "")
|
|
|
-
|
|
|
|
|
node := body["node"].(map[string]interface{})
|
|
node := body["node"].(map[string]interface{})
|
|
|
assert.Equal(t, node["prevValue"], "XXX", "")
|
|
assert.Equal(t, node["prevValue"], "XXX", "")
|
|
|
assert.Equal(t, node["value"], "YYY", "")
|
|
assert.Equal(t, node["value"], "YYY", "")
|
|
|
- assert.Equal(t, node["modifiedIndex"], 2, "")
|
|
|
|
|
|
|
+ assert.Equal(t, node["modifiedIndex"], 3, "")
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -194,16 +193,16 @@ func TestV2SetKeyCASOnIndexFail(t *testing.T) {
|
|
|
tests.RunServer(func(s *server.Server) {
|
|
tests.RunServer(func(s *server.Server) {
|
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
|
v.Set("value", "XXX")
|
|
v.Set("value", "XXX")
|
|
|
- resp, _ := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
tests.ReadBody(resp)
|
|
tests.ReadBody(resp)
|
|
|
v.Set("value", "YYY")
|
|
v.Set("value", "YYY")
|
|
|
v.Set("prevIndex", "10")
|
|
v.Set("prevIndex", "10")
|
|
|
- resp, _ = tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ = tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
body := tests.ReadBodyJSON(resp)
|
|
body := tests.ReadBodyJSON(resp)
|
|
|
assert.Equal(t, body["errorCode"], 101, "")
|
|
assert.Equal(t, body["errorCode"], 101, "")
|
|
|
assert.Equal(t, body["message"], "Test Failed", "")
|
|
assert.Equal(t, body["message"], "Test Failed", "")
|
|
|
- assert.Equal(t, body["cause"], "[ != XXX] [10 != 1]", "")
|
|
|
|
|
- assert.Equal(t, body["index"], 1, "")
|
|
|
|
|
|
|
+ assert.Equal(t, body["cause"], "[ != XXX] [10 != 2]", "")
|
|
|
|
|
+ assert.Equal(t, body["index"], 2, "")
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -216,7 +215,7 @@ func TestV2SetKeyCASWithInvalidIndex(t *testing.T) {
|
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
|
v.Set("value", "YYY")
|
|
v.Set("value", "YYY")
|
|
|
v.Set("prevIndex", "bad_index")
|
|
v.Set("prevIndex", "bad_index")
|
|
|
- resp, _ := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
body := tests.ReadBodyJSON(resp)
|
|
body := tests.ReadBodyJSON(resp)
|
|
|
assert.Equal(t, body["errorCode"], 203, "")
|
|
assert.Equal(t, body["errorCode"], 203, "")
|
|
|
assert.Equal(t, body["message"], "The given index in POST form is not a number", "")
|
|
assert.Equal(t, body["message"], "The given index in POST form is not a number", "")
|
|
@@ -233,18 +232,17 @@ func TestV2SetKeyCASOnValueSuccess(t *testing.T) {
|
|
|
tests.RunServer(func(s *server.Server) {
|
|
tests.RunServer(func(s *server.Server) {
|
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
|
v.Set("value", "XXX")
|
|
v.Set("value", "XXX")
|
|
|
- resp, _ := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
tests.ReadBody(resp)
|
|
tests.ReadBody(resp)
|
|
|
v.Set("value", "YYY")
|
|
v.Set("value", "YYY")
|
|
|
v.Set("prevValue", "XXX")
|
|
v.Set("prevValue", "XXX")
|
|
|
- resp, _ = tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ = tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
body := tests.ReadBodyJSON(resp)
|
|
body := tests.ReadBodyJSON(resp)
|
|
|
assert.Equal(t, body["action"], "compareAndSwap", "")
|
|
assert.Equal(t, body["action"], "compareAndSwap", "")
|
|
|
-
|
|
|
|
|
node := body["node"].(map[string]interface{})
|
|
node := body["node"].(map[string]interface{})
|
|
|
assert.Equal(t, node["prevValue"], "XXX", "")
|
|
assert.Equal(t, node["prevValue"], "XXX", "")
|
|
|
assert.Equal(t, node["value"], "YYY", "")
|
|
assert.Equal(t, node["value"], "YYY", "")
|
|
|
- assert.Equal(t, node["modifiedIndex"], 2, "")
|
|
|
|
|
|
|
+ assert.Equal(t, node["modifiedIndex"], 3, "")
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -257,16 +255,16 @@ func TestV2SetKeyCASOnValueFail(t *testing.T) {
|
|
|
tests.RunServer(func(s *server.Server) {
|
|
tests.RunServer(func(s *server.Server) {
|
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
|
v.Set("value", "XXX")
|
|
v.Set("value", "XXX")
|
|
|
- resp, _ := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
tests.ReadBody(resp)
|
|
tests.ReadBody(resp)
|
|
|
v.Set("value", "YYY")
|
|
v.Set("value", "YYY")
|
|
|
v.Set("prevValue", "AAA")
|
|
v.Set("prevValue", "AAA")
|
|
|
- resp, _ = tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ = tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
body := tests.ReadBodyJSON(resp)
|
|
body := tests.ReadBodyJSON(resp)
|
|
|
assert.Equal(t, body["errorCode"], 101, "")
|
|
assert.Equal(t, body["errorCode"], 101, "")
|
|
|
assert.Equal(t, body["message"], "Test Failed", "")
|
|
assert.Equal(t, body["message"], "Test Failed", "")
|
|
|
- assert.Equal(t, body["cause"], "[AAA != XXX] [0 != 1]", "")
|
|
|
|
|
- assert.Equal(t, body["index"], 1, "")
|
|
|
|
|
|
|
+ assert.Equal(t, body["cause"], "[AAA != XXX] [0 != 2]", "")
|
|
|
|
|
+ assert.Equal(t, body["index"], 2, "")
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -279,7 +277,7 @@ func TestV2SetKeyCASWithMissingValueFails(t *testing.T) {
|
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
|
v.Set("value", "XXX")
|
|
v.Set("value", "XXX")
|
|
|
v.Set("prevValue", "")
|
|
v.Set("prevValue", "")
|
|
|
- resp, _ := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
|
|
|
|
+ resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
|
|
|
body := tests.ReadBodyJSON(resp)
|
|
body := tests.ReadBodyJSON(resp)
|
|
|
assert.Equal(t, body["errorCode"], 201, "")
|
|
assert.Equal(t, body["errorCode"], 201, "")
|
|
|
assert.Equal(t, body["message"], "PrevValue is Required in POST form", "")
|
|
assert.Equal(t, body["message"], "PrevValue is Required in POST form", "")
|