mirror of
https://github.com/status-im/consul.git
synced 2025-01-09 13:26:07 +00:00
test: drop error check on http.NewRequest
Most URLs are static so the error check is redundant. The subsequent test wouldn't work if the url is wrong.
This commit is contained in:
parent
7fa2471ba7
commit
1e89692cc1
@ -20,10 +20,7 @@ func makeTestACL(t *testing.T, srv *HTTPServer) string {
|
|||||||
}
|
}
|
||||||
enc.Encode(raw)
|
enc.Encode(raw)
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT", "/v1/acl/create?token=root", body)
|
req, _ := http.NewRequest("PUT", "/v1/acl/create?token=root", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.ACLCreate(resp, req)
|
obj, err := srv.ACLCreate(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -47,10 +44,7 @@ func TestACLUpdate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
enc.Encode(raw)
|
enc.Encode(raw)
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT", "/v1/acl/update?token=root", body)
|
req, _ := http.NewRequest("PUT", "/v1/acl/update?token=root", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.ACLUpdate(resp, req)
|
obj, err := srv.ACLUpdate(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -75,10 +69,7 @@ func TestACLUpdate_Upsert(t *testing.T) {
|
|||||||
}
|
}
|
||||||
enc.Encode(raw)
|
enc.Encode(raw)
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT", "/v1/acl/update?token=root", body)
|
req, _ := http.NewRequest("PUT", "/v1/acl/update?token=root", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.ACLUpdate(resp, req)
|
obj, err := srv.ACLUpdate(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -94,7 +85,7 @@ func TestACLUpdate_Upsert(t *testing.T) {
|
|||||||
func TestACLDestroy(t *testing.T) {
|
func TestACLDestroy(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
id := makeTestACL(t, srv)
|
id := makeTestACL(t, srv)
|
||||||
req, err := http.NewRequest("PUT", "/v1/acl/destroy/"+id+"?token=root", nil)
|
req, _ := http.NewRequest("PUT", "/v1/acl/destroy/"+id+"?token=root", nil)
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.ACLDestroy(resp, req)
|
obj, err := srv.ACLDestroy(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -104,8 +95,7 @@ func TestACLDestroy(t *testing.T) {
|
|||||||
t.Fatalf("should work")
|
t.Fatalf("should work")
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err = http.NewRequest("GET",
|
req, _ = http.NewRequest("GET", "/v1/acl/info/"+id, nil)
|
||||||
"/v1/acl/info/"+id, nil)
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.ACLGet(resp, req)
|
obj, err = srv.ACLGet(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -125,8 +115,7 @@ func TestACLClone(t *testing.T) {
|
|||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
id := makeTestACL(t, srv)
|
id := makeTestACL(t, srv)
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT",
|
req, _ := http.NewRequest("PUT", "/v1/acl/clone/"+id+"?token=root", nil)
|
||||||
"/v1/acl/clone/"+id+"?token=root", nil)
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.ACLClone(resp, req)
|
obj, err := srv.ACLClone(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -140,8 +129,7 @@ func TestACLClone(t *testing.T) {
|
|||||||
t.Fatalf("bad id")
|
t.Fatalf("bad id")
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err = http.NewRequest("GET",
|
req, _ = http.NewRequest("GET", "/v1/acl/info/"+aclResp.ID, nil)
|
||||||
"/v1/acl/info/"+aclResp.ID, nil)
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.ACLGet(resp, req)
|
obj, err = srv.ACLGet(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -159,7 +147,7 @@ func TestACLClone(t *testing.T) {
|
|||||||
|
|
||||||
func TestACLGet(t *testing.T) {
|
func TestACLGet(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
req, err := http.NewRequest("GET", "/v1/acl/info/nope", nil)
|
req, _ := http.NewRequest("GET", "/v1/acl/info/nope", nil)
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.ACLGet(resp, req)
|
obj, err := srv.ACLGet(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -177,8 +165,7 @@ func TestACLGet(t *testing.T) {
|
|||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
id := makeTestACL(t, srv)
|
id := makeTestACL(t, srv)
|
||||||
|
|
||||||
req, err := http.NewRequest("GET",
|
req, _ := http.NewRequest("GET", "/v1/acl/info/"+id, nil)
|
||||||
"/v1/acl/info/"+id, nil)
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.ACLGet(resp, req)
|
obj, err := srv.ACLGet(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -201,7 +188,7 @@ func TestACLList(t *testing.T) {
|
|||||||
ids = append(ids, makeTestACL(t, srv))
|
ids = append(ids, makeTestACL(t, srv))
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/acl/list?token=root", nil)
|
req, _ := http.NewRequest("GET", "/v1/acl/list?token=root", nil)
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.ACLList(resp, req)
|
obj, err := srv.ACLList(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -221,7 +208,7 @@ func TestACLList(t *testing.T) {
|
|||||||
|
|
||||||
func TestACLReplicationStatus(t *testing.T) {
|
func TestACLReplicationStatus(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
req, err := http.NewRequest("GET", "/v1/acl/replication", nil)
|
req, _ := http.NewRequest("GET", "/v1/acl/replication", nil)
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.ACLReplicationStatus(resp, req)
|
obj, err := srv.ACLReplicationStatus(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -34,10 +34,7 @@ func makeReadOnlyAgentACL(t *testing.T, srv *HTTPServer) string {
|
|||||||
}
|
}
|
||||||
enc.Encode(raw)
|
enc.Encode(raw)
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT", "/v1/acl/create?token=root", body)
|
req, _ := http.NewRequest("PUT", "/v1/acl/create?token=root", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.ACLCreate(resp, req)
|
obj, err := srv.ACLCreate(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -61,11 +58,7 @@ func TestAgent_Services(t *testing.T) {
|
|||||||
}
|
}
|
||||||
srv.agent.state.AddService(srv1, "")
|
srv.agent.state.AddService(srv1, "")
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/services", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/services", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentServices(nil, req)
|
obj, err := srv.AgentServices(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
@ -87,11 +80,7 @@ func TestAgent_Services_ACLFilter(t *testing.T) {
|
|||||||
|
|
||||||
// Try no token.
|
// Try no token.
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/services", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/services", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentServices(nil, req)
|
obj, err := srv.AgentServices(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
@ -104,11 +93,7 @@ func TestAgent_Services_ACLFilter(t *testing.T) {
|
|||||||
|
|
||||||
// Try the root token (we will get the implicit "consul" service).
|
// Try the root token (we will get the implicit "consul" service).
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/services?token=root", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/services?token=root", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentServices(nil, req)
|
obj, err := srv.AgentServices(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
@ -134,11 +119,7 @@ func TestAgent_Checks(t *testing.T) {
|
|||||||
}
|
}
|
||||||
srv.agent.state.AddCheck(chk1, "")
|
srv.agent.state.AddCheck(chk1, "")
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/checks", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/checks", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentChecks(nil, req)
|
obj, err := srv.AgentChecks(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
@ -168,11 +149,7 @@ func TestAgent_Checks_ACLFilter(t *testing.T) {
|
|||||||
|
|
||||||
// Try no token.
|
// Try no token.
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/checks", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/checks", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentChecks(nil, req)
|
obj, err := srv.AgentChecks(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
@ -185,11 +162,7 @@ func TestAgent_Checks_ACLFilter(t *testing.T) {
|
|||||||
|
|
||||||
// Try the root token.
|
// Try the root token.
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/checks?token=root", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/checks?token=root", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentChecks(nil, req)
|
obj, err := srv.AgentChecks(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
@ -212,11 +185,7 @@ func TestAgent_Self(t *testing.T) {
|
|||||||
defer srv.Shutdown()
|
defer srv.Shutdown()
|
||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/self", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/self", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentSelf(nil, req)
|
obj, err := srv.AgentSelf(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
@ -259,43 +228,23 @@ func TestAgent_Self_ACLDeny(t *testing.T) {
|
|||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
// Try without a token.
|
// Try without a token.
|
||||||
{
|
req, _ := http.NewRequest("GET", "/v1/agent/self", nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/self", nil)
|
_, err := srv.AgentSelf(nil, req)
|
||||||
if err != nil {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
|
||||||
|
|
||||||
_, err = srv.AgentSelf(nil, req)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try the agent master token (resolved on the agent).
|
// Try the agent master token (resolved on the agent).
|
||||||
{
|
req, _ = http.NewRequest("GET", "/v1/agent/self?token=towel", nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/self?token=towel", nil)
|
if _, err := srv.AgentSelf(nil, req); err != nil {
|
||||||
if err != nil {
|
t.Fatalf("err: %v", err)
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = srv.AgentSelf(nil, req)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try a read only token (resolved on the servers).
|
// Try a read only token (resolved on the servers).
|
||||||
ro := makeReadOnlyAgentACL(t, srv)
|
ro := makeReadOnlyAgentACL(t, srv)
|
||||||
{
|
req, _ = http.NewRequest("GET", fmt.Sprintf("/v1/agent/self?token=%s", ro), nil)
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/self?token=%s", ro), nil)
|
if _, err := srv.AgentSelf(nil, req); err != nil {
|
||||||
if err != nil {
|
t.Fatalf("err: %v", err)
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = srv.AgentSelf(nil, req)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,19 +306,14 @@ func TestAgent_Reload(t *testing.T) {
|
|||||||
t.Fatalf("missing redis service")
|
t.Fatalf("missing redis service")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ioutil.WriteFile(tmpFile.Name(), []byte(`{"acl_enforce_version_8": false, "service":{"name":"redis-reloaded"}}`), 0644)
|
data := []byte(`{"acl_enforce_version_8": false, "service":{"name":"redis-reloaded"}}`)
|
||||||
if err != nil {
|
if err := ioutil.WriteFile(tmpFile.Name(), data, 0644); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
srv := cmd.httpServers[0]
|
srv := cmd.httpServers[0]
|
||||||
req, err := http.NewRequest("PUT", "/v1/agent/reload", nil)
|
req, _ := http.NewRequest("PUT", "/v1/agent/reload", nil)
|
||||||
if err != nil {
|
if _, err := srv.AgentReload(nil, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = srv.AgentReload(nil, req)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,30 +329,18 @@ func TestAgent_Reload_ACLDeny(t *testing.T) {
|
|||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
// Try without a token.
|
// Try without a token.
|
||||||
{
|
req, _ := http.NewRequest("PUT", "/v1/agent/reload", nil)
|
||||||
req, err := http.NewRequest("PUT", "/v1/agent/reload", nil)
|
_, err := srv.AgentReload(nil, req)
|
||||||
if err != nil {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
|
||||||
|
|
||||||
_, err = srv.AgentReload(nil, req)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try with a read only token (resolved on the servers).
|
// Try with a read only token (resolved on the servers).
|
||||||
ro := makeReadOnlyAgentACL(t, srv)
|
ro := makeReadOnlyAgentACL(t, srv)
|
||||||
{
|
req, _ = http.NewRequest("PUT", fmt.Sprintf("/v1/agent/reload?token=%s", ro), nil)
|
||||||
req, err := http.NewRequest("PUT", fmt.Sprintf("/v1/agent/reload?token=%s", ro), nil)
|
_, err = srv.AgentReload(nil, req)
|
||||||
if err != nil {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
|
||||||
|
|
||||||
_, err = srv.AgentReload(nil, req)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This proves we call the ACL function, and we've got the other reload
|
// This proves we call the ACL function, and we've got the other reload
|
||||||
@ -423,11 +355,7 @@ func TestAgent_Members(t *testing.T) {
|
|||||||
defer srv.Shutdown()
|
defer srv.Shutdown()
|
||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/members", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/members", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentMembers(nil, req)
|
obj, err := srv.AgentMembers(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
@ -448,11 +376,7 @@ func TestAgent_Members_WAN(t *testing.T) {
|
|||||||
defer srv.Shutdown()
|
defer srv.Shutdown()
|
||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/members?wan=true", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/members?wan=true", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentMembers(nil, req)
|
obj, err := srv.AgentMembers(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
@ -475,11 +399,7 @@ func TestAgent_Members_ACLFilter(t *testing.T) {
|
|||||||
|
|
||||||
// Try no token.
|
// Try no token.
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/members", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/members", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentMembers(nil, req)
|
obj, err := srv.AgentMembers(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
@ -492,11 +412,7 @@ func TestAgent_Members_ACLFilter(t *testing.T) {
|
|||||||
|
|
||||||
// Try the root token.
|
// Try the root token.
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/members?token=root", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/members?token=root", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentMembers(nil, req)
|
obj, err := srv.AgentMembers(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
@ -519,11 +435,7 @@ func TestAgent_Join(t *testing.T) {
|
|||||||
defer a2.Shutdown()
|
defer a2.Shutdown()
|
||||||
|
|
||||||
addr := fmt.Sprintf("127.0.0.1:%d", a2.config.Ports.SerfLan)
|
addr := fmt.Sprintf("127.0.0.1:%d", a2.config.Ports.SerfLan)
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s", addr), nil)
|
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s", addr), nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentJoin(nil, req)
|
obj, err := srv.AgentJoin(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
@ -554,11 +466,7 @@ func TestAgent_Join_WAN(t *testing.T) {
|
|||||||
defer a2.Shutdown()
|
defer a2.Shutdown()
|
||||||
|
|
||||||
addr := fmt.Sprintf("127.0.0.1:%d", a2.config.Ports.SerfWan)
|
addr := fmt.Sprintf("127.0.0.1:%d", a2.config.Ports.SerfWan)
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s?wan=true", addr), nil)
|
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s?wan=true", addr), nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentJoin(nil, req)
|
obj, err := srv.AgentJoin(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
@ -591,12 +499,8 @@ func TestAgent_Join_ACLDeny(t *testing.T) {
|
|||||||
|
|
||||||
// Try without a token.
|
// Try without a token.
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s", addr), nil)
|
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s", addr), nil)
|
||||||
if err != nil {
|
_, err := srv.AgentJoin(nil, req)
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = srv.AgentJoin(nil, req)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
@ -604,12 +508,8 @@ func TestAgent_Join_ACLDeny(t *testing.T) {
|
|||||||
|
|
||||||
// Try the agent master token (resolved on the agent).
|
// Try the agent master token (resolved on the agent).
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s?token=towel", addr), nil)
|
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s?token=towel", addr), nil)
|
||||||
if err != nil {
|
_, err := srv.AgentJoin(nil, req)
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = srv.AgentJoin(nil, req)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
@ -618,12 +518,8 @@ func TestAgent_Join_ACLDeny(t *testing.T) {
|
|||||||
// Try with a read only token (resolved on the servers).
|
// Try with a read only token (resolved on the servers).
|
||||||
ro := makeReadOnlyAgentACL(t, srv)
|
ro := makeReadOnlyAgentACL(t, srv)
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s?token=%s", addr, ro), nil)
|
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s?token=%s", addr, ro), nil)
|
||||||
if err != nil {
|
_, err := srv.AgentJoin(nil, req)
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = srv.AgentJoin(nil, req)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
@ -651,11 +547,7 @@ func TestAgent_Leave(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Graceful leave now
|
// Graceful leave now
|
||||||
req, err := http.NewRequest("PUT", "/v1/agent/leave", nil)
|
req, _ := http.NewRequest("PUT", "/v1/agent/leave", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv2.AgentLeave(nil, req)
|
obj, err := srv2.AgentLeave(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
@ -679,12 +571,8 @@ func TestAgent_Leave_ACLDeny(t *testing.T) {
|
|||||||
defer srv.Shutdown()
|
defer srv.Shutdown()
|
||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT", "/v1/agent/leave", nil)
|
req, _ := http.NewRequest("PUT", "/v1/agent/leave", nil)
|
||||||
if err != nil {
|
_, err := srv.AgentLeave(nil, req)
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = srv.AgentLeave(nil, req)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
@ -697,12 +585,8 @@ func TestAgent_Leave_ACLDeny(t *testing.T) {
|
|||||||
defer srv.Shutdown()
|
defer srv.Shutdown()
|
||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT", "/v1/agent/leave?token=towel", nil)
|
req, _ := http.NewRequest("PUT", "/v1/agent/leave?token=towel", nil)
|
||||||
if err != nil {
|
_, err := srv.AgentLeave(nil, req)
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = srv.AgentLeave(nil, req)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
@ -716,12 +600,8 @@ func TestAgent_Leave_ACLDeny(t *testing.T) {
|
|||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
ro := makeReadOnlyAgentACL(t, srv)
|
ro := makeReadOnlyAgentACL(t, srv)
|
||||||
req, err := http.NewRequest("PUT", fmt.Sprintf("/v1/agent/leave?token=%s", ro), nil)
|
req, _ := http.NewRequest("PUT", fmt.Sprintf("/v1/agent/leave?token=%s", ro), nil)
|
||||||
if err != nil {
|
_, err := srv.AgentLeave(nil, req)
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = srv.AgentLeave(nil, req)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
@ -748,11 +628,7 @@ func TestAgent_ForceLeave(t *testing.T) {
|
|||||||
a2.Shutdown()
|
a2.Shutdown()
|
||||||
|
|
||||||
// Force leave now
|
// Force leave now
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/force-leave/%s", a2.config.NodeName), nil)
|
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/agent/force-leave/%s", a2.config.NodeName), nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentForceLeave(nil, req)
|
obj, err := srv.AgentForceLeave(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
@ -777,12 +653,8 @@ func TestAgent_ForceLeave_ACLDeny(t *testing.T) {
|
|||||||
|
|
||||||
// Try without a token.
|
// Try without a token.
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/force-leave/nope", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/force-leave/nope", nil)
|
||||||
if err != nil {
|
_, err := srv.AgentForceLeave(nil, req)
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = srv.AgentForceLeave(nil, req)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
@ -790,12 +662,8 @@ func TestAgent_ForceLeave_ACLDeny(t *testing.T) {
|
|||||||
|
|
||||||
// Try the agent master token (resolved on the agent).
|
// Try the agent master token (resolved on the agent).
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/force-leave/nope?token=towel", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/force-leave/nope?token=towel", nil)
|
||||||
if err != nil {
|
_, err := srv.AgentForceLeave(nil, req)
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = srv.AgentForceLeave(nil, req)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
@ -804,12 +672,8 @@ func TestAgent_ForceLeave_ACLDeny(t *testing.T) {
|
|||||||
// Try a read only token (resolved on the servers).
|
// Try a read only token (resolved on the servers).
|
||||||
ro := makeReadOnlyAgentACL(t, srv)
|
ro := makeReadOnlyAgentACL(t, srv)
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/force-leave/nope?token=%s", ro), nil)
|
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/agent/force-leave/nope?token=%s", ro), nil)
|
||||||
if err != nil {
|
_, err := srv.AgentForceLeave(nil, req)
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = srv.AgentForceLeave(nil, req)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
@ -823,10 +687,7 @@ func TestAgent_RegisterCheck(t *testing.T) {
|
|||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
// Register node
|
// Register node
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/check/register?token=abc123", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/check/register?token=abc123", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
args := &CheckDefinition{
|
args := &CheckDefinition{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
CheckType: CheckType{
|
CheckType: CheckType{
|
||||||
@ -872,10 +733,7 @@ func TestAgent_RegisterCheck_Passing(t *testing.T) {
|
|||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
// Register node
|
// Register node
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/check/register", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/check/register", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
args := &CheckDefinition{
|
args := &CheckDefinition{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
CheckType: CheckType{
|
CheckType: CheckType{
|
||||||
@ -916,10 +774,7 @@ func TestAgent_RegisterCheck_BadStatus(t *testing.T) {
|
|||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
// Register node
|
// Register node
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/check/register", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/check/register", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
args := &CheckDefinition{
|
args := &CheckDefinition{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
CheckType: CheckType{
|
CheckType: CheckType{
|
||||||
@ -945,10 +800,7 @@ func TestAgent_RegisterCheck_ACLDeny(t *testing.T) {
|
|||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
// Try with no token.
|
// Try with no token.
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/check/register", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/check/register", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
args := &CheckDefinition{
|
args := &CheckDefinition{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
CheckType: CheckType{
|
CheckType: CheckType{
|
||||||
@ -956,19 +808,15 @@ func TestAgent_RegisterCheck_ACLDeny(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
req.Body = encodeReq(args)
|
req.Body = encodeReq(args)
|
||||||
_, err = srv.AgentRegisterCheck(nil, req)
|
_, err := srv.AgentRegisterCheck(nil, req)
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try the root token.
|
// Try the root token.
|
||||||
req, err = http.NewRequest("GET", "/v1/agent/check/register?token=root", nil)
|
req, _ = http.NewRequest("GET", "/v1/agent/check/register?token=root", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
req.Body = encodeReq(args)
|
req.Body = encodeReq(args)
|
||||||
_, err = srv.AgentRegisterCheck(nil, req)
|
if _, err := srv.AgentRegisterCheck(nil, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -985,11 +833,7 @@ func TestAgent_DeregisterCheck(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Register node
|
// Register node
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/check/deregister/test", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/check/deregister/test", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentDeregisterCheck(nil, req)
|
obj, err := srv.AgentDeregisterCheck(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
@ -1016,22 +860,15 @@ func TestAgent_DeregisterCheckACLDeny(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try with no token.
|
// Try with no token.
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/check/deregister/test", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/check/deregister/test", nil)
|
||||||
if err != nil {
|
_, err := srv.AgentDeregisterCheck(nil, req)
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
_, err = srv.AgentDeregisterCheck(nil, req)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try with the root token.
|
// Try with the root token.
|
||||||
req, err = http.NewRequest("GET", "/v1/agent/check/deregister/test?token=root", nil)
|
req, _ = http.NewRequest("GET", "/v1/agent/check/deregister/test?token=root", nil)
|
||||||
if err != nil {
|
if _, err := srv.AgentDeregisterCheck(nil, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
_, err = srv.AgentDeregisterCheck(nil, req)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1048,11 +885,7 @@ func TestAgent_PassCheck(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/check/pass/test", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/check/pass/test", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentCheckPass(nil, req)
|
obj, err := srv.AgentCheckPass(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
@ -1081,22 +914,15 @@ func TestAgent_PassCheck_ACLDeny(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try with no token.
|
// Try with no token.
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/check/pass/test", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/check/pass/test", nil)
|
||||||
if err != nil {
|
_, err := srv.AgentCheckPass(nil, req)
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
_, err = srv.AgentCheckPass(nil, req)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try with the root token.
|
// Try with the root token.
|
||||||
req, err = http.NewRequest("GET", "/v1/agent/check/pass/test?token=root", nil)
|
req, _ = http.NewRequest("GET", "/v1/agent/check/pass/test?token=root", nil)
|
||||||
if err != nil {
|
if _, err := srv.AgentCheckPass(nil, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
_, err = srv.AgentCheckPass(nil, req)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1113,11 +939,7 @@ func TestAgent_WarnCheck(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/check/warn/test", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/check/warn/test", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentCheckWarn(nil, req)
|
obj, err := srv.AgentCheckWarn(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
@ -1146,22 +968,15 @@ func TestAgent_WarnCheck_ACLDeny(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try with no token.
|
// Try with no token.
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/check/warn/test", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/check/warn/test", nil)
|
||||||
if err != nil {
|
_, err := srv.AgentCheckWarn(nil, req)
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
_, err = srv.AgentCheckWarn(nil, req)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try with the root token.
|
// Try with the root token.
|
||||||
req, err = http.NewRequest("GET", "/v1/agent/check/warn/test?token=root", nil)
|
req, _ = http.NewRequest("GET", "/v1/agent/check/warn/test?token=root", nil)
|
||||||
if err != nil {
|
if _, err := srv.AgentCheckWarn(nil, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
_, err = srv.AgentCheckWarn(nil, req)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1178,11 +993,7 @@ func TestAgent_FailCheck(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/check/fail/test", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/check/fail/test", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentCheckFail(nil, req)
|
obj, err := srv.AgentCheckFail(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
@ -1211,22 +1022,15 @@ func TestAgent_FailCheck_ACLDeny(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try with no token.
|
// Try with no token.
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/check/fail/test", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/check/fail/test", nil)
|
||||||
if err != nil {
|
_, err := srv.AgentCheckFail(nil, req)
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
_, err = srv.AgentCheckFail(nil, req)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try with the root token.
|
// Try with the root token.
|
||||||
req, err = http.NewRequest("GET", "/v1/agent/check/fail/test?token=root", nil)
|
req, _ = http.NewRequest("GET", "/v1/agent/check/fail/test?token=root", nil)
|
||||||
if err != nil {
|
if _, err := srv.AgentCheckFail(nil, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
_, err = srv.AgentCheckFail(nil, req)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1250,10 +1054,7 @@ func TestAgent_UpdateCheck(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
req, err := http.NewRequest("PUT", "/v1/agent/check/update/test", nil)
|
req, _ := http.NewRequest("PUT", "/v1/agent/check/update/test", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
req.Body = encodeReq(c)
|
req.Body = encodeReq(c)
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
@ -1276,11 +1077,7 @@ func TestAgent_UpdateCheck(t *testing.T) {
|
|||||||
|
|
||||||
// Make sure abusive levels of output are capped.
|
// Make sure abusive levels of output are capped.
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("PUT", "/v1/agent/check/update/test", nil)
|
req, _ := http.NewRequest("PUT", "/v1/agent/check/update/test", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
update := checkUpdate{
|
update := checkUpdate{
|
||||||
Status: api.HealthPassing,
|
Status: api.HealthPassing,
|
||||||
Output: strings.Repeat("-= bad -=", 5*CheckBufSize),
|
Output: strings.Repeat("-= bad -=", 5*CheckBufSize),
|
||||||
@ -1310,11 +1107,7 @@ func TestAgent_UpdateCheck(t *testing.T) {
|
|||||||
|
|
||||||
// Check a bogus status.
|
// Check a bogus status.
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("PUT", "/v1/agent/check/update/test", nil)
|
req, _ := http.NewRequest("PUT", "/v1/agent/check/update/test", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
update := checkUpdate{
|
update := checkUpdate{
|
||||||
Status: "itscomplicated",
|
Status: "itscomplicated",
|
||||||
}
|
}
|
||||||
@ -1335,11 +1128,7 @@ func TestAgent_UpdateCheck(t *testing.T) {
|
|||||||
|
|
||||||
// Check a bogus verb.
|
// Check a bogus verb.
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("POST", "/v1/agent/check/update/test", nil)
|
req, _ := http.NewRequest("POST", "/v1/agent/check/update/test", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
update := checkUpdate{
|
update := checkUpdate{
|
||||||
Status: api.HealthPassing,
|
Status: api.HealthPassing,
|
||||||
}
|
}
|
||||||
@ -1372,24 +1161,17 @@ func TestAgent_UpdateCheck_ACLDeny(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try with no token.
|
// Try with no token.
|
||||||
req, err := http.NewRequest("PUT", "/v1/agent/check/update/test", nil)
|
req, _ := http.NewRequest("PUT", "/v1/agent/check/update/test", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
req.Body = encodeReq(checkUpdate{api.HealthPassing, "hello-passing"})
|
req.Body = encodeReq(checkUpdate{api.HealthPassing, "hello-passing"})
|
||||||
_, err = srv.AgentCheckUpdate(nil, req)
|
_, err := srv.AgentCheckUpdate(nil, req)
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try with the root token.
|
// Try with the root token.
|
||||||
req, err = http.NewRequest("PUT", "/v1/agent/check/update/test?token=root", nil)
|
req, _ = http.NewRequest("PUT", "/v1/agent/check/update/test?token=root", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
req.Body = encodeReq(checkUpdate{api.HealthPassing, "hello-passing"})
|
req.Body = encodeReq(checkUpdate{api.HealthPassing, "hello-passing"})
|
||||||
_, err = srv.AgentCheckUpdate(nil, req)
|
if _, err := srv.AgentCheckUpdate(nil, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1400,10 +1182,7 @@ func TestAgent_RegisterService(t *testing.T) {
|
|||||||
defer srv.Shutdown()
|
defer srv.Shutdown()
|
||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/service/register?token=abc123", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/service/register?token=abc123", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
args := &ServiceDefinition{
|
args := &ServiceDefinition{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Tags: []string{"master"},
|
Tags: []string{"master"},
|
||||||
@ -1475,24 +1254,17 @@ func TestAgent_RegisterService_ACLDeny(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try with no token.
|
// Try with no token.
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/service/register", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/service/register", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
req.Body = encodeReq(args)
|
req.Body = encodeReq(args)
|
||||||
_, err = srv.AgentRegisterService(nil, req)
|
_, err := srv.AgentRegisterService(nil, req)
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try with the root token.
|
// Try with the root token.
|
||||||
req, err = http.NewRequest("GET", "/v1/agent/service/register?token=root", nil)
|
req, _ = http.NewRequest("GET", "/v1/agent/service/register?token=root", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
req.Body = encodeReq(args)
|
req.Body = encodeReq(args)
|
||||||
_, err = srv.AgentRegisterService(nil, req)
|
if _, err := srv.AgentRegisterService(nil, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1542,11 +1314,7 @@ func TestAgent_DeregisterService(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/service/deregister/test", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/service/deregister/test", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obj, err := srv.AgentDeregisterService(nil, req)
|
obj, err := srv.AgentDeregisterService(nil, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
@ -1580,22 +1348,15 @@ func TestAgent_DeregisterService_ACLDeny(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try without a token.
|
// Try without a token.
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/service/deregister/test", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/service/deregister/test", nil)
|
||||||
if err != nil {
|
_, err := srv.AgentDeregisterService(nil, req)
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
_, err = srv.AgentDeregisterService(nil, req)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try with the root.
|
// Try with the root.
|
||||||
req, err = http.NewRequest("GET", "/v1/agent/service/deregister/test?token=root", nil)
|
req, _ = http.NewRequest("GET", "/v1/agent/service/deregister/test?token=root", nil)
|
||||||
if err != nil {
|
if _, err := srv.AgentDeregisterService(nil, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
_, err = srv.AgentDeregisterService(nil, req)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1743,22 +1504,15 @@ func TestAgent_ServiceMaintenance_ACLDeny(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try with no token.
|
// Try with no token.
|
||||||
req, err := http.NewRequest("PUT", "/v1/agent/service/maintenance/test?enable=true&reason=broken", nil)
|
req, _ := http.NewRequest("PUT", "/v1/agent/service/maintenance/test?enable=true&reason=broken", nil)
|
||||||
if err != nil {
|
_, err := srv.AgentServiceMaintenance(nil, req)
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
_, err = srv.AgentServiceMaintenance(nil, req)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try with the root token.
|
// Try with the root token.
|
||||||
req, err = http.NewRequest("PUT", "/v1/agent/service/maintenance/test?enable=true&reason=broken&token=root", nil)
|
req, _ = http.NewRequest("PUT", "/v1/agent/service/maintenance/test?enable=true&reason=broken&token=root", nil)
|
||||||
if err != nil {
|
if _, err := srv.AgentServiceMaintenance(nil, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
_, err = srv.AgentServiceMaintenance(nil, req)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1797,8 +1551,7 @@ func TestAgent_NodeMaintenance_Enable(t *testing.T) {
|
|||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
// Force the node into maintenance mode
|
// Force the node into maintenance mode
|
||||||
req, _ := http.NewRequest(
|
req, _ := http.NewRequest("PUT", "/v1/agent/self/maintenance?enable=true&reason=broken&token=mytoken", nil)
|
||||||
"PUT", "/v1/agent/self/maintenance?enable=true&reason=broken&token=mytoken", nil)
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
if _, err := srv.AgentNodeMaintenance(resp, req); err != nil {
|
if _, err := srv.AgentNodeMaintenance(resp, req); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
@ -1856,24 +1609,15 @@ func TestAgent_NodeMaintenance_ACLDeny(t *testing.T) {
|
|||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
// Try with no token.
|
// Try with no token.
|
||||||
req, err := http.NewRequest(
|
req, _ := http.NewRequest("PUT", "/v1/agent/self/maintenance?enable=true&reason=broken", nil)
|
||||||
"PUT", "/v1/agent/self/maintenance?enable=true&reason=broken", nil)
|
_, err := srv.AgentNodeMaintenance(nil, req)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
_, err = srv.AgentNodeMaintenance(nil, req)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try with the root token.
|
// Try with the root token.
|
||||||
req, err = http.NewRequest(
|
req, _ = http.NewRequest("PUT", "/v1/agent/self/maintenance?enable=true&reason=broken&token=root", nil)
|
||||||
"PUT", "/v1/agent/self/maintenance?enable=true&reason=broken&token=root", nil)
|
if _, err := srv.AgentNodeMaintenance(nil, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
_, err = srv.AgentNodeMaintenance(nil, req)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1885,10 +1629,7 @@ func TestAgent_RegisterCheck_Service(t *testing.T) {
|
|||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
// First register the service
|
// First register the service
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/service/register", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/service/register", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
args := &ServiceDefinition{
|
args := &ServiceDefinition{
|
||||||
Name: "memcache",
|
Name: "memcache",
|
||||||
Port: 8000,
|
Port: 8000,
|
||||||
@ -1903,10 +1644,7 @@ func TestAgent_RegisterCheck_Service(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now register an additional check
|
// Now register an additional check
|
||||||
req, err = http.NewRequest("GET", "/v1/agent/check/register", nil)
|
req, _ = http.NewRequest("GET", "/v1/agent/check/register", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
checkArgs := &CheckDefinition{
|
checkArgs := &CheckDefinition{
|
||||||
Name: "memcache_check2",
|
Name: "memcache_check2",
|
||||||
ServiceID: "memcache",
|
ServiceID: "memcache",
|
||||||
@ -2007,13 +1745,8 @@ func TestAgent_Monitor_ACLDeny(t *testing.T) {
|
|||||||
defer srv.agent.Shutdown()
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
// Try without a token.
|
// Try without a token.
|
||||||
req, err := http.NewRequest("GET", "/v1/agent/monitor", nil)
|
req, _ := http.NewRequest("GET", "/v1/agent/monitor", nil)
|
||||||
if err != nil {
|
if _, err := srv.AgentMonitor(nil, req); err != errPermissionDenied {
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = srv.AgentMonitor(nil, req)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,10 +23,7 @@ func TestCatalogRegister(t *testing.T) {
|
|||||||
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
||||||
|
|
||||||
// Register node
|
// Register node
|
||||||
req, err := http.NewRequest("GET", "/v1/catalog/register", nil)
|
req, _ := http.NewRequest("GET", "/v1/catalog/register", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
args := &structs.RegisterRequest{
|
args := &structs.RegisterRequest{
|
||||||
Node: "foo",
|
Node: "foo",
|
||||||
Address: "127.0.0.1",
|
Address: "127.0.0.1",
|
||||||
@ -97,10 +94,7 @@ func TestCatalogDeregister(t *testing.T) {
|
|||||||
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
||||||
|
|
||||||
// Register node
|
// Register node
|
||||||
req, err := http.NewRequest("GET", "/v1/catalog/deregister", nil)
|
req, _ := http.NewRequest("GET", "/v1/catalog/deregister", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
args := &structs.DeregisterRequest{
|
args := &structs.DeregisterRequest{
|
||||||
Node: "foo",
|
Node: "foo",
|
||||||
}
|
}
|
||||||
@ -156,11 +150,7 @@ func TestCatalogNodes(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/catalog/nodes?dc=dc1", nil)
|
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?dc=dc1", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.CatalogNodes(resp, req)
|
obj, err := srv.CatalogNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -199,11 +189,7 @@ func TestCatalogNodes_MetaFilter(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/catalog/nodes?node-meta=somekey:somevalue", nil)
|
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?node-meta=somekey:somevalue", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.CatalogNodes(resp, req)
|
obj, err := srv.CatalogNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -278,11 +264,7 @@ func TestCatalogNodes_WanTranslation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Query nodes in DC2 from DC1.
|
// Query nodes in DC2 from DC1.
|
||||||
req, err := http.NewRequest("GET", "/v1/catalog/nodes?dc=dc2", nil)
|
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?dc=dc2", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp1 := httptest.NewRecorder()
|
resp1 := httptest.NewRecorder()
|
||||||
obj1, err1 := srv1.CatalogNodes(resp1, req)
|
obj1, err1 := srv1.CatalogNodes(resp1, req)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
@ -362,12 +344,7 @@ func TestCatalogNodes_Blocking(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
// Do a blocking read
|
// Do a blocking read
|
||||||
req, err := http.NewRequest("GET",
|
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/catalog/nodes?wait=60s&index=%d", out.Index), nil)
|
||||||
fmt.Sprintf("/v1/catalog/nodes?wait=60s&index=%d", out.Index), nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.CatalogNodes(resp, req)
|
obj, err := srv.CatalogNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -419,11 +396,7 @@ func TestCatalogNodes_DistanceSort(t *testing.T) {
|
|||||||
|
|
||||||
// Nobody has coordinates set so this will still return them in the
|
// Nobody has coordinates set so this will still return them in the
|
||||||
// order they are indexed.
|
// order they are indexed.
|
||||||
req, err := http.NewRequest("GET", "/v1/catalog/nodes?dc=dc1&near=foo", nil)
|
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?dc=dc1&near=foo", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.CatalogNodes(resp, req)
|
obj, err := srv.CatalogNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -457,11 +430,7 @@ func TestCatalogNodes_DistanceSort(t *testing.T) {
|
|||||||
time.Sleep(300 * time.Millisecond)
|
time.Sleep(300 * time.Millisecond)
|
||||||
|
|
||||||
// Query again and now foo should have moved to the front of the line.
|
// Query again and now foo should have moved to the front of the line.
|
||||||
req, err = http.NewRequest("GET", "/v1/catalog/nodes?dc=dc1&near=foo", nil)
|
req, _ = http.NewRequest("GET", "/v1/catalog/nodes?dc=dc1&near=foo", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.CatalogNodes(resp, req)
|
obj, err = srv.CatalogNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -507,11 +476,7 @@ func TestCatalogServices(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/catalog/services?dc=dc1", nil)
|
req, _ := http.NewRequest("GET", "/v1/catalog/services?dc=dc1", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.CatalogServices(resp, req)
|
obj, err := srv.CatalogServices(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -552,11 +517,7 @@ func TestCatalogServices_NodeMetaFilter(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/catalog/services?node-meta=somekey:somevalue", nil)
|
req, _ := http.NewRequest("GET", "/v1/catalog/services?node-meta=somekey:somevalue", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.CatalogServices(resp, req)
|
obj, err := srv.CatalogServices(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -584,11 +545,7 @@ func TestCatalogServiceNodes(t *testing.T) {
|
|||||||
|
|
||||||
// Make sure an empty list is returned, not a nil
|
// Make sure an empty list is returned, not a nil
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("GET", "/v1/catalog/service/api?tag=a", nil)
|
req, _ := http.NewRequest("GET", "/v1/catalog/service/api?tag=a", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.CatalogServiceNodes(resp, req)
|
obj, err := srv.CatalogServiceNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -619,11 +576,7 @@ func TestCatalogServiceNodes(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/catalog/service/api?tag=a", nil)
|
req, _ := http.NewRequest("GET", "/v1/catalog/service/api?tag=a", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.CatalogServiceNodes(resp, req)
|
obj, err := srv.CatalogServiceNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -648,11 +601,7 @@ func TestCatalogServiceNodes_NodeMetaFilter(t *testing.T) {
|
|||||||
|
|
||||||
// Make sure an empty list is returned, not a nil
|
// Make sure an empty list is returned, not a nil
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("GET", "/v1/catalog/service/api?node-meta=somekey:somevalue", nil)
|
req, _ := http.NewRequest("GET", "/v1/catalog/service/api?node-meta=somekey:somevalue", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.CatalogServiceNodes(resp, req)
|
obj, err := srv.CatalogServiceNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -685,11 +634,7 @@ func TestCatalogServiceNodes_NodeMetaFilter(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/catalog/service/api?node-meta=somekey:somevalue", nil)
|
req, _ := http.NewRequest("GET", "/v1/catalog/service/api?node-meta=somekey:somevalue", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.CatalogServiceNodes(resp, req)
|
obj, err := srv.CatalogServiceNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -760,11 +705,7 @@ func TestCatalogServiceNodes_WanTranslation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Query for the node in DC2 from DC1.
|
// Query for the node in DC2 from DC1.
|
||||||
req, err := http.NewRequest("GET", "/v1/catalog/service/http_wan_translation_test?dc=dc2", nil)
|
req, _ := http.NewRequest("GET", "/v1/catalog/service/http_wan_translation_test?dc=dc2", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp1 := httptest.NewRecorder()
|
resp1 := httptest.NewRecorder()
|
||||||
obj1, err1 := srv1.CatalogServiceNodes(resp1, req)
|
obj1, err1 := srv1.CatalogServiceNodes(resp1, req)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
@ -824,11 +765,7 @@ func TestCatalogServiceNodes_DistanceSort(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/catalog/service/api?tag=a", nil)
|
req, _ := http.NewRequest("GET", "/v1/catalog/service/api?tag=a", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
args = &structs.RegisterRequest{
|
args = &structs.RegisterRequest{
|
||||||
Datacenter: "dc1",
|
Datacenter: "dc1",
|
||||||
Node: "foo",
|
Node: "foo",
|
||||||
@ -844,11 +781,7 @@ func TestCatalogServiceNodes_DistanceSort(t *testing.T) {
|
|||||||
|
|
||||||
// Nobody has coordinates set so this will still return them in the
|
// Nobody has coordinates set so this will still return them in the
|
||||||
// order they are indexed.
|
// order they are indexed.
|
||||||
req, err = http.NewRequest("GET", "/v1/catalog/service/api?tag=a&near=foo", nil)
|
req, _ = http.NewRequest("GET", "/v1/catalog/service/api?tag=a&near=foo", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.CatalogServiceNodes(resp, req)
|
obj, err := srv.CatalogServiceNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -879,11 +812,7 @@ func TestCatalogServiceNodes_DistanceSort(t *testing.T) {
|
|||||||
time.Sleep(300 * time.Millisecond)
|
time.Sleep(300 * time.Millisecond)
|
||||||
|
|
||||||
// Query again and now foo should have moved to the front of the line.
|
// Query again and now foo should have moved to the front of the line.
|
||||||
req, err = http.NewRequest("GET", "/v1/catalog/service/api?tag=a&near=foo", nil)
|
req, _ = http.NewRequest("GET", "/v1/catalog/service/api?tag=a&near=foo", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.CatalogServiceNodes(resp, req)
|
obj, err = srv.CatalogServiceNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -927,11 +856,7 @@ func TestCatalogNodeServices(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/catalog/node/foo?dc=dc1", nil)
|
req, _ := http.NewRequest("GET", "/v1/catalog/node/foo?dc=dc1", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.CatalogNodeServices(resp, req)
|
obj, err := srv.CatalogNodeServices(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1001,10 +926,7 @@ func TestCatalogNodeServices_WanTranslation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Query for the node in DC2 from DC1.
|
// Query for the node in DC2 from DC1.
|
||||||
req, err := http.NewRequest("GET", "/v1/catalog/node/foo?dc=dc2", nil)
|
req, _ := http.NewRequest("GET", "/v1/catalog/node/foo?dc=dc2", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
resp1 := httptest.NewRecorder()
|
resp1 := httptest.NewRecorder()
|
||||||
obj1, err1 := srv1.CatalogNodeServices(resp1, req)
|
obj1, err1 := srv1.CatalogNodeServices(resp1, req)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
|
@ -20,11 +20,7 @@ func TestCoordinate_Datacenters(t *testing.T) {
|
|||||||
|
|
||||||
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/coordinate/datacenters", nil)
|
req, _ := http.NewRequest("GET", "/v1/coordinate/datacenters", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.CoordinateDatacenters(resp, req)
|
obj, err := srv.CoordinateDatacenters(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -49,11 +45,7 @@ func TestCoordinate_Nodes(t *testing.T) {
|
|||||||
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
||||||
|
|
||||||
// Make sure an empty list is non-nil.
|
// Make sure an empty list is non-nil.
|
||||||
req, err := http.NewRequest("GET", "/v1/coordinate/nodes?dc=dc1", nil)
|
req, _ := http.NewRequest("GET", "/v1/coordinate/nodes?dc=dc1", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.CoordinateNodes(resp, req)
|
obj, err := srv.CoordinateNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -102,11 +94,7 @@ func TestCoordinate_Nodes(t *testing.T) {
|
|||||||
time.Sleep(300 * time.Millisecond)
|
time.Sleep(300 * time.Millisecond)
|
||||||
|
|
||||||
// Query back and check the nodes are present and sorted correctly.
|
// Query back and check the nodes are present and sorted correctly.
|
||||||
req, err = http.NewRequest("GET", "/v1/coordinate/nodes?dc=dc1", nil)
|
req, _ = http.NewRequest("GET", "/v1/coordinate/nodes?dc=dc1", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.CoordinateNodes(resp, req)
|
obj, err = srv.CoordinateNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -18,10 +18,7 @@ func TestEventFire(t *testing.T) {
|
|||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer([]byte("test"))
|
body := bytes.NewBuffer([]byte("test"))
|
||||||
url := "/v1/event/fire/test?node=Node&service=foo&tag=bar"
|
url := "/v1/event/fire/test?node=Node&service=foo&tag=bar"
|
||||||
req, err := http.NewRequest("PUT", url, body)
|
req, _ := http.NewRequest("PUT", url, body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.EventFire(resp, req)
|
obj, err := srv.EventFire(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -84,10 +81,7 @@ func TestEventFire_token(t *testing.T) {
|
|||||||
for _, c := range tcases {
|
for _, c := range tcases {
|
||||||
// Try to fire the event over the HTTP interface
|
// Try to fire the event over the HTTP interface
|
||||||
url := fmt.Sprintf("/v1/event/fire/%s?token=%s", c.event, token)
|
url := fmt.Sprintf("/v1/event/fire/%s?token=%s", c.event, token)
|
||||||
req, err := http.NewRequest("PUT", url, nil)
|
req, _ := http.NewRequest("PUT", url, nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
if _, err := srv.EventFire(resp, req); err != nil {
|
if _, err := srv.EventFire(resp, req); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
@ -124,10 +118,7 @@ func TestEventList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
retry.Run(t, func(r *retry.R) {
|
retry.Run(t, func(r *retry.R) {
|
||||||
req, err := http.NewRequest("GET", "/v1/event/list", nil)
|
req, _ := http.NewRequest("GET", "/v1/event/list", nil)
|
||||||
if err != nil {
|
|
||||||
r.Fatal(err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.EventList(resp, req)
|
obj, err := srv.EventList(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -162,10 +153,7 @@ func TestEventList_Filter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
retry.Run(t, func(r *retry.R) {
|
retry.Run(t, func(r *retry.R) {
|
||||||
req, err := http.NewRequest("GET", "/v1/event/list?name=foo", nil)
|
req, _ := http.NewRequest("GET", "/v1/event/list?name=foo", nil)
|
||||||
if err != nil {
|
|
||||||
r.Fatal(err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.EventList(resp, req)
|
obj, err := srv.EventList(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -202,10 +190,7 @@ func TestEventList_ACLFilter(t *testing.T) {
|
|||||||
// Try no token.
|
// Try no token.
|
||||||
{
|
{
|
||||||
retry.Run(t, func(r *retry.R) {
|
retry.Run(t, func(r *retry.R) {
|
||||||
req, err := http.NewRequest("GET", "/v1/event/list", nil)
|
req, _ := http.NewRequest("GET", "/v1/event/list", nil)
|
||||||
if err != nil {
|
|
||||||
r.Fatal(err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.EventList(resp, req)
|
obj, err := srv.EventList(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -225,10 +210,7 @@ func TestEventList_ACLFilter(t *testing.T) {
|
|||||||
// Try the root token.
|
// Try the root token.
|
||||||
{
|
{
|
||||||
retry.Run(t, func(r *retry.R) {
|
retry.Run(t, func(r *retry.R) {
|
||||||
req, err := http.NewRequest("GET", "/v1/event/list?token=root", nil)
|
req, _ := http.NewRequest("GET", "/v1/event/list?token=root", nil)
|
||||||
if err != nil {
|
|
||||||
r.Fatal(err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.EventList(resp, req)
|
obj, err := srv.EventList(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -255,13 +237,9 @@ func TestEventList_Blocking(t *testing.T) {
|
|||||||
|
|
||||||
var index string
|
var index string
|
||||||
retry.Run(t, func(r *retry.R) {
|
retry.Run(t, func(r *retry.R) {
|
||||||
req, err := http.NewRequest("GET", "/v1/event/list", nil)
|
req, _ := http.NewRequest("GET", "/v1/event/list", nil)
|
||||||
if err != nil {
|
|
||||||
r.Fatal(err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.EventList(resp, req)
|
if _, err := srv.EventList(resp, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
r.Fatal(err)
|
r.Fatal(err)
|
||||||
}
|
}
|
||||||
header := resp.Header().Get("X-Consul-Index")
|
header := resp.Header().Get("X-Consul-Index")
|
||||||
@ -281,10 +259,7 @@ func TestEventList_Blocking(t *testing.T) {
|
|||||||
|
|
||||||
retry.Run(t, func(r *retry.R) {
|
retry.Run(t, func(r *retry.R) {
|
||||||
url := "/v1/event/list?index=" + index
|
url := "/v1/event/list?index=" + index
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, _ := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
|
||||||
r.Fatal(err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.EventList(resp, req)
|
obj, err := srv.EventList(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -322,10 +297,7 @@ func TestEventList_EventBufOrder(t *testing.T) {
|
|||||||
// filtering on a list of > 1 matching event.
|
// filtering on a list of > 1 matching event.
|
||||||
retry.Run(t, func(r *retry.R) {
|
retry.Run(t, func(r *retry.R) {
|
||||||
url := "/v1/event/list?name=foo"
|
url := "/v1/event/list?name=foo"
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, _ := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
|
||||||
r.Fatal(err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.EventList(resp, req)
|
obj, err := srv.EventList(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -17,11 +17,7 @@ import (
|
|||||||
|
|
||||||
func TestHealthChecksInState(t *testing.T) {
|
func TestHealthChecksInState(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
req, err := http.NewRequest("GET", "/v1/health/state/warning?dc=dc1", nil)
|
req, _ := http.NewRequest("GET", "/v1/health/state/warning?dc=dc1", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
retry.Run(t, func(r *retry.R) {
|
retry.Run(t, func(r *retry.R) {
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.HealthChecksInState(resp, req)
|
obj, err := srv.HealthChecksInState(resp, req)
|
||||||
@ -41,11 +37,7 @@ func TestHealthChecksInState(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
req, err := http.NewRequest("GET", "/v1/health/state/passing?dc=dc1", nil)
|
req, _ := http.NewRequest("GET", "/v1/health/state/passing?dc=dc1", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
retry.Run(t, func(r *retry.R) {
|
retry.Run(t, func(r *retry.R) {
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.HealthChecksInState(resp, req)
|
obj, err := srv.HealthChecksInState(resp, req)
|
||||||
@ -83,11 +75,7 @@ func TestHealthChecksInState_NodeMetaFilter(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/health/state/critical?node-meta=somekey:somevalue", nil)
|
req, _ := http.NewRequest("GET", "/v1/health/state/critical?node-meta=somekey:somevalue", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
retry.Run(t, func(r *retry.R) {
|
retry.Run(t, func(r *retry.R) {
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.HealthChecksInState(resp, req)
|
obj, err := srv.HealthChecksInState(resp, req)
|
||||||
@ -136,11 +124,7 @@ func TestHealthChecksInState_DistanceSort(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/health/state/critical?dc=dc1&near=foo", nil)
|
req, _ := http.NewRequest("GET", "/v1/health/state/critical?dc=dc1&near=foo", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.HealthChecksInState(resp, req)
|
obj, err := srv.HealthChecksInState(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -196,11 +180,7 @@ func TestHealthNodeChecks(t *testing.T) {
|
|||||||
|
|
||||||
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/health/node/nope?dc=dc1", nil)
|
req, _ := http.NewRequest("GET", "/v1/health/node/nope?dc=dc1", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.HealthNodeChecks(resp, req)
|
obj, err := srv.HealthNodeChecks(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -214,12 +194,7 @@ func TestHealthNodeChecks(t *testing.T) {
|
|||||||
t.Fatalf("bad: %v", obj)
|
t.Fatalf("bad: %v", obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err = http.NewRequest("GET",
|
req, _ = http.NewRequest("GET", fmt.Sprintf("/v1/health/node/%s?dc=dc1", srv.agent.config.NodeName), nil)
|
||||||
fmt.Sprintf("/v1/health/node/%s?dc=dc1", srv.agent.config.NodeName), nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.HealthNodeChecks(resp, req)
|
obj, err = srv.HealthNodeChecks(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -242,11 +217,7 @@ func TestHealthServiceChecks(t *testing.T) {
|
|||||||
|
|
||||||
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1", nil)
|
req, _ := http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.HealthServiceChecks(resp, req)
|
obj, err := srv.HealthServiceChecks(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -277,11 +248,7 @@ func TestHealthServiceChecks(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1", nil)
|
req, _ = http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.HealthServiceChecks(resp, req)
|
obj, err = srv.HealthServiceChecks(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -304,11 +271,7 @@ func TestHealthServiceChecks_NodeMetaFilter(t *testing.T) {
|
|||||||
|
|
||||||
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1&node-meta=somekey:somevalue", nil)
|
req, _ := http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1&node-meta=somekey:somevalue", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.HealthServiceChecks(resp, req)
|
obj, err := srv.HealthServiceChecks(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -340,11 +303,7 @@ func TestHealthServiceChecks_NodeMetaFilter(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1&node-meta=somekey:somevalue", nil)
|
req, _ = http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1&node-meta=somekey:somevalue", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.HealthServiceChecks(resp, req)
|
obj, err = srv.HealthServiceChecks(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -393,11 +352,7 @@ func TestHealthServiceChecks_DistanceSort(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/health/checks/test?dc=dc1&near=foo", nil)
|
req, _ := http.NewRequest("GET", "/v1/health/checks/test?dc=dc1&near=foo", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.HealthServiceChecks(resp, req)
|
obj, err := srv.HealthServiceChecks(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -453,11 +408,7 @@ func TestHealthServiceNodes(t *testing.T) {
|
|||||||
|
|
||||||
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/health/service/consul?dc=dc1", nil)
|
req, _ := http.NewRequest("GET", "/v1/health/service/consul?dc=dc1", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.HealthServiceNodes(resp, req)
|
obj, err := srv.HealthServiceNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -472,11 +423,7 @@ func TestHealthServiceNodes(t *testing.T) {
|
|||||||
t.Fatalf("bad: %v", obj)
|
t.Fatalf("bad: %v", obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/v1/health/service/nope?dc=dc1", nil)
|
req, _ = http.NewRequest("GET", "/v1/health/service/nope?dc=dc1", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.HealthServiceNodes(resp, req)
|
obj, err = srv.HealthServiceNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -506,11 +453,7 @@ func TestHealthServiceNodes(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/v1/health/service/test?dc=dc1", nil)
|
req, _ = http.NewRequest("GET", "/v1/health/service/test?dc=dc1", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.HealthServiceNodes(resp, req)
|
obj, err = srv.HealthServiceNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -534,11 +477,7 @@ func TestHealthServiceNodes_NodeMetaFilter(t *testing.T) {
|
|||||||
|
|
||||||
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/health/service/consul?dc=dc1&node-meta=somekey:somevalue", nil)
|
req, _ := http.NewRequest("GET", "/v1/health/service/consul?dc=dc1&node-meta=somekey:somevalue", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.HealthServiceNodes(resp, req)
|
obj, err := srv.HealthServiceNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -569,11 +508,7 @@ func TestHealthServiceNodes_NodeMetaFilter(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/v1/health/service/test?dc=dc1&node-meta=somekey:somevalue", nil)
|
req, _ = http.NewRequest("GET", "/v1/health/service/test?dc=dc1&node-meta=somekey:somevalue", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.HealthServiceNodes(resp, req)
|
obj, err = srv.HealthServiceNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -623,11 +558,7 @@ func TestHealthServiceNodes_DistanceSort(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/health/service/test?dc=dc1&near=foo", nil)
|
req, _ := http.NewRequest("GET", "/v1/health/service/test?dc=dc1&near=foo", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.HealthServiceNodes(resp, req)
|
obj, err := srv.HealthServiceNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -701,11 +632,7 @@ func TestHealthServiceNodes_PassingFilter(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/health/service/consul?passing", nil)
|
req, _ := http.NewRequest("GET", "/v1/health/service/consul?passing", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.HealthServiceNodes(resp, req)
|
obj, err := srv.HealthServiceNodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -776,10 +703,7 @@ func TestHealthServiceNodes_WanTranslation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Query for a service in DC2 from DC1.
|
// Query for a service in DC2 from DC1.
|
||||||
req, err := http.NewRequest("GET", "/v1/health/service/http_wan_translation_test?dc=dc2", nil)
|
req, _ := http.NewRequest("GET", "/v1/health/service/http_wan_translation_test?dc=dc2", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
resp1 := httptest.NewRecorder()
|
resp1 := httptest.NewRecorder()
|
||||||
obj1, err1 := srv1.HealthServiceNodes(resp1, req)
|
obj1, err1 := srv1.HealthServiceNodes(resp1, req)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
|
@ -357,7 +357,6 @@ func TestHTTP_wrap_obfuscateLog(t *testing.T) {
|
|||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
req, _ := http.NewRequest("GET", "/some/url?token=secret1&token=secret2", nil)
|
req, _ := http.NewRequest("GET", "/some/url?token=secret1&token=secret2", nil)
|
||||||
|
|
||||||
handler := func(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
handler := func(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@ -414,11 +413,7 @@ func TestParseSource(t *testing.T) {
|
|||||||
|
|
||||||
// Default is agent's DC and no node (since the user didn't care, then
|
// Default is agent's DC and no node (since the user didn't care, then
|
||||||
// just give them the cheapest possible query).
|
// just give them the cheapest possible query).
|
||||||
req, err := http.NewRequest("GET",
|
req, _ := http.NewRequest("GET", "/v1/catalog/nodes", nil)
|
||||||
"/v1/catalog/nodes", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
source := structs.QuerySource{}
|
source := structs.QuerySource{}
|
||||||
srv.parseSource(req, &source)
|
srv.parseSource(req, &source)
|
||||||
if source.Datacenter != "dc1" || source.Node != "" {
|
if source.Datacenter != "dc1" || source.Node != "" {
|
||||||
@ -426,11 +421,7 @@ func TestParseSource(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Adding the source parameter should set that node.
|
// Adding the source parameter should set that node.
|
||||||
req, err = http.NewRequest("GET",
|
req, _ = http.NewRequest("GET", "/v1/catalog/nodes?near=bob", nil)
|
||||||
"/v1/catalog/nodes?near=bob", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
source = structs.QuerySource{}
|
source = structs.QuerySource{}
|
||||||
srv.parseSource(req, &source)
|
srv.parseSource(req, &source)
|
||||||
if source.Datacenter != "dc1" || source.Node != "bob" {
|
if source.Datacenter != "dc1" || source.Node != "bob" {
|
||||||
@ -439,11 +430,7 @@ func TestParseSource(t *testing.T) {
|
|||||||
|
|
||||||
// We should follow whatever dc parameter was given so that the node is
|
// We should follow whatever dc parameter was given so that the node is
|
||||||
// looked up correctly on the receiving end.
|
// looked up correctly on the receiving end.
|
||||||
req, err = http.NewRequest("GET",
|
req, _ = http.NewRequest("GET", "/v1/catalog/nodes?near=bob&dc=foo", nil)
|
||||||
"/v1/catalog/nodes?near=bob&dc=foo", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
source = structs.QuerySource{}
|
source = structs.QuerySource{}
|
||||||
srv.parseSource(req, &source)
|
srv.parseSource(req, &source)
|
||||||
if source.Datacenter != "foo" || source.Node != "bob" {
|
if source.Datacenter != "foo" || source.Node != "bob" {
|
||||||
@ -451,11 +438,7 @@ func TestParseSource(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The magic "_agent" node name will use the agent's local node name.
|
// The magic "_agent" node name will use the agent's local node name.
|
||||||
req, err = http.NewRequest("GET",
|
req, _ = http.NewRequest("GET", "/v1/catalog/nodes?near=_agent", nil)
|
||||||
"/v1/catalog/nodes?near=_agent", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
source = structs.QuerySource{}
|
source = structs.QuerySource{}
|
||||||
srv.parseSource(req, &source)
|
srv.parseSource(req, &source)
|
||||||
if source.Datacenter != "dc1" || source.Node != srv.agent.config.NodeName {
|
if source.Datacenter != "dc1" || source.Node != srv.agent.config.NodeName {
|
||||||
@ -467,12 +450,7 @@ func TestParseWait(t *testing.T) {
|
|||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
var b structs.QueryOptions
|
var b structs.QueryOptions
|
||||||
|
|
||||||
req, err := http.NewRequest("GET",
|
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?wait=60s&index=1000", nil)
|
||||||
"/v1/catalog/nodes?wait=60s&index=1000", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if d := parseWait(resp, req, &b); d {
|
if d := parseWait(resp, req, &b); d {
|
||||||
t.Fatalf("unexpected done")
|
t.Fatalf("unexpected done")
|
||||||
}
|
}
|
||||||
@ -489,12 +467,7 @@ func TestParseWait_InvalidTime(t *testing.T) {
|
|||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
var b structs.QueryOptions
|
var b structs.QueryOptions
|
||||||
|
|
||||||
req, err := http.NewRequest("GET",
|
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?wait=60foo&index=1000", nil)
|
||||||
"/v1/catalog/nodes?wait=60foo&index=1000", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if d := parseWait(resp, req, &b); !d {
|
if d := parseWait(resp, req, &b); !d {
|
||||||
t.Fatalf("expected done")
|
t.Fatalf("expected done")
|
||||||
}
|
}
|
||||||
@ -508,12 +481,7 @@ func TestParseWait_InvalidIndex(t *testing.T) {
|
|||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
var b structs.QueryOptions
|
var b structs.QueryOptions
|
||||||
|
|
||||||
req, err := http.NewRequest("GET",
|
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?wait=60s&index=foo", nil)
|
||||||
"/v1/catalog/nodes?wait=60s&index=foo", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if d := parseWait(resp, req, &b); !d {
|
if d := parseWait(resp, req, &b); !d {
|
||||||
t.Fatalf("expected done")
|
t.Fatalf("expected done")
|
||||||
}
|
}
|
||||||
@ -527,12 +495,7 @@ func TestParseConsistency(t *testing.T) {
|
|||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
var b structs.QueryOptions
|
var b structs.QueryOptions
|
||||||
|
|
||||||
req, err := http.NewRequest("GET",
|
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?stale", nil)
|
||||||
"/v1/catalog/nodes?stale", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if d := parseConsistency(resp, req, &b); d {
|
if d := parseConsistency(resp, req, &b); d {
|
||||||
t.Fatalf("unexpected done")
|
t.Fatalf("unexpected done")
|
||||||
}
|
}
|
||||||
@ -545,12 +508,7 @@ func TestParseConsistency(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
b = structs.QueryOptions{}
|
b = structs.QueryOptions{}
|
||||||
req, err = http.NewRequest("GET",
|
req, _ = http.NewRequest("GET", "/v1/catalog/nodes?consistent", nil)
|
||||||
"/v1/catalog/nodes?consistent", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if d := parseConsistency(resp, req, &b); d {
|
if d := parseConsistency(resp, req, &b); d {
|
||||||
t.Fatalf("unexpected done")
|
t.Fatalf("unexpected done")
|
||||||
}
|
}
|
||||||
@ -567,12 +525,7 @@ func TestParseConsistency_Invalid(t *testing.T) {
|
|||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
var b structs.QueryOptions
|
var b structs.QueryOptions
|
||||||
|
|
||||||
req, err := http.NewRequest("GET",
|
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?stale&consistent", nil)
|
||||||
"/v1/catalog/nodes?stale&consistent", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if d := parseConsistency(resp, req, &b); !d {
|
if d := parseConsistency(resp, req, &b); !d {
|
||||||
t.Fatalf("expected done")
|
t.Fatalf("expected done")
|
||||||
}
|
}
|
||||||
@ -586,33 +539,15 @@ func TestParseConsistency_Invalid(t *testing.T) {
|
|||||||
func TestACLResolution(t *testing.T) {
|
func TestACLResolution(t *testing.T) {
|
||||||
var token string
|
var token string
|
||||||
// Request without token
|
// Request without token
|
||||||
req, err := http.NewRequest("GET",
|
req, _ := http.NewRequest("GET", "/v1/catalog/nodes", nil)
|
||||||
"/v1/catalog/nodes", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Request with explicit token
|
// Request with explicit token
|
||||||
reqToken, err := http.NewRequest("GET",
|
reqToken, _ := http.NewRequest("GET", "/v1/catalog/nodes?token=foo", nil)
|
||||||
"/v1/catalog/nodes?token=foo", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Request with header token only
|
// Request with header token only
|
||||||
reqHeaderToken, err := http.NewRequest("GET",
|
reqHeaderToken, _ := http.NewRequest("GET", "/v1/catalog/nodes", nil)
|
||||||
"/v1/catalog/nodes", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
reqHeaderToken.Header.Add("X-Consul-Token", "bar")
|
reqHeaderToken.Header.Add("X-Consul-Token", "bar")
|
||||||
|
|
||||||
// Request with header and querystring tokens
|
// Request with header and querystring tokens
|
||||||
reqBothTokens, err := http.NewRequest("GET",
|
reqBothTokens, _ := http.NewRequest("GET", "/v1/catalog/nodes?token=baz", nil)
|
||||||
"/v1/catalog/nodes?token=baz", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
reqBothTokens.Header.Add("X-Consul-Token", "zap")
|
reqBothTokens.Header.Add("X-Consul-Token", "zap")
|
||||||
|
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
@ -706,11 +641,7 @@ func TestScadaHTTP(t *testing.T) {
|
|||||||
|
|
||||||
func TestEnableWebUI(t *testing.T) {
|
func TestEnableWebUI(t *testing.T) {
|
||||||
httpTestWithConfig(t, func(s *HTTPServer) {
|
httpTestWithConfig(t, func(s *HTTPServer) {
|
||||||
req, err := http.NewRequest("GET", "/ui/", nil)
|
req, _ := http.NewRequest("GET", "/ui/", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform the request
|
// Perform the request
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
s.mux.ServeHTTP(resp, req)
|
s.mux.ServeHTTP(resp, req)
|
||||||
|
@ -31,11 +31,7 @@ func TestKVSEndpoint_PUT_GET_DELETE(t *testing.T) {
|
|||||||
|
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
buf := bytes.NewBuffer([]byte("test"))
|
buf := bytes.NewBuffer([]byte("test"))
|
||||||
req, err := http.NewRequest("PUT", "/v1/kv/"+key, buf)
|
req, _ := http.NewRequest("PUT", "/v1/kv/"+key, buf)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -48,11 +44,7 @@ func TestKVSEndpoint_PUT_GET_DELETE(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
req, err := http.NewRequest("GET", "/v1/kv/"+key, nil)
|
req, _ := http.NewRequest("GET", "/v1/kv/"+key, nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -75,14 +67,9 @@ func TestKVSEndpoint_PUT_GET_DELETE(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
req, err := http.NewRequest("DELETE", "/v1/kv/"+key, nil)
|
req, _ := http.NewRequest("DELETE", "/v1/kv/"+key, nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.KVSEndpoint(resp, req)
|
if _, err := srv.KVSEndpoint(resp, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,11 +93,7 @@ func TestKVSEndpoint_Recurse(t *testing.T) {
|
|||||||
|
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
buf := bytes.NewBuffer([]byte("test"))
|
buf := bytes.NewBuffer([]byte("test"))
|
||||||
req, err := http.NewRequest("PUT", "/v1/kv/"+key, buf)
|
req, _ := http.NewRequest("PUT", "/v1/kv/"+key, buf)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -124,11 +107,7 @@ func TestKVSEndpoint_Recurse(t *testing.T) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
// Get all the keys
|
// Get all the keys
|
||||||
req, err := http.NewRequest("GET", "/v1/kv/?recurse", nil)
|
req, _ := http.NewRequest("GET", "/v1/kv/?recurse", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -153,25 +132,16 @@ func TestKVSEndpoint_Recurse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
req, err := http.NewRequest("DELETE", "/v1/kv/?recurse", nil)
|
req, _ := http.NewRequest("DELETE", "/v1/kv/?recurse", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.KVSEndpoint(resp, req)
|
if _, err := srv.KVSEndpoint(resp, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// Get all the keys
|
// Get all the keys
|
||||||
req, err := http.NewRequest("GET", "/v1/kv/?recurse", nil)
|
req, _ := http.NewRequest("GET", "/v1/kv/?recurse", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -194,11 +164,7 @@ func TestKVSEndpoint_DELETE_CAS(t *testing.T) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
buf := bytes.NewBuffer([]byte("test"))
|
buf := bytes.NewBuffer([]byte("test"))
|
||||||
req, err := http.NewRequest("PUT", "/v1/kv/test", buf)
|
req, _ := http.NewRequest("PUT", "/v1/kv/test", buf)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -210,11 +176,7 @@ func TestKVSEndpoint_DELETE_CAS(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/kv/test", nil)
|
req, _ := http.NewRequest("GET", "/v1/kv/test", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -225,12 +187,7 @@ func TestKVSEndpoint_DELETE_CAS(t *testing.T) {
|
|||||||
// Create a CAS request, bad index
|
// Create a CAS request, bad index
|
||||||
{
|
{
|
||||||
buf := bytes.NewBuffer([]byte("zip"))
|
buf := bytes.NewBuffer([]byte("zip"))
|
||||||
req, err := http.NewRequest("DELETE",
|
req, _ := http.NewRequest("DELETE", fmt.Sprintf("/v1/kv/test?cas=%d", d.ModifyIndex-1), buf)
|
||||||
fmt.Sprintf("/v1/kv/test?cas=%d", d.ModifyIndex-1), buf)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -245,12 +202,7 @@ func TestKVSEndpoint_DELETE_CAS(t *testing.T) {
|
|||||||
// Create a CAS request, good index
|
// Create a CAS request, good index
|
||||||
{
|
{
|
||||||
buf := bytes.NewBuffer([]byte("zip"))
|
buf := bytes.NewBuffer([]byte("zip"))
|
||||||
req, err := http.NewRequest("DELETE",
|
req, _ := http.NewRequest("DELETE", fmt.Sprintf("/v1/kv/test?cas=%d", d.ModifyIndex), buf)
|
||||||
fmt.Sprintf("/v1/kv/test?cas=%d", d.ModifyIndex), buf)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -281,11 +233,7 @@ func TestKVSEndpoint_CAS(t *testing.T) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
buf := bytes.NewBuffer([]byte("test"))
|
buf := bytes.NewBuffer([]byte("test"))
|
||||||
req, err := http.NewRequest("PUT", "/v1/kv/test?flags=50", buf)
|
req, _ := http.NewRequest("PUT", "/v1/kv/test?flags=50", buf)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -297,11 +245,7 @@ func TestKVSEndpoint_CAS(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/kv/test", nil)
|
req, _ := http.NewRequest("GET", "/v1/kv/test", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -317,12 +261,7 @@ func TestKVSEndpoint_CAS(t *testing.T) {
|
|||||||
// Create a CAS request, bad index
|
// Create a CAS request, bad index
|
||||||
{
|
{
|
||||||
buf := bytes.NewBuffer([]byte("zip"))
|
buf := bytes.NewBuffer([]byte("zip"))
|
||||||
req, err := http.NewRequest("PUT",
|
req, _ := http.NewRequest("PUT", fmt.Sprintf("/v1/kv/test?flags=42&cas=%d", d.ModifyIndex-1), buf)
|
||||||
fmt.Sprintf("/v1/kv/test?flags=42&cas=%d", d.ModifyIndex-1), buf)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -337,12 +276,7 @@ func TestKVSEndpoint_CAS(t *testing.T) {
|
|||||||
// Create a CAS request, good index
|
// Create a CAS request, good index
|
||||||
{
|
{
|
||||||
buf := bytes.NewBuffer([]byte("zip"))
|
buf := bytes.NewBuffer([]byte("zip"))
|
||||||
req, err := http.NewRequest("PUT",
|
req, _ := http.NewRequest("PUT", fmt.Sprintf("/v1/kv/test?flags=42&cas=%d", d.ModifyIndex), buf)
|
||||||
fmt.Sprintf("/v1/kv/test?flags=42&cas=%d", d.ModifyIndex), buf)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -386,11 +320,7 @@ func TestKVSEndpoint_ListKeys(t *testing.T) {
|
|||||||
|
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
buf := bytes.NewBuffer([]byte("test"))
|
buf := bytes.NewBuffer([]byte("test"))
|
||||||
req, err := http.NewRequest("PUT", "/v1/kv/"+key, buf)
|
req, _ := http.NewRequest("PUT", "/v1/kv/"+key, buf)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -404,11 +334,7 @@ func TestKVSEndpoint_ListKeys(t *testing.T) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
// Get all the keys
|
// Get all the keys
|
||||||
req, err := http.NewRequest("GET", "/v1/kv/?keys&seperator=/", nil)
|
req, _ := http.NewRequest("GET", "/v1/kv/?keys&seperator=/", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -432,12 +358,7 @@ func TestKVSEndpoint_AcquireRelease(t *testing.T) {
|
|||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
// Acquire the lock
|
// Acquire the lock
|
||||||
id := makeTestSession(t, srv)
|
id := makeTestSession(t, srv)
|
||||||
req, err := http.NewRequest("PUT",
|
req, _ := http.NewRequest("PUT", "/v1/kv/test?acquire="+id, bytes.NewReader(nil))
|
||||||
"/v1/kv/test?acquire="+id, bytes.NewReader(nil))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -448,10 +369,7 @@ func TestKVSEndpoint_AcquireRelease(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify we have the lock
|
// Verify we have the lock
|
||||||
req, err = http.NewRequest("GET", "/v1/kv/test", nil)
|
req, _ = http.NewRequest("GET", "/v1/kv/test", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.KVSEndpoint(resp, req)
|
obj, err = srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -465,11 +383,7 @@ func TestKVSEndpoint_AcquireRelease(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Release the lock
|
// Release the lock
|
||||||
req, err = http.NewRequest("PUT",
|
req, _ = http.NewRequest("PUT", "/v1/kv/test?release="+id, bytes.NewReader(nil))
|
||||||
"/v1/kv/test?release="+id, bytes.NewReader(nil))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.KVSEndpoint(resp, req)
|
obj, err = srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -480,10 +394,7 @@ func TestKVSEndpoint_AcquireRelease(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify we do not have the lock
|
// Verify we do not have the lock
|
||||||
req, err = http.NewRequest("GET", "/v1/kv/test", nil)
|
req, _ = http.NewRequest("GET", "/v1/kv/test", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.KVSEndpoint(resp, req)
|
obj, err = srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -501,10 +412,7 @@ func TestKVSEndpoint_AcquireRelease(t *testing.T) {
|
|||||||
func TestKVSEndpoint_GET_Raw(t *testing.T) {
|
func TestKVSEndpoint_GET_Raw(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
buf := bytes.NewBuffer([]byte("test"))
|
buf := bytes.NewBuffer([]byte("test"))
|
||||||
req, err := http.NewRequest("PUT", "/v1/kv/test", buf)
|
req, _ := http.NewRequest("PUT", "/v1/kv/test", buf)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -514,10 +422,7 @@ func TestKVSEndpoint_GET_Raw(t *testing.T) {
|
|||||||
t.Fatalf("should work")
|
t.Fatalf("should work")
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/v1/kv/test?raw", nil)
|
req, _ = http.NewRequest("GET", "/v1/kv/test?raw", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.KVSEndpoint(resp, req)
|
obj, err = srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -534,11 +439,7 @@ func TestKVSEndpoint_GET_Raw(t *testing.T) {
|
|||||||
|
|
||||||
func TestKVSEndpoint_PUT_ConflictingFlags(t *testing.T) {
|
func TestKVSEndpoint_PUT_ConflictingFlags(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
req, err := http.NewRequest("PUT", "/v1/kv/test?cas=0&acquire=xxx", nil)
|
req, _ := http.NewRequest("PUT", "/v1/kv/test?cas=0&acquire=xxx", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
if _, err := srv.KVSEndpoint(resp, req); err != nil {
|
if _, err := srv.KVSEndpoint(resp, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
@ -555,11 +456,7 @@ func TestKVSEndpoint_PUT_ConflictingFlags(t *testing.T) {
|
|||||||
|
|
||||||
func TestKVSEndpoint_DELETE_ConflictingFlags(t *testing.T) {
|
func TestKVSEndpoint_DELETE_ConflictingFlags(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
req, err := http.NewRequest("DELETE", "/v1/kv/test?recurse&cas=0", nil)
|
req, _ := http.NewRequest("DELETE", "/v1/kv/test?recurse&cas=0", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
if _, err := srv.KVSEndpoint(resp, req); err != nil {
|
if _, err := srv.KVSEndpoint(resp, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
|
@ -17,11 +17,7 @@ import (
|
|||||||
func TestOperator_RaftConfiguration(t *testing.T) {
|
func TestOperator_RaftConfiguration(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/operator/raft/configuration", body)
|
req, _ := http.NewRequest("GET", "/v1/operator/raft/configuration", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.OperatorRaftConfiguration(resp, req)
|
obj, err := srv.OperatorRaftConfiguration(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -45,15 +41,11 @@ func TestOperator_RaftConfiguration(t *testing.T) {
|
|||||||
func TestOperator_RaftPeer(t *testing.T) {
|
func TestOperator_RaftPeer(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("DELETE", "/v1/operator/raft/peer?address=nope", body)
|
req, _ := http.NewRequest("DELETE", "/v1/operator/raft/peer?address=nope", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we get this error, it proves we sent the address all the
|
// If we get this error, it proves we sent the address all the
|
||||||
// way through.
|
// way through.
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.OperatorRaftPeer(resp, req)
|
_, err := srv.OperatorRaftPeer(resp, req)
|
||||||
if err == nil || !strings.Contains(err.Error(),
|
if err == nil || !strings.Contains(err.Error(),
|
||||||
"address \"nope\" was not found in the Raft configuration") {
|
"address \"nope\" was not found in the Raft configuration") {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
@ -62,15 +54,11 @@ func TestOperator_RaftPeer(t *testing.T) {
|
|||||||
|
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("DELETE", "/v1/operator/raft/peer?id=nope", body)
|
req, _ := http.NewRequest("DELETE", "/v1/operator/raft/peer?id=nope", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we get this error, it proves we sent the ID all the
|
// If we get this error, it proves we sent the ID all the
|
||||||
// way through.
|
// way through.
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.OperatorRaftPeer(resp, req)
|
_, err := srv.OperatorRaftPeer(resp, req)
|
||||||
if err == nil || !strings.Contains(err.Error(),
|
if err == nil || !strings.Contains(err.Error(),
|
||||||
"id \"nope\" was not found in the Raft configuration") {
|
"id \"nope\" was not found in the Raft configuration") {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
@ -86,13 +74,9 @@ func TestOperator_KeyringInstall(t *testing.T) {
|
|||||||
}
|
}
|
||||||
httpTestWithConfig(t, func(srv *HTTPServer) {
|
httpTestWithConfig(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBufferString(fmt.Sprintf("{\"Key\":\"%s\"}", newKey))
|
body := bytes.NewBufferString(fmt.Sprintf("{\"Key\":\"%s\"}", newKey))
|
||||||
req, err := http.NewRequest("POST", "/v1/operator/keyring", body)
|
req, _ := http.NewRequest("POST", "/v1/operator/keyring", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.OperatorKeyringEndpoint(resp, req)
|
_, err := srv.OperatorKeyringEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
@ -123,11 +107,7 @@ func TestOperator_KeyringList(t *testing.T) {
|
|||||||
c.EncryptKey = key
|
c.EncryptKey = key
|
||||||
}
|
}
|
||||||
httpTestWithConfig(t, func(srv *HTTPServer) {
|
httpTestWithConfig(t, func(srv *HTTPServer) {
|
||||||
req, err := http.NewRequest("GET", "/v1/operator/keyring", nil)
|
req, _ := http.NewRequest("GET", "/v1/operator/keyring", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
r, err := srv.OperatorKeyringEndpoint(resp, req)
|
r, err := srv.OperatorKeyringEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -199,14 +179,9 @@ func TestOperator_KeyringRemove(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body := bytes.NewBufferString(fmt.Sprintf("{\"Key\":\"%s\"}", tempKey))
|
body := bytes.NewBufferString(fmt.Sprintf("{\"Key\":\"%s\"}", tempKey))
|
||||||
req, err := http.NewRequest("DELETE", "/v1/operator/keyring", body)
|
req, _ := http.NewRequest("DELETE", "/v1/operator/keyring", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.OperatorKeyringEndpoint(resp, req)
|
if _, err := srv.OperatorKeyringEndpoint(resp, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,13 +217,9 @@ func TestOperator_KeyringUse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body := bytes.NewBufferString(fmt.Sprintf("{\"Key\":\"%s\"}", newKey))
|
body := bytes.NewBufferString(fmt.Sprintf("{\"Key\":\"%s\"}", newKey))
|
||||||
req, err := http.NewRequest("PUT", "/v1/operator/keyring", body)
|
req, _ := http.NewRequest("PUT", "/v1/operator/keyring", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.OperatorKeyringEndpoint(resp, req)
|
_, err := srv.OperatorKeyringEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
@ -288,13 +259,9 @@ func TestOperator_Keyring_InvalidRelayFactor(t *testing.T) {
|
|||||||
"asdf": "Error parsing relay factor",
|
"asdf": "Error parsing relay factor",
|
||||||
}
|
}
|
||||||
for relayFactor, errString := range cases {
|
for relayFactor, errString := range cases {
|
||||||
req, err := http.NewRequest("GET", "/v1/operator/keyring?relay-factor="+relayFactor, nil)
|
req, _ := http.NewRequest("GET", "/v1/operator/keyring?relay-factor="+relayFactor, nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.OperatorKeyringEndpoint(resp, req)
|
_, err := srv.OperatorKeyringEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
@ -309,11 +276,7 @@ func TestOperator_Keyring_InvalidRelayFactor(t *testing.T) {
|
|||||||
func TestOperator_AutopilotGetConfiguration(t *testing.T) {
|
func TestOperator_AutopilotGetConfiguration(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/operator/autopilot/configuration", body)
|
req, _ := http.NewRequest("GET", "/v1/operator/autopilot/configuration", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.OperatorAutopilotConfiguration(resp, req)
|
obj, err := srv.OperatorAutopilotConfiguration(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -335,13 +298,9 @@ func TestOperator_AutopilotGetConfiguration(t *testing.T) {
|
|||||||
func TestOperator_AutopilotSetConfiguration(t *testing.T) {
|
func TestOperator_AutopilotSetConfiguration(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer([]byte(`{"CleanupDeadServers": false}`))
|
body := bytes.NewBuffer([]byte(`{"CleanupDeadServers": false}`))
|
||||||
req, err := http.NewRequest("PUT", "/v1/operator/autopilot/configuration", body)
|
req, _ := http.NewRequest("PUT", "/v1/operator/autopilot/configuration", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
if _, err = srv.OperatorAutopilotConfiguration(resp, req); err != nil {
|
if _, err := srv.OperatorAutopilotConfiguration(resp, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if resp.Code != 200 {
|
if resp.Code != 200 {
|
||||||
@ -365,13 +324,9 @@ func TestOperator_AutopilotSetConfiguration(t *testing.T) {
|
|||||||
func TestOperator_AutopilotCASConfiguration(t *testing.T) {
|
func TestOperator_AutopilotCASConfiguration(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer([]byte(`{"CleanupDeadServers": false}`))
|
body := bytes.NewBuffer([]byte(`{"CleanupDeadServers": false}`))
|
||||||
req, err := http.NewRequest("PUT", "/v1/operator/autopilot/configuration", body)
|
req, _ := http.NewRequest("PUT", "/v1/operator/autopilot/configuration", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
if _, err = srv.OperatorAutopilotConfiguration(resp, req); err != nil {
|
if _, err := srv.OperatorAutopilotConfiguration(resp, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if resp.Code != 200 {
|
if resp.Code != 200 {
|
||||||
@ -394,12 +349,7 @@ func TestOperator_AutopilotCASConfiguration(t *testing.T) {
|
|||||||
// Create a CAS request, bad index
|
// Create a CAS request, bad index
|
||||||
{
|
{
|
||||||
buf := bytes.NewBuffer([]byte(`{"CleanupDeadServers": true}`))
|
buf := bytes.NewBuffer([]byte(`{"CleanupDeadServers": true}`))
|
||||||
req, err := http.NewRequest("PUT",
|
req, _ := http.NewRequest("PUT", fmt.Sprintf("/v1/operator/autopilot/configuration?cas=%d", reply.ModifyIndex-1), buf)
|
||||||
fmt.Sprintf("/v1/operator/autopilot/configuration?cas=%d", reply.ModifyIndex-1), buf)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.OperatorAutopilotConfiguration(resp, req)
|
obj, err := srv.OperatorAutopilotConfiguration(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -414,12 +364,7 @@ func TestOperator_AutopilotCASConfiguration(t *testing.T) {
|
|||||||
// Create a CAS request, good index
|
// Create a CAS request, good index
|
||||||
{
|
{
|
||||||
buf := bytes.NewBuffer([]byte(`{"CleanupDeadServers": true}`))
|
buf := bytes.NewBuffer([]byte(`{"CleanupDeadServers": true}`))
|
||||||
req, err := http.NewRequest("PUT",
|
req, _ := http.NewRequest("PUT", fmt.Sprintf("/v1/operator/autopilot/configuration?cas=%d", reply.ModifyIndex), buf)
|
||||||
fmt.Sprintf("/v1/operator/autopilot/configuration?cas=%d", reply.ModifyIndex), buf)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.OperatorAutopilotConfiguration(resp, req)
|
obj, err := srv.OperatorAutopilotConfiguration(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -447,10 +392,7 @@ func TestOperator_ServerHealth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
httpTestWithConfig(t, func(srv *HTTPServer) {
|
httpTestWithConfig(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/operator/autopilot/health", body)
|
req, _ := http.NewRequest("GET", "/v1/operator/autopilot/health", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
retry.Run(t, func(r *retry.R) {
|
retry.Run(t, func(r *retry.R) {
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.OperatorServerHealth(resp, req)
|
obj, err := srv.OperatorServerHealth(resp, req)
|
||||||
@ -484,10 +426,7 @@ func TestOperator_ServerHealth_Unhealthy(t *testing.T) {
|
|||||||
}
|
}
|
||||||
httpTestWithConfig(t, func(srv *HTTPServer) {
|
httpTestWithConfig(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/operator/autopilot/health", body)
|
req, _ := http.NewRequest("GET", "/v1/operator/autopilot/health", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
retry.Run(t, func(r *retry.R) {
|
retry.Run(t, func(r *retry.R) {
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.OperatorServerHealth(resp, req)
|
obj, err := srv.OperatorServerHealth(resp, req)
|
||||||
|
@ -131,11 +131,7 @@ func TestPreparedQuery_Create(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "/v1/query?token=my-token", body)
|
req, _ := http.NewRequest("POST", "/v1/query?token=my-token", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.PreparedQueryGeneral(resp, req)
|
obj, err := srv.PreparedQueryGeneral(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -167,11 +163,7 @@ func TestPreparedQuery_List(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/query", body)
|
req, _ := http.NewRequest("GET", "/v1/query", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.PreparedQueryGeneral(resp, req)
|
obj, err := srv.PreparedQueryGeneral(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -215,11 +207,7 @@ func TestPreparedQuery_List(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/query?token=my-token&consistent=true", body)
|
req, _ := http.NewRequest("GET", "/v1/query?token=my-token&consistent=true", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.PreparedQueryGeneral(resp, req)
|
obj, err := srv.PreparedQueryGeneral(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -251,11 +239,7 @@ func TestPreparedQuery_Execute(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/query/my-id/execute", body)
|
req, _ := http.NewRequest("GET", "/v1/query/my-id/execute", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.PreparedQuerySpecific(resp, req)
|
obj, err := srv.PreparedQuerySpecific(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -307,11 +291,7 @@ func TestPreparedQuery_Execute(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/query/my-id/execute?token=my-token&consistent=true&near=my-node&limit=5", body)
|
req, _ := http.NewRequest("GET", "/v1/query/my-id/execute?token=my-token&consistent=true&near=my-node&limit=5", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.PreparedQuerySpecific(resp, req)
|
obj, err := srv.PreparedQuerySpecific(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -350,11 +330,7 @@ func TestPreparedQuery_Execute(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/query/my-id/execute", nil)
|
req, _ := http.NewRequest("GET", "/v1/query/my-id/execute", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
|
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
@ -382,11 +358,7 @@ func TestPreparedQuery_Execute(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/query/my-id/execute?dc=dc2", body)
|
req, _ := http.NewRequest("GET", "/v1/query/my-id/execute?dc=dc2", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.PreparedQuerySpecific(resp, req)
|
obj, err := srv.PreparedQuerySpecific(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -433,11 +405,7 @@ func TestPreparedQuery_Execute(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/query/my-id/execute?dc=dc2", body)
|
req, _ := http.NewRequest("GET", "/v1/query/my-id/execute?dc=dc2", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.PreparedQuerySpecific(resp, req)
|
obj, err := srv.PreparedQuerySpecific(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -465,14 +433,9 @@ func TestPreparedQuery_Execute(t *testing.T) {
|
|||||||
|
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/query/not-there/execute", body)
|
req, _ := http.NewRequest("GET", "/v1/query/not-there/execute", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.PreparedQuerySpecific(resp, req)
|
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if resp.Code != 404 {
|
if resp.Code != 404 {
|
||||||
@ -516,11 +479,7 @@ func TestPreparedQuery_Explain(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/query/my-id/explain?token=my-token&consistent=true&near=my-node&limit=5", body)
|
req, _ := http.NewRequest("GET", "/v1/query/my-id/explain?token=my-token&consistent=true&near=my-node&limit=5", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.PreparedQuerySpecific(resp, req)
|
obj, err := srv.PreparedQuerySpecific(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -540,14 +499,9 @@ func TestPreparedQuery_Explain(t *testing.T) {
|
|||||||
|
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/query/not-there/explain", body)
|
req, _ := http.NewRequest("GET", "/v1/query/not-there/explain", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.PreparedQuerySpecific(resp, req)
|
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if resp.Code != 404 {
|
if resp.Code != 404 {
|
||||||
@ -584,11 +538,7 @@ func TestPreparedQuery_Get(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/query/my-id?token=my-token&consistent=true", body)
|
req, _ := http.NewRequest("GET", "/v1/query/my-id?token=my-token&consistent=true", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.PreparedQuerySpecific(resp, req)
|
obj, err := srv.PreparedQuerySpecific(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -608,14 +558,9 @@ func TestPreparedQuery_Get(t *testing.T) {
|
|||||||
|
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/query/f004177f-2c28-83b7-4229-eacc25fe55d1", body)
|
req, _ := http.NewRequest("GET", "/v1/query/f004177f-2c28-83b7-4229-eacc25fe55d1", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.PreparedQuerySpecific(resp, req)
|
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if resp.Code != 404 {
|
if resp.Code != 404 {
|
||||||
@ -689,14 +634,9 @@ func TestPreparedQuery_Update(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT", "/v1/query/my-id?token=my-token", body)
|
req, _ := http.NewRequest("PUT", "/v1/query/my-id?token=my-token", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.PreparedQuerySpecific(resp, req)
|
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if resp.Code != 200 {
|
if resp.Code != 200 {
|
||||||
@ -740,14 +680,9 @@ func TestPreparedQuery_Delete(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("DELETE", "/v1/query/my-id?token=my-token", body)
|
req, _ := http.NewRequest("DELETE", "/v1/query/my-id?token=my-token", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.PreparedQuerySpecific(resp, req)
|
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if resp.Code != 200 {
|
if resp.Code != 200 {
|
||||||
@ -759,14 +694,9 @@ func TestPreparedQuery_Delete(t *testing.T) {
|
|||||||
func TestPreparedQuery_BadMethods(t *testing.T) {
|
func TestPreparedQuery_BadMethods(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("DELETE", "/v1/query", body)
|
req, _ := http.NewRequest("DELETE", "/v1/query", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.PreparedQueryGeneral(resp, req)
|
if _, err := srv.PreparedQueryGeneral(resp, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if resp.Code != 405 {
|
if resp.Code != 405 {
|
||||||
@ -776,14 +706,9 @@ func TestPreparedQuery_BadMethods(t *testing.T) {
|
|||||||
|
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("POST", "/v1/query/my-id", body)
|
req, _ := http.NewRequest("POST", "/v1/query/my-id", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.PreparedQuerySpecific(resp, req)
|
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if resp.Code != 405 {
|
if resp.Code != 405 {
|
||||||
@ -794,11 +719,7 @@ func TestPreparedQuery_BadMethods(t *testing.T) {
|
|||||||
|
|
||||||
func TestPreparedQuery_parseLimit(t *testing.T) {
|
func TestPreparedQuery_parseLimit(t *testing.T) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/query", body)
|
req, _ := http.NewRequest("GET", "/v1/query", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
limit := 99
|
limit := 99
|
||||||
if err := parseLimit(req, &limit); err != nil {
|
if err := parseLimit(req, &limit); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
@ -807,10 +728,7 @@ func TestPreparedQuery_parseLimit(t *testing.T) {
|
|||||||
t.Fatalf("bad limit: %d", limit)
|
t.Fatalf("bad limit: %d", limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/v1/query?limit=11", body)
|
req, _ = http.NewRequest("GET", "/v1/query?limit=11", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
if err := parseLimit(req, &limit); err != nil {
|
if err := parseLimit(req, &limit); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
@ -818,10 +736,7 @@ func TestPreparedQuery_parseLimit(t *testing.T) {
|
|||||||
t.Fatalf("bad limit: %d", limit)
|
t.Fatalf("bad limit: %d", limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/v1/query?limit=bob", body)
|
req, _ = http.NewRequest("GET", "/v1/query?limit=bob", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
if err := parseLimit(req, &limit); err == nil {
|
if err := parseLimit(req, &limit); err == nil {
|
||||||
t.Fatalf("bad: %v", err)
|
t.Fatalf("bad: %v", err)
|
||||||
}
|
}
|
||||||
@ -863,11 +778,7 @@ func TestPreparedQuery_Integration(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "/v1/query", body)
|
req, _ := http.NewRequest("POST", "/v1/query", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.PreparedQueryGeneral(resp, req)
|
obj, err := srv.PreparedQueryGeneral(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -886,11 +797,7 @@ func TestPreparedQuery_Integration(t *testing.T) {
|
|||||||
// List them all.
|
// List them all.
|
||||||
{
|
{
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/query?token=root", body)
|
req, _ := http.NewRequest("GET", "/v1/query?token=root", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.PreparedQueryGeneral(resp, req)
|
obj, err := srv.PreparedQueryGeneral(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -911,11 +818,7 @@ func TestPreparedQuery_Integration(t *testing.T) {
|
|||||||
// Execute it.
|
// Execute it.
|
||||||
{
|
{
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/query/"+id+"/execute", body)
|
req, _ := http.NewRequest("GET", "/v1/query/"+id+"/execute", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.PreparedQuerySpecific(resp, req)
|
obj, err := srv.PreparedQuerySpecific(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -936,11 +839,7 @@ func TestPreparedQuery_Integration(t *testing.T) {
|
|||||||
// Read it back.
|
// Read it back.
|
||||||
{
|
{
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/query/"+id, body)
|
req, _ := http.NewRequest("GET", "/v1/query/"+id, body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.PreparedQuerySpecific(resp, req)
|
obj, err := srv.PreparedQuerySpecific(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -973,14 +872,9 @@ func TestPreparedQuery_Integration(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT", "/v1/query/"+id, body)
|
req, _ := http.NewRequest("PUT", "/v1/query/"+id, body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.PreparedQuerySpecific(resp, req)
|
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if resp.Code != 200 {
|
if resp.Code != 200 {
|
||||||
@ -991,14 +885,9 @@ func TestPreparedQuery_Integration(t *testing.T) {
|
|||||||
// Delete it.
|
// Delete it.
|
||||||
{
|
{
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("DELETE", "/v1/query/"+id, body)
|
req, _ := http.NewRequest("DELETE", "/v1/query/"+id, body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.PreparedQuerySpecific(resp, req)
|
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if resp.Code != 200 {
|
if resp.Code != 200 {
|
||||||
|
@ -45,11 +45,7 @@ func TestSessionCreate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
enc.Encode(raw)
|
enc.Encode(raw)
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT", "/v1/session/create", body)
|
req, _ := http.NewRequest("PUT", "/v1/session/create", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.SessionCreate(resp, req)
|
obj, err := srv.SessionCreate(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -94,11 +90,7 @@ func TestSessionCreateDelete(t *testing.T) {
|
|||||||
}
|
}
|
||||||
enc.Encode(raw)
|
enc.Encode(raw)
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT", "/v1/session/create", body)
|
req, _ := http.NewRequest("PUT", "/v1/session/create", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.SessionCreate(resp, req)
|
obj, err := srv.SessionCreate(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -144,10 +136,7 @@ func TestFixupLockDelay(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeTestSession(t *testing.T, srv *HTTPServer) string {
|
func makeTestSession(t *testing.T, srv *HTTPServer) string {
|
||||||
req, err := http.NewRequest("PUT", "/v1/session/create", nil)
|
req, _ := http.NewRequest("PUT", "/v1/session/create", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.SessionCreate(resp, req)
|
obj, err := srv.SessionCreate(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -166,10 +155,7 @@ func makeTestSessionDelete(t *testing.T, srv *HTTPServer) string {
|
|||||||
}
|
}
|
||||||
enc.Encode(raw)
|
enc.Encode(raw)
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT", "/v1/session/create", body)
|
req, _ := http.NewRequest("PUT", "/v1/session/create", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.SessionCreate(resp, req)
|
obj, err := srv.SessionCreate(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -188,10 +174,7 @@ func makeTestSessionTTL(t *testing.T, srv *HTTPServer, ttl string) string {
|
|||||||
}
|
}
|
||||||
enc.Encode(raw)
|
enc.Encode(raw)
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT", "/v1/session/create", body)
|
req, _ := http.NewRequest("PUT", "/v1/session/create", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.SessionCreate(resp, req)
|
obj, err := srv.SessionCreate(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -205,7 +188,7 @@ func TestSessionDestroy(t *testing.T) {
|
|||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
id := makeTestSession(t, srv)
|
id := makeTestSession(t, srv)
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT", "/v1/session/destroy/"+id, nil)
|
req, _ := http.NewRequest("PUT", "/v1/session/destroy/"+id, nil)
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.SessionDestroy(resp, req)
|
obj, err := srv.SessionDestroy(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -235,8 +218,7 @@ func testSessionTTL(t *testing.T, ttl time.Duration, cb func(c *Config)) {
|
|||||||
|
|
||||||
id := makeTestSessionTTL(t, srv, TTL)
|
id := makeTestSessionTTL(t, srv, TTL)
|
||||||
|
|
||||||
req, err := http.NewRequest("GET",
|
req, _ := http.NewRequest("GET", "/v1/session/info/"+id, nil)
|
||||||
"/v1/session/info/"+id, nil)
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.SessionGet(resp, req)
|
obj, err := srv.SessionGet(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -255,8 +237,7 @@ func testSessionTTL(t *testing.T, ttl time.Duration, cb func(c *Config)) {
|
|||||||
|
|
||||||
time.Sleep(ttl*structs.SessionTTLMultiplier + ttl)
|
time.Sleep(ttl*structs.SessionTTLMultiplier + ttl)
|
||||||
|
|
||||||
req, err = http.NewRequest("GET",
|
req, _ = http.NewRequest("GET", "/v1/session/info/"+id, nil)
|
||||||
"/v1/session/info/"+id, nil)
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.SessionGet(resp, req)
|
obj, err = srv.SessionGet(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -275,8 +256,7 @@ func TestSessionTTLRenew(t *testing.T) {
|
|||||||
httpTestWithConfig(t, func(srv *HTTPServer) {
|
httpTestWithConfig(t, func(srv *HTTPServer) {
|
||||||
id := makeTestSessionTTL(t, srv, TTL)
|
id := makeTestSessionTTL(t, srv, TTL)
|
||||||
|
|
||||||
req, err := http.NewRequest("GET",
|
req, _ := http.NewRequest("GET", "/v1/session/info/"+id, nil)
|
||||||
"/v1/session/info/"+id, nil)
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.SessionGet(resp, req)
|
obj, err := srv.SessionGet(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -296,8 +276,7 @@ func TestSessionTTLRenew(t *testing.T) {
|
|||||||
// Sleep to consume some time before renew
|
// Sleep to consume some time before renew
|
||||||
time.Sleep(ttl * (structs.SessionTTLMultiplier / 2))
|
time.Sleep(ttl * (structs.SessionTTLMultiplier / 2))
|
||||||
|
|
||||||
req, err = http.NewRequest("PUT",
|
req, _ = http.NewRequest("PUT", "/v1/session/renew/"+id, nil)
|
||||||
"/v1/session/renew/"+id, nil)
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.SessionRenew(resp, req)
|
obj, err = srv.SessionRenew(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -314,8 +293,7 @@ func TestSessionTTLRenew(t *testing.T) {
|
|||||||
// Sleep for ttl * TTL Multiplier
|
// Sleep for ttl * TTL Multiplier
|
||||||
time.Sleep(ttl * structs.SessionTTLMultiplier)
|
time.Sleep(ttl * structs.SessionTTLMultiplier)
|
||||||
|
|
||||||
req, err = http.NewRequest("GET",
|
req, _ = http.NewRequest("GET", "/v1/session/info/"+id, nil)
|
||||||
"/v1/session/info/"+id, nil)
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.SessionGet(resp, req)
|
obj, err = srv.SessionGet(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -332,8 +310,7 @@ func TestSessionTTLRenew(t *testing.T) {
|
|||||||
// now wait for timeout and expect session to get destroyed
|
// now wait for timeout and expect session to get destroyed
|
||||||
time.Sleep(ttl * structs.SessionTTLMultiplier)
|
time.Sleep(ttl * structs.SessionTTLMultiplier)
|
||||||
|
|
||||||
req, err = http.NewRequest("GET",
|
req, _ = http.NewRequest("GET", "/v1/session/info/"+id, nil)
|
||||||
"/v1/session/info/"+id, nil)
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.SessionGet(resp, req)
|
obj, err = srv.SessionGet(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -351,7 +328,7 @@ func TestSessionTTLRenew(t *testing.T) {
|
|||||||
|
|
||||||
func TestSessionGet(t *testing.T) {
|
func TestSessionGet(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
req, err := http.NewRequest("GET", "/v1/session/info/adf4238a-882b-9ddc-4a9d-5b6758e4159e", nil)
|
req, _ := http.NewRequest("GET", "/v1/session/info/adf4238a-882b-9ddc-4a9d-5b6758e4159e", nil)
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.SessionGet(resp, req)
|
obj, err := srv.SessionGet(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -369,8 +346,7 @@ func TestSessionGet(t *testing.T) {
|
|||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
id := makeTestSession(t, srv)
|
id := makeTestSession(t, srv)
|
||||||
|
|
||||||
req, err := http.NewRequest("GET",
|
req, _ := http.NewRequest("GET", "/v1/session/info/"+id, nil)
|
||||||
"/v1/session/info/"+id, nil)
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.SessionGet(resp, req)
|
obj, err := srv.SessionGet(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -388,7 +364,7 @@ func TestSessionGet(t *testing.T) {
|
|||||||
|
|
||||||
func TestSessionList(t *testing.T) {
|
func TestSessionList(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
req, err := http.NewRequest("GET", "/v1/session/list", nil)
|
req, _ := http.NewRequest("GET", "/v1/session/list", nil)
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.SessionList(resp, req)
|
obj, err := srv.SessionList(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -409,7 +385,7 @@ func TestSessionList(t *testing.T) {
|
|||||||
ids = append(ids, makeTestSession(t, srv))
|
ids = append(ids, makeTestSession(t, srv))
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/session/list", nil)
|
req, _ := http.NewRequest("GET", "/v1/session/list", nil)
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.SessionList(resp, req)
|
obj, err := srv.SessionList(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -427,8 +403,7 @@ func TestSessionList(t *testing.T) {
|
|||||||
|
|
||||||
func TestSessionsForNode(t *testing.T) {
|
func TestSessionsForNode(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
req, err := http.NewRequest("GET",
|
req, _ := http.NewRequest("GET", "/v1/session/node/"+srv.agent.config.NodeName, nil)
|
||||||
"/v1/session/node/"+srv.agent.config.NodeName, nil)
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.SessionsForNode(resp, req)
|
obj, err := srv.SessionsForNode(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -449,8 +424,7 @@ func TestSessionsForNode(t *testing.T) {
|
|||||||
ids = append(ids, makeTestSession(t, srv))
|
ids = append(ids, makeTestSession(t, srv))
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET",
|
req, _ := http.NewRequest("GET", "/v1/session/node/"+srv.agent.config.NodeName, nil)
|
||||||
"/v1/session/node/"+srv.agent.config.NodeName, nil)
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.SessionsForNode(resp, req)
|
obj, err := srv.SessionsForNode(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -472,10 +446,7 @@ func TestSessionDeleteDestroy(t *testing.T) {
|
|||||||
|
|
||||||
// now create a new key for the session and acquire it
|
// now create a new key for the session and acquire it
|
||||||
buf := bytes.NewBuffer([]byte("test"))
|
buf := bytes.NewBuffer([]byte("test"))
|
||||||
req, err := http.NewRequest("PUT", "/v1/kv/ephemeral?acquire="+id, buf)
|
req, _ := http.NewRequest("PUT", "/v1/kv/ephemeral?acquire="+id, buf)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.KVSEndpoint(resp, req)
|
obj, err := srv.KVSEndpoint(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -487,7 +458,7 @@ func TestSessionDeleteDestroy(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// now destroy the session, this should delete the key created above
|
// now destroy the session, this should delete the key created above
|
||||||
req, err = http.NewRequest("PUT", "/v1/session/destroy/"+id, nil)
|
req, _ = http.NewRequest("PUT", "/v1/session/destroy/"+id, nil)
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.SessionDestroy(resp, req)
|
obj, err = srv.SessionDestroy(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -13,14 +13,9 @@ func TestSnapshot(t *testing.T) {
|
|||||||
var snap io.Reader
|
var snap io.Reader
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("GET", "/v1/snapshot?token=root", body)
|
req, _ := http.NewRequest("GET", "/v1/snapshot?token=root", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.Snapshot(resp, req)
|
if _, err := srv.Snapshot(resp, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
snap = resp.Body
|
snap = resp.Body
|
||||||
@ -40,14 +35,9 @@ func TestSnapshot(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
req, err := http.NewRequest("PUT", "/v1/snapshot?token=root", snap)
|
req, _ := http.NewRequest("PUT", "/v1/snapshot?token=root", snap)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.Snapshot(resp, req)
|
if _, err := srv.Snapshot(resp, req); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -57,13 +47,9 @@ func TestSnapshot_Options(t *testing.T) {
|
|||||||
for _, method := range []string{"GET", "PUT"} {
|
for _, method := range []string{"GET", "PUT"} {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest(method, "/v1/snapshot?token=anonymous", body)
|
req, _ := http.NewRequest(method, "/v1/snapshot?token=anonymous", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.Snapshot(resp, req)
|
_, err := srv.Snapshot(resp, req)
|
||||||
if err == nil || !strings.Contains(err.Error(), "Permission denied") {
|
if err == nil || !strings.Contains(err.Error(), "Permission denied") {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
@ -71,13 +57,9 @@ func TestSnapshot_Options(t *testing.T) {
|
|||||||
|
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest(method, "/v1/snapshot?dc=nope", body)
|
req, _ := http.NewRequest(method, "/v1/snapshot?dc=nope", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.Snapshot(resp, req)
|
_, err := srv.Snapshot(resp, req)
|
||||||
if err == nil || !strings.Contains(err.Error(), "No path to datacenter") {
|
if err == nil || !strings.Contains(err.Error(), "No path to datacenter") {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
@ -85,13 +67,9 @@ func TestSnapshot_Options(t *testing.T) {
|
|||||||
|
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest(method, "/v1/snapshot?token=root&stale", body)
|
req, _ := http.NewRequest(method, "/v1/snapshot?token=root&stale", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.Snapshot(resp, req)
|
_, err := srv.Snapshot(resp, req)
|
||||||
if method == "GET" {
|
if method == "GET" {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
@ -108,13 +86,9 @@ func TestSnapshot_Options(t *testing.T) {
|
|||||||
func TestSnapshot_BadMethods(t *testing.T) {
|
func TestSnapshot_BadMethods(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("POST", "/v1/snapshot", body)
|
req, _ := http.NewRequest("POST", "/v1/snapshot", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.Snapshot(resp, req)
|
_, err := srv.Snapshot(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
@ -125,13 +99,9 @@ func TestSnapshot_BadMethods(t *testing.T) {
|
|||||||
|
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
body := bytes.NewBuffer(nil)
|
body := bytes.NewBuffer(nil)
|
||||||
req, err := http.NewRequest("DELETE", "/v1/snapshot", body)
|
req, _ := http.NewRequest("DELETE", "/v1/snapshot", body)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err = srv.Snapshot(resp, req)
|
_, err := srv.Snapshot(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,7 @@ import (
|
|||||||
func TestTxnEndpoint_Bad_JSON(t *testing.T) {
|
func TestTxnEndpoint_Bad_JSON(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
buf := bytes.NewBuffer([]byte("{"))
|
buf := bytes.NewBuffer([]byte("{"))
|
||||||
req, err := http.NewRequest("PUT", "/v1/txn", buf)
|
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
if _, err := srv.Txn(resp, req); err != nil {
|
if _, err := srv.Txn(resp, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
@ -36,11 +32,7 @@ func TestTxnEndpoint_Bad_JSON(t *testing.T) {
|
|||||||
func TestTxnEndpoint_Bad_Method(t *testing.T) {
|
func TestTxnEndpoint_Bad_Method(t *testing.T) {
|
||||||
httpTest(t, func(srv *HTTPServer) {
|
httpTest(t, func(srv *HTTPServer) {
|
||||||
buf := bytes.NewBuffer([]byte("{}"))
|
buf := bytes.NewBuffer([]byte("{}"))
|
||||||
req, err := http.NewRequest("GET", "/v1/txn", buf)
|
req, _ := http.NewRequest("GET", "/v1/txn", buf)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
if _, err := srv.Txn(resp, req); err != nil {
|
if _, err := srv.Txn(resp, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
@ -64,11 +56,7 @@ func TestTxnEndpoint_Bad_Size_Item(t *testing.T) {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
`, strings.Repeat("bad", 2*maxKVSize))))
|
`, strings.Repeat("bad", 2*maxKVSize))))
|
||||||
req, err := http.NewRequest("PUT", "/v1/txn", buf)
|
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
if _, err := srv.Txn(resp, req); err != nil {
|
if _, err := srv.Txn(resp, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
@ -107,11 +95,7 @@ func TestTxnEndpoint_Bad_Size_Net(t *testing.T) {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
`, value, value, value)))
|
`, value, value, value)))
|
||||||
req, err := http.NewRequest("PUT", "/v1/txn", buf)
|
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
if _, err := srv.Txn(resp, req); err != nil {
|
if _, err := srv.Txn(resp, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
@ -136,11 +120,7 @@ func TestTxnEndpoint_Bad_Size_Ops(t *testing.T) {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
`, strings.Repeat(`{ "KV": { "Verb": "get", "Key": "key" } },`, 2*maxTxnOps))))
|
`, strings.Repeat(`{ "KV": { "Verb": "get", "Key": "key" } },`, 2*maxTxnOps))))
|
||||||
req, err := http.NewRequest("PUT", "/v1/txn", buf)
|
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
if _, err := srv.Txn(resp, req); err != nil {
|
if _, err := srv.Txn(resp, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
@ -177,11 +157,7 @@ func TestTxnEndpoint_KV_Actions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
`, id)))
|
`, id)))
|
||||||
req, err := http.NewRequest("PUT", "/v1/txn", buf)
|
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.Txn(resp, req)
|
obj, err := srv.Txn(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -253,11 +229,7 @@ func TestTxnEndpoint_KV_Actions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
`))
|
`))
|
||||||
req, err := http.NewRequest("PUT", "/v1/txn", buf)
|
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.Txn(resp, req)
|
obj, err := srv.Txn(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -341,11 +313,7 @@ func TestTxnEndpoint_KV_Actions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
`, index)))
|
`, index)))
|
||||||
req, err := http.NewRequest("PUT", "/v1/txn", buf)
|
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.Txn(resp, req)
|
obj, err := srv.Txn(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -415,13 +383,9 @@ func TestTxnEndpoint_KV_Actions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
`))
|
`))
|
||||||
req, err := http.NewRequest("PUT", "/v1/txn", buf)
|
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
if _, err = srv.Txn(resp, req); err != nil {
|
if _, err := srv.Txn(resp, req); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if resp.Code != 409 {
|
if resp.Code != 409 {
|
||||||
|
@ -41,10 +41,7 @@ func TestUiIndex(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Register node
|
// Register node
|
||||||
req, err := http.NewRequest("GET", "/ui/my-file", nil)
|
req, _ := http.NewRequest("GET", "/ui/my-file", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
req.URL.Scheme = "http"
|
req.URL.Scheme = "http"
|
||||||
req.URL.Host = srv.listener.Addr().String()
|
req.URL.Host = srv.listener.Addr().String()
|
||||||
|
|
||||||
@ -87,11 +84,7 @@ func TestUiNodes(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v1/internal/ui/nodes/dc1", nil)
|
req, _ := http.NewRequest("GET", "/v1/internal/ui/nodes/dc1", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.UINodes(resp, req)
|
obj, err := srv.UINodes(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -120,12 +113,7 @@ func TestUiNodeInfo(t *testing.T) {
|
|||||||
|
|
||||||
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
|
||||||
|
|
||||||
req, err := http.NewRequest("GET",
|
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/internal/ui/node/%s", srv.agent.config.NodeName), nil)
|
||||||
fmt.Sprintf("/v1/internal/ui/node/%s", srv.agent.config.NodeName), nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := srv.UINodeInfo(resp, req)
|
obj, err := srv.UINodeInfo(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -151,11 +139,7 @@ func TestUiNodeInfo(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/v1/internal/ui/node/test", nil)
|
req, _ = http.NewRequest("GET", "/v1/internal/ui/node/test", nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
obj, err = srv.UINodeInfo(resp, req)
|
obj, err = srv.UINodeInfo(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user