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:
Frank Schroeder 2017-05-09 13:38:05 +02:00 committed by Frank Schröder
parent 7fa2471ba7
commit 1e89692cc1
14 changed files with 325 additions and 1254 deletions

View File

@ -20,10 +20,7 @@ func makeTestACL(t *testing.T, srv *HTTPServer) string {
}
enc.Encode(raw)
req, err := http.NewRequest("PUT", "/v1/acl/create?token=root", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/acl/create?token=root", body)
resp := httptest.NewRecorder()
obj, err := srv.ACLCreate(resp, req)
if err != nil {
@ -47,10 +44,7 @@ func TestACLUpdate(t *testing.T) {
}
enc.Encode(raw)
req, err := http.NewRequest("PUT", "/v1/acl/update?token=root", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/acl/update?token=root", body)
resp := httptest.NewRecorder()
obj, err := srv.ACLUpdate(resp, req)
if err != nil {
@ -75,10 +69,7 @@ func TestACLUpdate_Upsert(t *testing.T) {
}
enc.Encode(raw)
req, err := http.NewRequest("PUT", "/v1/acl/update?token=root", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/acl/update?token=root", body)
resp := httptest.NewRecorder()
obj, err := srv.ACLUpdate(resp, req)
if err != nil {
@ -94,7 +85,7 @@ func TestACLUpdate_Upsert(t *testing.T) {
func TestACLDestroy(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
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()
obj, err := srv.ACLDestroy(resp, req)
if err != nil {
@ -104,8 +95,7 @@ func TestACLDestroy(t *testing.T) {
t.Fatalf("should work")
}
req, err = http.NewRequest("GET",
"/v1/acl/info/"+id, nil)
req, _ = http.NewRequest("GET", "/v1/acl/info/"+id, nil)
resp = httptest.NewRecorder()
obj, err = srv.ACLGet(resp, req)
if err != nil {
@ -125,8 +115,7 @@ func TestACLClone(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
id := makeTestACL(t, srv)
req, err := http.NewRequest("PUT",
"/v1/acl/clone/"+id+"?token=root", nil)
req, _ := http.NewRequest("PUT", "/v1/acl/clone/"+id+"?token=root", nil)
resp := httptest.NewRecorder()
obj, err := srv.ACLClone(resp, req)
if err != nil {
@ -140,8 +129,7 @@ func TestACLClone(t *testing.T) {
t.Fatalf("bad id")
}
req, err = http.NewRequest("GET",
"/v1/acl/info/"+aclResp.ID, nil)
req, _ = http.NewRequest("GET", "/v1/acl/info/"+aclResp.ID, nil)
resp = httptest.NewRecorder()
obj, err = srv.ACLGet(resp, req)
if err != nil {
@ -159,7 +147,7 @@ func TestACLClone(t *testing.T) {
func TestACLGet(t *testing.T) {
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()
obj, err := srv.ACLGet(resp, req)
if err != nil {
@ -177,8 +165,7 @@ func TestACLGet(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
id := makeTestACL(t, srv)
req, err := http.NewRequest("GET",
"/v1/acl/info/"+id, nil)
req, _ := http.NewRequest("GET", "/v1/acl/info/"+id, nil)
resp := httptest.NewRecorder()
obj, err := srv.ACLGet(resp, req)
if err != nil {
@ -201,7 +188,7 @@ func TestACLList(t *testing.T) {
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()
obj, err := srv.ACLList(resp, req)
if err != nil {
@ -221,7 +208,7 @@ func TestACLList(t *testing.T) {
func TestACLReplicationStatus(t *testing.T) {
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()
obj, err := srv.ACLReplicationStatus(resp, req)
if err != nil {

View File

@ -34,10 +34,7 @@ func makeReadOnlyAgentACL(t *testing.T, srv *HTTPServer) string {
}
enc.Encode(raw)
req, err := http.NewRequest("PUT", "/v1/acl/create?token=root", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/acl/create?token=root", body)
resp := httptest.NewRecorder()
obj, err := srv.ACLCreate(resp, req)
if err != nil {
@ -61,11 +58,7 @@ func TestAgent_Services(t *testing.T) {
}
srv.agent.state.AddService(srv1, "")
req, err := http.NewRequest("GET", "/v1/agent/services", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/services", nil)
obj, err := srv.AgentServices(nil, req)
if err != nil {
t.Fatalf("Err: %v", err)
@ -87,11 +80,7 @@ func TestAgent_Services_ACLFilter(t *testing.T) {
// Try no token.
{
req, err := http.NewRequest("GET", "/v1/agent/services", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/services", nil)
obj, err := srv.AgentServices(nil, req)
if err != nil {
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).
{
req, err := http.NewRequest("GET", "/v1/agent/services?token=root", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/services?token=root", nil)
obj, err := srv.AgentServices(nil, req)
if err != nil {
t.Fatalf("Err: %v", err)
@ -134,11 +119,7 @@ func TestAgent_Checks(t *testing.T) {
}
srv.agent.state.AddCheck(chk1, "")
req, err := http.NewRequest("GET", "/v1/agent/checks", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/checks", nil)
obj, err := srv.AgentChecks(nil, req)
if err != nil {
t.Fatalf("Err: %v", err)
@ -168,11 +149,7 @@ func TestAgent_Checks_ACLFilter(t *testing.T) {
// Try no token.
{
req, err := http.NewRequest("GET", "/v1/agent/checks", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/checks", nil)
obj, err := srv.AgentChecks(nil, req)
if err != nil {
t.Fatalf("Err: %v", err)
@ -185,11 +162,7 @@ func TestAgent_Checks_ACLFilter(t *testing.T) {
// Try the root token.
{
req, err := http.NewRequest("GET", "/v1/agent/checks?token=root", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/checks?token=root", nil)
obj, err := srv.AgentChecks(nil, req)
if err != nil {
t.Fatalf("Err: %v", err)
@ -212,11 +185,7 @@ func TestAgent_Self(t *testing.T) {
defer srv.Shutdown()
defer srv.agent.Shutdown()
req, err := http.NewRequest("GET", "/v1/agent/self", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/self", nil)
obj, err := srv.AgentSelf(nil, req)
if err != nil {
t.Fatalf("err: %v", err)
@ -259,43 +228,23 @@ func TestAgent_Self_ACLDeny(t *testing.T) {
defer srv.agent.Shutdown()
// Try without a token.
{
req, err := http.NewRequest("GET", "/v1/agent/self", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentSelf(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/self", nil)
_, 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).
{
req, err := http.NewRequest("GET", "/v1/agent/self?token=towel", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentSelf(nil, req)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/agent/self?token=towel", nil)
if _, err := srv.AgentSelf(nil, req); err != nil {
t.Fatalf("err: %v", err)
}
// Try a read only token (resolved on the servers).
ro := makeReadOnlyAgentACL(t, srv)
{
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/self?token=%s", ro), nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentSelf(nil, req)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", fmt.Sprintf("/v1/agent/self?token=%s", ro), nil)
if _, err := srv.AgentSelf(nil, req); err != nil {
t.Fatalf("err: %v", err)
}
}
@ -357,19 +306,14 @@ func TestAgent_Reload(t *testing.T) {
t.Fatalf("missing redis service")
}
err = ioutil.WriteFile(tmpFile.Name(), []byte(`{"acl_enforce_version_8": false, "service":{"name":"redis-reloaded"}}`), 0644)
if err != nil {
data := []byte(`{"acl_enforce_version_8": false, "service":{"name":"redis-reloaded"}}`)
if err := ioutil.WriteFile(tmpFile.Name(), data, 0644); err != nil {
t.Fatalf("err: %v", err)
}
srv := cmd.httpServers[0]
req, err := http.NewRequest("PUT", "/v1/agent/reload", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentReload(nil, req)
if err != nil {
req, _ := http.NewRequest("PUT", "/v1/agent/reload", nil)
if _, err := srv.AgentReload(nil, req); err != nil {
t.Fatalf("Err: %v", err)
}
@ -385,30 +329,18 @@ func TestAgent_Reload_ACLDeny(t *testing.T) {
defer srv.agent.Shutdown()
// Try without a token.
{
req, err := http.NewRequest("PUT", "/v1/agent/reload", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentReload(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/agent/reload", nil)
_, 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).
ro := makeReadOnlyAgentACL(t, srv)
{
req, err := http.NewRequest("PUT", fmt.Sprintf("/v1/agent/reload?token=%s", ro), nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentReload(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("PUT", fmt.Sprintf("/v1/agent/reload?token=%s", ro), nil)
_, 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
@ -423,11 +355,7 @@ func TestAgent_Members(t *testing.T) {
defer srv.Shutdown()
defer srv.agent.Shutdown()
req, err := http.NewRequest("GET", "/v1/agent/members", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/members", nil)
obj, err := srv.AgentMembers(nil, req)
if err != nil {
t.Fatalf("Err: %v", err)
@ -448,11 +376,7 @@ func TestAgent_Members_WAN(t *testing.T) {
defer srv.Shutdown()
defer srv.agent.Shutdown()
req, err := http.NewRequest("GET", "/v1/agent/members?wan=true", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/members?wan=true", nil)
obj, err := srv.AgentMembers(nil, req)
if err != nil {
t.Fatalf("Err: %v", err)
@ -475,11 +399,7 @@ func TestAgent_Members_ACLFilter(t *testing.T) {
// Try no token.
{
req, err := http.NewRequest("GET", "/v1/agent/members", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/members", nil)
obj, err := srv.AgentMembers(nil, req)
if err != nil {
t.Fatalf("Err: %v", err)
@ -492,11 +412,7 @@ func TestAgent_Members_ACLFilter(t *testing.T) {
// Try the root token.
{
req, err := http.NewRequest("GET", "/v1/agent/members?token=root", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/members?token=root", nil)
obj, err := srv.AgentMembers(nil, req)
if err != nil {
t.Fatalf("Err: %v", err)
@ -519,11 +435,7 @@ func TestAgent_Join(t *testing.T) {
defer a2.Shutdown()
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)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s", addr), nil)
obj, err := srv.AgentJoin(nil, req)
if err != nil {
t.Fatalf("Err: %v", err)
@ -554,11 +466,7 @@ func TestAgent_Join_WAN(t *testing.T) {
defer a2.Shutdown()
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)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s?wan=true", addr), nil)
obj, err := srv.AgentJoin(nil, req)
if err != nil {
t.Fatalf("Err: %v", err)
@ -591,12 +499,8 @@ func TestAgent_Join_ACLDeny(t *testing.T) {
// Try without a token.
{
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s", addr), nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentJoin(nil, req)
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s", addr), nil)
_, err := srv.AgentJoin(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
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).
{
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s?token=towel", addr), nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentJoin(nil, req)
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s?token=towel", addr), nil)
_, err := srv.AgentJoin(nil, req)
if err != nil {
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).
ro := makeReadOnlyAgentACL(t, srv)
{
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s?token=%s", addr, ro), nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentJoin(nil, req)
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s?token=%s", addr, ro), nil)
_, err := srv.AgentJoin(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
@ -651,11 +547,7 @@ func TestAgent_Leave(t *testing.T) {
}
// Graceful leave now
req, err := http.NewRequest("PUT", "/v1/agent/leave", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/agent/leave", nil)
obj, err := srv2.AgentLeave(nil, req)
if err != nil {
t.Fatalf("Err: %v", err)
@ -679,12 +571,8 @@ func TestAgent_Leave_ACLDeny(t *testing.T) {
defer srv.Shutdown()
defer srv.agent.Shutdown()
req, err := http.NewRequest("PUT", "/v1/agent/leave", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentLeave(nil, req)
req, _ := http.NewRequest("PUT", "/v1/agent/leave", nil)
_, err := srv.AgentLeave(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
@ -697,12 +585,8 @@ func TestAgent_Leave_ACLDeny(t *testing.T) {
defer srv.Shutdown()
defer srv.agent.Shutdown()
req, err := http.NewRequest("PUT", "/v1/agent/leave?token=towel", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentLeave(nil, req)
req, _ := http.NewRequest("PUT", "/v1/agent/leave?token=towel", nil)
_, err := srv.AgentLeave(nil, req)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -716,12 +600,8 @@ func TestAgent_Leave_ACLDeny(t *testing.T) {
defer srv.agent.Shutdown()
ro := makeReadOnlyAgentACL(t, srv)
req, err := http.NewRequest("PUT", fmt.Sprintf("/v1/agent/leave?token=%s", ro), nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentLeave(nil, req)
req, _ := http.NewRequest("PUT", fmt.Sprintf("/v1/agent/leave?token=%s", ro), nil)
_, err := srv.AgentLeave(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
@ -748,11 +628,7 @@ func TestAgent_ForceLeave(t *testing.T) {
a2.Shutdown()
// Force leave now
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/force-leave/%s", a2.config.NodeName), nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/agent/force-leave/%s", a2.config.NodeName), nil)
obj, err := srv.AgentForceLeave(nil, req)
if err != nil {
t.Fatalf("Err: %v", err)
@ -777,12 +653,8 @@ func TestAgent_ForceLeave_ACLDeny(t *testing.T) {
// Try without a token.
{
req, err := http.NewRequest("GET", "/v1/agent/force-leave/nope", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentForceLeave(nil, req)
req, _ := http.NewRequest("GET", "/v1/agent/force-leave/nope", nil)
_, err := srv.AgentForceLeave(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
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).
{
req, err := http.NewRequest("GET", "/v1/agent/force-leave/nope?token=towel", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentForceLeave(nil, req)
req, _ := http.NewRequest("GET", "/v1/agent/force-leave/nope?token=towel", nil)
_, err := srv.AgentForceLeave(nil, req)
if err != nil {
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).
ro := makeReadOnlyAgentACL(t, srv)
{
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/force-leave/nope?token=%s", ro), nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentForceLeave(nil, req)
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/agent/force-leave/nope?token=%s", ro), nil)
_, err := srv.AgentForceLeave(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
@ -823,10 +687,7 @@ func TestAgent_RegisterCheck(t *testing.T) {
defer srv.agent.Shutdown()
// Register node
req, err := http.NewRequest("GET", "/v1/agent/check/register?token=abc123", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/check/register?token=abc123", nil)
args := &CheckDefinition{
Name: "test",
CheckType: CheckType{
@ -872,10 +733,7 @@ func TestAgent_RegisterCheck_Passing(t *testing.T) {
defer srv.agent.Shutdown()
// Register node
req, err := http.NewRequest("GET", "/v1/agent/check/register", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/check/register", nil)
args := &CheckDefinition{
Name: "test",
CheckType: CheckType{
@ -916,10 +774,7 @@ func TestAgent_RegisterCheck_BadStatus(t *testing.T) {
defer srv.agent.Shutdown()
// Register node
req, err := http.NewRequest("GET", "/v1/agent/check/register", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/check/register", nil)
args := &CheckDefinition{
Name: "test",
CheckType: CheckType{
@ -945,10 +800,7 @@ func TestAgent_RegisterCheck_ACLDeny(t *testing.T) {
defer srv.agent.Shutdown()
// Try with no token.
req, err := http.NewRequest("GET", "/v1/agent/check/register", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/check/register", nil)
args := &CheckDefinition{
Name: "test",
CheckType: CheckType{
@ -956,19 +808,15 @@ func TestAgent_RegisterCheck_ACLDeny(t *testing.T) {
},
}
req.Body = encodeReq(args)
_, err = srv.AgentRegisterCheck(nil, req)
_, err := srv.AgentRegisterCheck(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
// Try the root token.
req, err = http.NewRequest("GET", "/v1/agent/check/register?token=root", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/agent/check/register?token=root", nil)
req.Body = encodeReq(args)
_, err = srv.AgentRegisterCheck(nil, req)
if err != nil {
if _, err := srv.AgentRegisterCheck(nil, req); err != nil {
t.Fatalf("err: %v", err)
}
}
@ -985,11 +833,7 @@ func TestAgent_DeregisterCheck(t *testing.T) {
}
// Register node
req, err := http.NewRequest("GET", "/v1/agent/check/deregister/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/check/deregister/test", nil)
obj, err := srv.AgentDeregisterCheck(nil, req)
if err != nil {
t.Fatalf("err: %v", err)
@ -1016,22 +860,15 @@ func TestAgent_DeregisterCheckACLDeny(t *testing.T) {
}
// Try with no token.
req, err := http.NewRequest("GET", "/v1/agent/check/deregister/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentDeregisterCheck(nil, req)
req, _ := http.NewRequest("GET", "/v1/agent/check/deregister/test", nil)
_, err := srv.AgentDeregisterCheck(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
// Try with the root token.
req, err = http.NewRequest("GET", "/v1/agent/check/deregister/test?token=root", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentDeregisterCheck(nil, req)
if err != nil {
req, _ = http.NewRequest("GET", "/v1/agent/check/deregister/test?token=root", nil)
if _, err := srv.AgentDeregisterCheck(nil, req); err != nil {
t.Fatalf("err: %v", err)
}
}
@ -1048,11 +885,7 @@ func TestAgent_PassCheck(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/agent/check/pass/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/check/pass/test", nil)
obj, err := srv.AgentCheckPass(nil, req)
if err != nil {
t.Fatalf("err: %v", err)
@ -1081,22 +914,15 @@ func TestAgent_PassCheck_ACLDeny(t *testing.T) {
}
// Try with no token.
req, err := http.NewRequest("GET", "/v1/agent/check/pass/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentCheckPass(nil, req)
req, _ := http.NewRequest("GET", "/v1/agent/check/pass/test", nil)
_, err := srv.AgentCheckPass(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
// Try with the root token.
req, err = http.NewRequest("GET", "/v1/agent/check/pass/test?token=root", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentCheckPass(nil, req)
if err != nil {
req, _ = http.NewRequest("GET", "/v1/agent/check/pass/test?token=root", nil)
if _, err := srv.AgentCheckPass(nil, req); err != nil {
t.Fatalf("err: %v", err)
}
}
@ -1113,11 +939,7 @@ func TestAgent_WarnCheck(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/agent/check/warn/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/check/warn/test", nil)
obj, err := srv.AgentCheckWarn(nil, req)
if err != nil {
t.Fatalf("err: %v", err)
@ -1146,22 +968,15 @@ func TestAgent_WarnCheck_ACLDeny(t *testing.T) {
}
// Try with no token.
req, err := http.NewRequest("GET", "/v1/agent/check/warn/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentCheckWarn(nil, req)
req, _ := http.NewRequest("GET", "/v1/agent/check/warn/test", nil)
_, err := srv.AgentCheckWarn(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
// Try with the root token.
req, err = http.NewRequest("GET", "/v1/agent/check/warn/test?token=root", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentCheckWarn(nil, req)
if err != nil {
req, _ = http.NewRequest("GET", "/v1/agent/check/warn/test?token=root", nil)
if _, err := srv.AgentCheckWarn(nil, req); err != nil {
t.Fatalf("err: %v", err)
}
}
@ -1178,11 +993,7 @@ func TestAgent_FailCheck(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/agent/check/fail/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/check/fail/test", nil)
obj, err := srv.AgentCheckFail(nil, req)
if err != nil {
t.Fatalf("err: %v", err)
@ -1211,22 +1022,15 @@ func TestAgent_FailCheck_ACLDeny(t *testing.T) {
}
// Try with no token.
req, err := http.NewRequest("GET", "/v1/agent/check/fail/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentCheckFail(nil, req)
req, _ := http.NewRequest("GET", "/v1/agent/check/fail/test", nil)
_, err := srv.AgentCheckFail(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
// Try with the root token.
req, err = http.NewRequest("GET", "/v1/agent/check/fail/test?token=root", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentCheckFail(nil, req)
if err != nil {
req, _ = http.NewRequest("GET", "/v1/agent/check/fail/test?token=root", nil)
if _, err := srv.AgentCheckFail(nil, req); err != nil {
t.Fatalf("err: %v", err)
}
}
@ -1250,10 +1054,7 @@ func TestAgent_UpdateCheck(t *testing.T) {
}
for _, c := range cases {
req, err := http.NewRequest("PUT", "/v1/agent/check/update/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/agent/check/update/test", nil)
req.Body = encodeReq(c)
resp := httptest.NewRecorder()
@ -1276,11 +1077,7 @@ func TestAgent_UpdateCheck(t *testing.T) {
// Make sure abusive levels of output are capped.
{
req, err := http.NewRequest("PUT", "/v1/agent/check/update/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/agent/check/update/test", nil)
update := checkUpdate{
Status: api.HealthPassing,
Output: strings.Repeat("-= bad -=", 5*CheckBufSize),
@ -1310,11 +1107,7 @@ func TestAgent_UpdateCheck(t *testing.T) {
// Check a bogus status.
{
req, err := http.NewRequest("PUT", "/v1/agent/check/update/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/agent/check/update/test", nil)
update := checkUpdate{
Status: "itscomplicated",
}
@ -1335,11 +1128,7 @@ func TestAgent_UpdateCheck(t *testing.T) {
// Check a bogus verb.
{
req, err := http.NewRequest("POST", "/v1/agent/check/update/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("POST", "/v1/agent/check/update/test", nil)
update := checkUpdate{
Status: api.HealthPassing,
}
@ -1372,24 +1161,17 @@ func TestAgent_UpdateCheck_ACLDeny(t *testing.T) {
}
// Try with no token.
req, err := http.NewRequest("PUT", "/v1/agent/check/update/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/agent/check/update/test", nil)
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) {
t.Fatalf("err: %v", err)
}
// Try with the root token.
req, err = http.NewRequest("PUT", "/v1/agent/check/update/test?token=root", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("PUT", "/v1/agent/check/update/test?token=root", nil)
req.Body = encodeReq(checkUpdate{api.HealthPassing, "hello-passing"})
_, err = srv.AgentCheckUpdate(nil, req)
if err != nil {
if _, err := srv.AgentCheckUpdate(nil, req); err != nil {
t.Fatalf("err: %v", err)
}
}
@ -1400,10 +1182,7 @@ func TestAgent_RegisterService(t *testing.T) {
defer srv.Shutdown()
defer srv.agent.Shutdown()
req, err := http.NewRequest("GET", "/v1/agent/service/register?token=abc123", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/service/register?token=abc123", nil)
args := &ServiceDefinition{
Name: "test",
Tags: []string{"master"},
@ -1475,24 +1254,17 @@ func TestAgent_RegisterService_ACLDeny(t *testing.T) {
}
// Try with no token.
req, err := http.NewRequest("GET", "/v1/agent/service/register", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/service/register", nil)
req.Body = encodeReq(args)
_, err = srv.AgentRegisterService(nil, req)
_, err := srv.AgentRegisterService(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
// Try with the root token.
req, err = http.NewRequest("GET", "/v1/agent/service/register?token=root", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/agent/service/register?token=root", nil)
req.Body = encodeReq(args)
_, err = srv.AgentRegisterService(nil, req)
if err != nil {
if _, err := srv.AgentRegisterService(nil, req); err != nil {
t.Fatalf("err: %v", err)
}
}
@ -1542,11 +1314,7 @@ func TestAgent_DeregisterService(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/agent/service/deregister/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/service/deregister/test", nil)
obj, err := srv.AgentDeregisterService(nil, req)
if err != nil {
t.Fatalf("err: %v", err)
@ -1580,22 +1348,15 @@ func TestAgent_DeregisterService_ACLDeny(t *testing.T) {
}
// Try without a token.
req, err := http.NewRequest("GET", "/v1/agent/service/deregister/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentDeregisterService(nil, req)
req, _ := http.NewRequest("GET", "/v1/agent/service/deregister/test", nil)
_, err := srv.AgentDeregisterService(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
// Try with the root.
req, err = http.NewRequest("GET", "/v1/agent/service/deregister/test?token=root", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentDeregisterService(nil, req)
if err != nil {
req, _ = http.NewRequest("GET", "/v1/agent/service/deregister/test?token=root", nil)
if _, err := srv.AgentDeregisterService(nil, req); err != nil {
t.Fatalf("err: %v", err)
}
}
@ -1743,22 +1504,15 @@ func TestAgent_ServiceMaintenance_ACLDeny(t *testing.T) {
}
// Try with no token.
req, err := http.NewRequest("PUT", "/v1/agent/service/maintenance/test?enable=true&reason=broken", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentServiceMaintenance(nil, req)
req, _ := http.NewRequest("PUT", "/v1/agent/service/maintenance/test?enable=true&reason=broken", nil)
_, err := srv.AgentServiceMaintenance(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
// Try with the root token.
req, err = http.NewRequest("PUT", "/v1/agent/service/maintenance/test?enable=true&reason=broken&token=root", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentServiceMaintenance(nil, req)
if err != nil {
req, _ = http.NewRequest("PUT", "/v1/agent/service/maintenance/test?enable=true&reason=broken&token=root", nil)
if _, err := srv.AgentServiceMaintenance(nil, req); err != nil {
t.Fatalf("err: %v", err)
}
}
@ -1797,8 +1551,7 @@ func TestAgent_NodeMaintenance_Enable(t *testing.T) {
defer srv.agent.Shutdown()
// Force the node into maintenance mode
req, _ := http.NewRequest(
"PUT", "/v1/agent/self/maintenance?enable=true&reason=broken&token=mytoken", nil)
req, _ := http.NewRequest("PUT", "/v1/agent/self/maintenance?enable=true&reason=broken&token=mytoken", nil)
resp := httptest.NewRecorder()
if _, err := srv.AgentNodeMaintenance(resp, req); err != nil {
t.Fatalf("err: %s", err)
@ -1856,24 +1609,15 @@ func TestAgent_NodeMaintenance_ACLDeny(t *testing.T) {
defer srv.agent.Shutdown()
// Try with no token.
req, err := http.NewRequest(
"PUT", "/v1/agent/self/maintenance?enable=true&reason=broken", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentNodeMaintenance(nil, req)
req, _ := http.NewRequest("PUT", "/v1/agent/self/maintenance?enable=true&reason=broken", nil)
_, err := srv.AgentNodeMaintenance(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
// Try with the root token.
req, err = http.NewRequest(
"PUT", "/v1/agent/self/maintenance?enable=true&reason=broken&token=root", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentNodeMaintenance(nil, req)
if err != nil {
req, _ = http.NewRequest("PUT", "/v1/agent/self/maintenance?enable=true&reason=broken&token=root", nil)
if _, err := srv.AgentNodeMaintenance(nil, req); err != nil {
t.Fatalf("err: %v", err)
}
}
@ -1885,10 +1629,7 @@ func TestAgent_RegisterCheck_Service(t *testing.T) {
defer srv.agent.Shutdown()
// First register the service
req, err := http.NewRequest("GET", "/v1/agent/service/register", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/agent/service/register", nil)
args := &ServiceDefinition{
Name: "memcache",
Port: 8000,
@ -1903,10 +1644,7 @@ func TestAgent_RegisterCheck_Service(t *testing.T) {
}
// Now register an additional check
req, err = http.NewRequest("GET", "/v1/agent/check/register", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/agent/check/register", nil)
checkArgs := &CheckDefinition{
Name: "memcache_check2",
ServiceID: "memcache",
@ -2007,13 +1745,8 @@ func TestAgent_Monitor_ACLDeny(t *testing.T) {
defer srv.agent.Shutdown()
// Try without a token.
req, err := http.NewRequest("GET", "/v1/agent/monitor", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
_, err = srv.AgentMonitor(nil, req)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
req, _ := http.NewRequest("GET", "/v1/agent/monitor", nil)
if _, err := srv.AgentMonitor(nil, req); err != errPermissionDenied {
t.Fatalf("err: %v", err)
}

View File

@ -23,10 +23,7 @@ func TestCatalogRegister(t *testing.T) {
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
// Register node
req, err := http.NewRequest("GET", "/v1/catalog/register", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/register", nil)
args := &structs.RegisterRequest{
Node: "foo",
Address: "127.0.0.1",
@ -97,10 +94,7 @@ func TestCatalogDeregister(t *testing.T) {
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
// Register node
req, err := http.NewRequest("GET", "/v1/catalog/deregister", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/deregister", nil)
args := &structs.DeregisterRequest{
Node: "foo",
}
@ -156,11 +150,7 @@ func TestCatalogNodes(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/catalog/nodes?dc=dc1", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?dc=dc1", nil)
resp := httptest.NewRecorder()
obj, err := srv.CatalogNodes(resp, req)
if err != nil {
@ -199,11 +189,7 @@ func TestCatalogNodes_MetaFilter(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/catalog/nodes?node-meta=somekey:somevalue", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?node-meta=somekey:somevalue", nil)
resp := httptest.NewRecorder()
obj, err := srv.CatalogNodes(resp, req)
if err != nil {
@ -278,11 +264,7 @@ func TestCatalogNodes_WanTranslation(t *testing.T) {
}
// Query nodes in DC2 from DC1.
req, err := http.NewRequest("GET", "/v1/catalog/nodes?dc=dc2", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?dc=dc2", nil)
resp1 := httptest.NewRecorder()
obj1, err1 := srv1.CatalogNodes(resp1, req)
if err1 != nil {
@ -362,12 +344,7 @@ func TestCatalogNodes_Blocking(t *testing.T) {
}()
// Do a blocking read
req, err := http.NewRequest("GET",
fmt.Sprintf("/v1/catalog/nodes?wait=60s&index=%d", out.Index), nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/catalog/nodes?wait=60s&index=%d", out.Index), nil)
resp := httptest.NewRecorder()
obj, err := srv.CatalogNodes(resp, req)
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
// order they are indexed.
req, err := http.NewRequest("GET", "/v1/catalog/nodes?dc=dc1&near=foo", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?dc=dc1&near=foo", nil)
resp := httptest.NewRecorder()
obj, err := srv.CatalogNodes(resp, req)
if err != nil {
@ -457,11 +430,7 @@ func TestCatalogNodes_DistanceSort(t *testing.T) {
time.Sleep(300 * time.Millisecond)
// 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)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/catalog/nodes?dc=dc1&near=foo", nil)
resp = httptest.NewRecorder()
obj, err = srv.CatalogNodes(resp, req)
if err != nil {
@ -507,11 +476,7 @@ func TestCatalogServices(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/catalog/services?dc=dc1", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/services?dc=dc1", nil)
resp := httptest.NewRecorder()
obj, err := srv.CatalogServices(resp, req)
if err != nil {
@ -552,11 +517,7 @@ func TestCatalogServices_NodeMetaFilter(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/catalog/services?node-meta=somekey:somevalue", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/services?node-meta=somekey:somevalue", nil)
resp := httptest.NewRecorder()
obj, err := srv.CatalogServices(resp, req)
if err != nil {
@ -584,11 +545,7 @@ func TestCatalogServiceNodes(t *testing.T) {
// Make sure an empty list is returned, not a nil
{
req, err := http.NewRequest("GET", "/v1/catalog/service/api?tag=a", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/service/api?tag=a", nil)
resp := httptest.NewRecorder()
obj, err := srv.CatalogServiceNodes(resp, req)
if err != nil {
@ -619,11 +576,7 @@ func TestCatalogServiceNodes(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/catalog/service/api?tag=a", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/service/api?tag=a", nil)
resp := httptest.NewRecorder()
obj, err := srv.CatalogServiceNodes(resp, req)
if err != nil {
@ -648,11 +601,7 @@ func TestCatalogServiceNodes_NodeMetaFilter(t *testing.T) {
// Make sure an empty list is returned, not a nil
{
req, err := http.NewRequest("GET", "/v1/catalog/service/api?node-meta=somekey:somevalue", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/service/api?node-meta=somekey:somevalue", nil)
resp := httptest.NewRecorder()
obj, err := srv.CatalogServiceNodes(resp, req)
if err != nil {
@ -685,11 +634,7 @@ func TestCatalogServiceNodes_NodeMetaFilter(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/catalog/service/api?node-meta=somekey:somevalue", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/service/api?node-meta=somekey:somevalue", nil)
resp := httptest.NewRecorder()
obj, err := srv.CatalogServiceNodes(resp, req)
if err != nil {
@ -760,11 +705,7 @@ func TestCatalogServiceNodes_WanTranslation(t *testing.T) {
}
// Query for the node in DC2 from DC1.
req, err := http.NewRequest("GET", "/v1/catalog/service/http_wan_translation_test?dc=dc2", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/service/http_wan_translation_test?dc=dc2", nil)
resp1 := httptest.NewRecorder()
obj1, err1 := srv1.CatalogServiceNodes(resp1, req)
if err1 != nil {
@ -824,11 +765,7 @@ func TestCatalogServiceNodes_DistanceSort(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/catalog/service/api?tag=a", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/service/api?tag=a", nil)
args = &structs.RegisterRequest{
Datacenter: "dc1",
Node: "foo",
@ -844,11 +781,7 @@ func TestCatalogServiceNodes_DistanceSort(t *testing.T) {
// Nobody has coordinates set so this will still return them in the
// order they are indexed.
req, err = http.NewRequest("GET", "/v1/catalog/service/api?tag=a&near=foo", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/catalog/service/api?tag=a&near=foo", nil)
resp := httptest.NewRecorder()
obj, err := srv.CatalogServiceNodes(resp, req)
if err != nil {
@ -879,11 +812,7 @@ func TestCatalogServiceNodes_DistanceSort(t *testing.T) {
time.Sleep(300 * time.Millisecond)
// 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)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/catalog/service/api?tag=a&near=foo", nil)
resp = httptest.NewRecorder()
obj, err = srv.CatalogServiceNodes(resp, req)
if err != nil {
@ -927,11 +856,7 @@ func TestCatalogNodeServices(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/catalog/node/foo?dc=dc1", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/node/foo?dc=dc1", nil)
resp := httptest.NewRecorder()
obj, err := srv.CatalogNodeServices(resp, req)
if err != nil {
@ -1001,10 +926,7 @@ func TestCatalogNodeServices_WanTranslation(t *testing.T) {
}
// Query for the node in DC2 from DC1.
req, err := http.NewRequest("GET", "/v1/catalog/node/foo?dc=dc2", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/node/foo?dc=dc2", nil)
resp1 := httptest.NewRecorder()
obj1, err1 := srv1.CatalogNodeServices(resp1, req)
if err1 != nil {

View File

@ -20,11 +20,7 @@ func TestCoordinate_Datacenters(t *testing.T) {
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
req, err := http.NewRequest("GET", "/v1/coordinate/datacenters", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/coordinate/datacenters", nil)
resp := httptest.NewRecorder()
obj, err := srv.CoordinateDatacenters(resp, req)
if err != nil {
@ -49,11 +45,7 @@ func TestCoordinate_Nodes(t *testing.T) {
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
// Make sure an empty list is non-nil.
req, err := http.NewRequest("GET", "/v1/coordinate/nodes?dc=dc1", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/coordinate/nodes?dc=dc1", nil)
resp := httptest.NewRecorder()
obj, err := srv.CoordinateNodes(resp, req)
if err != nil {
@ -102,11 +94,7 @@ func TestCoordinate_Nodes(t *testing.T) {
time.Sleep(300 * time.Millisecond)
// Query back and check the nodes are present and sorted correctly.
req, err = http.NewRequest("GET", "/v1/coordinate/nodes?dc=dc1", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/coordinate/nodes?dc=dc1", nil)
resp = httptest.NewRecorder()
obj, err = srv.CoordinateNodes(resp, req)
if err != nil {

View File

@ -18,10 +18,7 @@ func TestEventFire(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer([]byte("test"))
url := "/v1/event/fire/test?node=Node&service=foo&tag=bar"
req, err := http.NewRequest("PUT", url, body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", url, body)
resp := httptest.NewRecorder()
obj, err := srv.EventFire(resp, req)
if err != nil {
@ -84,10 +81,7 @@ func TestEventFire_token(t *testing.T) {
for _, c := range tcases {
// Try to fire the event over the HTTP interface
url := fmt.Sprintf("/v1/event/fire/%s?token=%s", c.event, token)
req, err := http.NewRequest("PUT", url, nil)
if err != nil {
t.Fatalf("err: %s", err)
}
req, _ := http.NewRequest("PUT", url, nil)
resp := httptest.NewRecorder()
if _, err := srv.EventFire(resp, req); err != nil {
t.Fatalf("err: %s", err)
@ -124,10 +118,7 @@ func TestEventList(t *testing.T) {
}
retry.Run(t, func(r *retry.R) {
req, err := http.NewRequest("GET", "/v1/event/list", nil)
if err != nil {
r.Fatal(err)
}
req, _ := http.NewRequest("GET", "/v1/event/list", nil)
resp := httptest.NewRecorder()
obj, err := srv.EventList(resp, req)
if err != nil {
@ -162,10 +153,7 @@ func TestEventList_Filter(t *testing.T) {
}
retry.Run(t, func(r *retry.R) {
req, err := http.NewRequest("GET", "/v1/event/list?name=foo", nil)
if err != nil {
r.Fatal(err)
}
req, _ := http.NewRequest("GET", "/v1/event/list?name=foo", nil)
resp := httptest.NewRecorder()
obj, err := srv.EventList(resp, req)
if err != nil {
@ -202,10 +190,7 @@ func TestEventList_ACLFilter(t *testing.T) {
// Try no token.
{
retry.Run(t, func(r *retry.R) {
req, err := http.NewRequest("GET", "/v1/event/list", nil)
if err != nil {
r.Fatal(err)
}
req, _ := http.NewRequest("GET", "/v1/event/list", nil)
resp := httptest.NewRecorder()
obj, err := srv.EventList(resp, req)
if err != nil {
@ -225,10 +210,7 @@ func TestEventList_ACLFilter(t *testing.T) {
// Try the root token.
{
retry.Run(t, func(r *retry.R) {
req, err := http.NewRequest("GET", "/v1/event/list?token=root", nil)
if err != nil {
r.Fatal(err)
}
req, _ := http.NewRequest("GET", "/v1/event/list?token=root", nil)
resp := httptest.NewRecorder()
obj, err := srv.EventList(resp, req)
if err != nil {
@ -255,13 +237,9 @@ func TestEventList_Blocking(t *testing.T) {
var index string
retry.Run(t, func(r *retry.R) {
req, err := http.NewRequest("GET", "/v1/event/list", nil)
if err != nil {
r.Fatal(err)
}
req, _ := http.NewRequest("GET", "/v1/event/list", nil)
resp := httptest.NewRecorder()
_, err = srv.EventList(resp, req)
if err != nil {
if _, err := srv.EventList(resp, req); err != nil {
r.Fatal(err)
}
header := resp.Header().Get("X-Consul-Index")
@ -281,10 +259,7 @@ func TestEventList_Blocking(t *testing.T) {
retry.Run(t, func(r *retry.R) {
url := "/v1/event/list?index=" + index
req, err := http.NewRequest("GET", url, nil)
if err != nil {
r.Fatal(err)
}
req, _ := http.NewRequest("GET", url, nil)
resp := httptest.NewRecorder()
obj, err := srv.EventList(resp, req)
if err != nil {
@ -322,10 +297,7 @@ func TestEventList_EventBufOrder(t *testing.T) {
// filtering on a list of > 1 matching event.
retry.Run(t, func(r *retry.R) {
url := "/v1/event/list?name=foo"
req, err := http.NewRequest("GET", url, nil)
if err != nil {
r.Fatal(err)
}
req, _ := http.NewRequest("GET", url, nil)
resp := httptest.NewRecorder()
obj, err := srv.EventList(resp, req)
if err != nil {

View File

@ -17,11 +17,7 @@ import (
func TestHealthChecksInState(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
req, err := http.NewRequest("GET", "/v1/health/state/warning?dc=dc1", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/health/state/warning?dc=dc1", nil)
retry.Run(t, func(r *retry.R) {
resp := httptest.NewRecorder()
obj, err := srv.HealthChecksInState(resp, req)
@ -41,11 +37,7 @@ func TestHealthChecksInState(t *testing.T) {
})
httpTest(t, func(srv *HTTPServer) {
req, err := http.NewRequest("GET", "/v1/health/state/passing?dc=dc1", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/health/state/passing?dc=dc1", nil)
retry.Run(t, func(r *retry.R) {
resp := httptest.NewRecorder()
obj, err := srv.HealthChecksInState(resp, req)
@ -83,11 +75,7 @@ func TestHealthChecksInState_NodeMetaFilter(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/health/state/critical?node-meta=somekey:somevalue", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/health/state/critical?node-meta=somekey:somevalue", nil)
retry.Run(t, func(r *retry.R) {
resp := httptest.NewRecorder()
obj, err := srv.HealthChecksInState(resp, req)
@ -136,11 +124,7 @@ func TestHealthChecksInState_DistanceSort(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/health/state/critical?dc=dc1&near=foo", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/health/state/critical?dc=dc1&near=foo", nil)
resp := httptest.NewRecorder()
obj, err := srv.HealthChecksInState(resp, req)
if err != nil {
@ -196,11 +180,7 @@ func TestHealthNodeChecks(t *testing.T) {
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
req, err := http.NewRequest("GET", "/v1/health/node/nope?dc=dc1", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/health/node/nope?dc=dc1", nil)
resp := httptest.NewRecorder()
obj, err := srv.HealthNodeChecks(resp, req)
if err != nil {
@ -214,12 +194,7 @@ func TestHealthNodeChecks(t *testing.T) {
t.Fatalf("bad: %v", obj)
}
req, err = http.NewRequest("GET",
fmt.Sprintf("/v1/health/node/%s?dc=dc1", srv.agent.config.NodeName), nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", fmt.Sprintf("/v1/health/node/%s?dc=dc1", srv.agent.config.NodeName), nil)
resp = httptest.NewRecorder()
obj, err = srv.HealthNodeChecks(resp, req)
if err != nil {
@ -242,11 +217,7 @@ func TestHealthServiceChecks(t *testing.T) {
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
req, err := http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1", nil)
resp := httptest.NewRecorder()
obj, err := srv.HealthServiceChecks(resp, req)
if err != nil {
@ -277,11 +248,7 @@ func TestHealthServiceChecks(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err = http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1", nil)
resp = httptest.NewRecorder()
obj, err = srv.HealthServiceChecks(resp, req)
if err != nil {
@ -304,11 +271,7 @@ func TestHealthServiceChecks_NodeMetaFilter(t *testing.T) {
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
req, err := http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1&node-meta=somekey:somevalue", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1&node-meta=somekey:somevalue", nil)
resp := httptest.NewRecorder()
obj, err := srv.HealthServiceChecks(resp, req)
if err != nil {
@ -340,11 +303,7 @@ func TestHealthServiceChecks_NodeMetaFilter(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err = http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1&node-meta=somekey:somevalue", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1&node-meta=somekey:somevalue", nil)
resp = httptest.NewRecorder()
obj, err = srv.HealthServiceChecks(resp, req)
if err != nil {
@ -393,11 +352,7 @@ func TestHealthServiceChecks_DistanceSort(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/health/checks/test?dc=dc1&near=foo", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/health/checks/test?dc=dc1&near=foo", nil)
resp := httptest.NewRecorder()
obj, err := srv.HealthServiceChecks(resp, req)
if err != nil {
@ -453,11 +408,7 @@ func TestHealthServiceNodes(t *testing.T) {
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
req, err := http.NewRequest("GET", "/v1/health/service/consul?dc=dc1", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/health/service/consul?dc=dc1", nil)
resp := httptest.NewRecorder()
obj, err := srv.HealthServiceNodes(resp, req)
if err != nil {
@ -472,11 +423,7 @@ func TestHealthServiceNodes(t *testing.T) {
t.Fatalf("bad: %v", obj)
}
req, err = http.NewRequest("GET", "/v1/health/service/nope?dc=dc1", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/health/service/nope?dc=dc1", nil)
resp = httptest.NewRecorder()
obj, err = srv.HealthServiceNodes(resp, req)
if err != nil {
@ -506,11 +453,7 @@ func TestHealthServiceNodes(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err = http.NewRequest("GET", "/v1/health/service/test?dc=dc1", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/health/service/test?dc=dc1", nil)
resp = httptest.NewRecorder()
obj, err = srv.HealthServiceNodes(resp, req)
if err != nil {
@ -534,11 +477,7 @@ func TestHealthServiceNodes_NodeMetaFilter(t *testing.T) {
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
req, err := http.NewRequest("GET", "/v1/health/service/consul?dc=dc1&node-meta=somekey:somevalue", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/health/service/consul?dc=dc1&node-meta=somekey:somevalue", nil)
resp := httptest.NewRecorder()
obj, err := srv.HealthServiceNodes(resp, req)
if err != nil {
@ -569,11 +508,7 @@ func TestHealthServiceNodes_NodeMetaFilter(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err = http.NewRequest("GET", "/v1/health/service/test?dc=dc1&node-meta=somekey:somevalue", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/health/service/test?dc=dc1&node-meta=somekey:somevalue", nil)
resp = httptest.NewRecorder()
obj, err = srv.HealthServiceNodes(resp, req)
if err != nil {
@ -623,11 +558,7 @@ func TestHealthServiceNodes_DistanceSort(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/health/service/test?dc=dc1&near=foo", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/health/service/test?dc=dc1&near=foo", nil)
resp := httptest.NewRecorder()
obj, err := srv.HealthServiceNodes(resp, req)
if err != nil {
@ -701,11 +632,7 @@ func TestHealthServiceNodes_PassingFilter(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/health/service/consul?passing", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/health/service/consul?passing", nil)
resp := httptest.NewRecorder()
obj, err := srv.HealthServiceNodes(resp, req)
if err != nil {
@ -776,10 +703,7 @@ func TestHealthServiceNodes_WanTranslation(t *testing.T) {
}
// Query for a service in DC2 from DC1.
req, err := http.NewRequest("GET", "/v1/health/service/http_wan_translation_test?dc=dc2", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/health/service/http_wan_translation_test?dc=dc2", nil)
resp1 := httptest.NewRecorder()
obj1, err1 := srv1.HealthServiceNodes(resp1, req)
if err1 != nil {

View File

@ -357,7 +357,6 @@ func TestHTTP_wrap_obfuscateLog(t *testing.T) {
resp := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/some/url?token=secret1&token=secret2", nil)
handler := func(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
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
// just give them the cheapest possible query).
req, err := http.NewRequest("GET",
"/v1/catalog/nodes", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/nodes", nil)
source := structs.QuerySource{}
srv.parseSource(req, &source)
if source.Datacenter != "dc1" || source.Node != "" {
@ -426,11 +421,7 @@ func TestParseSource(t *testing.T) {
}
// Adding the source parameter should set that node.
req, err = http.NewRequest("GET",
"/v1/catalog/nodes?near=bob", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/catalog/nodes?near=bob", nil)
source = structs.QuerySource{}
srv.parseSource(req, &source)
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
// looked up correctly on the receiving end.
req, err = http.NewRequest("GET",
"/v1/catalog/nodes?near=bob&dc=foo", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/catalog/nodes?near=bob&dc=foo", nil)
source = structs.QuerySource{}
srv.parseSource(req, &source)
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.
req, err = http.NewRequest("GET",
"/v1/catalog/nodes?near=_agent", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/catalog/nodes?near=_agent", nil)
source = structs.QuerySource{}
srv.parseSource(req, &source)
if source.Datacenter != "dc1" || source.Node != srv.agent.config.NodeName {
@ -467,12 +450,7 @@ func TestParseWait(t *testing.T) {
resp := httptest.NewRecorder()
var b structs.QueryOptions
req, err := http.NewRequest("GET",
"/v1/catalog/nodes?wait=60s&index=1000", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?wait=60s&index=1000", nil)
if d := parseWait(resp, req, &b); d {
t.Fatalf("unexpected done")
}
@ -489,12 +467,7 @@ func TestParseWait_InvalidTime(t *testing.T) {
resp := httptest.NewRecorder()
var b structs.QueryOptions
req, err := http.NewRequest("GET",
"/v1/catalog/nodes?wait=60foo&index=1000", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?wait=60foo&index=1000", nil)
if d := parseWait(resp, req, &b); !d {
t.Fatalf("expected done")
}
@ -508,12 +481,7 @@ func TestParseWait_InvalidIndex(t *testing.T) {
resp := httptest.NewRecorder()
var b structs.QueryOptions
req, err := http.NewRequest("GET",
"/v1/catalog/nodes?wait=60s&index=foo", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?wait=60s&index=foo", nil)
if d := parseWait(resp, req, &b); !d {
t.Fatalf("expected done")
}
@ -527,12 +495,7 @@ func TestParseConsistency(t *testing.T) {
resp := httptest.NewRecorder()
var b structs.QueryOptions
req, err := http.NewRequest("GET",
"/v1/catalog/nodes?stale", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?stale", nil)
if d := parseConsistency(resp, req, &b); d {
t.Fatalf("unexpected done")
}
@ -545,12 +508,7 @@ func TestParseConsistency(t *testing.T) {
}
b = structs.QueryOptions{}
req, err = http.NewRequest("GET",
"/v1/catalog/nodes?consistent", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/catalog/nodes?consistent", nil)
if d := parseConsistency(resp, req, &b); d {
t.Fatalf("unexpected done")
}
@ -567,12 +525,7 @@ func TestParseConsistency_Invalid(t *testing.T) {
resp := httptest.NewRecorder()
var b structs.QueryOptions
req, err := http.NewRequest("GET",
"/v1/catalog/nodes?stale&consistent", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/nodes?stale&consistent", nil)
if d := parseConsistency(resp, req, &b); !d {
t.Fatalf("expected done")
}
@ -586,33 +539,15 @@ func TestParseConsistency_Invalid(t *testing.T) {
func TestACLResolution(t *testing.T) {
var token string
// Request without token
req, err := http.NewRequest("GET",
"/v1/catalog/nodes", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/catalog/nodes", nil)
// Request with explicit token
reqToken, err := http.NewRequest("GET",
"/v1/catalog/nodes?token=foo", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
reqToken, _ := http.NewRequest("GET", "/v1/catalog/nodes?token=foo", nil)
// Request with header token only
reqHeaderToken, err := http.NewRequest("GET",
"/v1/catalog/nodes", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
reqHeaderToken, _ := http.NewRequest("GET", "/v1/catalog/nodes", nil)
reqHeaderToken.Header.Add("X-Consul-Token", "bar")
// Request with header and querystring tokens
reqBothTokens, err := http.NewRequest("GET",
"/v1/catalog/nodes?token=baz", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
reqBothTokens, _ := http.NewRequest("GET", "/v1/catalog/nodes?token=baz", nil)
reqBothTokens.Header.Add("X-Consul-Token", "zap")
httpTest(t, func(srv *HTTPServer) {
@ -706,11 +641,7 @@ func TestScadaHTTP(t *testing.T) {
func TestEnableWebUI(t *testing.T) {
httpTestWithConfig(t, func(s *HTTPServer) {
req, err := http.NewRequest("GET", "/ui/", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/ui/", nil)
// Perform the request
resp := httptest.NewRecorder()
s.mux.ServeHTTP(resp, req)

View File

@ -31,11 +31,7 @@ func TestKVSEndpoint_PUT_GET_DELETE(t *testing.T) {
for _, key := range keys {
buf := bytes.NewBuffer([]byte("test"))
req, err := http.NewRequest("PUT", "/v1/kv/"+key, buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/kv/"+key, buf)
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -48,11 +44,7 @@ func TestKVSEndpoint_PUT_GET_DELETE(t *testing.T) {
}
for _, key := range keys {
req, err := http.NewRequest("GET", "/v1/kv/"+key, nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/kv/"+key, nil)
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -75,14 +67,9 @@ func TestKVSEndpoint_PUT_GET_DELETE(t *testing.T) {
}
for _, key := range keys {
req, err := http.NewRequest("DELETE", "/v1/kv/"+key, nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("DELETE", "/v1/kv/"+key, nil)
resp := httptest.NewRecorder()
_, err = srv.KVSEndpoint(resp, req)
if err != nil {
if _, err := srv.KVSEndpoint(resp, req); err != nil {
t.Fatalf("err: %v", err)
}
}
@ -106,11 +93,7 @@ func TestKVSEndpoint_Recurse(t *testing.T) {
for _, key := range keys {
buf := bytes.NewBuffer([]byte("test"))
req, err := http.NewRequest("PUT", "/v1/kv/"+key, buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/kv/"+key, buf)
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -124,11 +107,7 @@ func TestKVSEndpoint_Recurse(t *testing.T) {
{
// Get all the keys
req, err := http.NewRequest("GET", "/v1/kv/?recurse", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/kv/?recurse", nil)
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -153,25 +132,16 @@ func TestKVSEndpoint_Recurse(t *testing.T) {
}
{
req, err := http.NewRequest("DELETE", "/v1/kv/?recurse", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("DELETE", "/v1/kv/?recurse", nil)
resp := httptest.NewRecorder()
_, err = srv.KVSEndpoint(resp, req)
if err != nil {
if _, err := srv.KVSEndpoint(resp, req); err != nil {
t.Fatalf("err: %v", err)
}
}
{
// Get all the keys
req, err := http.NewRequest("GET", "/v1/kv/?recurse", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/kv/?recurse", nil)
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -194,11 +164,7 @@ func TestKVSEndpoint_DELETE_CAS(t *testing.T) {
{
buf := bytes.NewBuffer([]byte("test"))
req, err := http.NewRequest("PUT", "/v1/kv/test", buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/kv/test", buf)
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -210,11 +176,7 @@ func TestKVSEndpoint_DELETE_CAS(t *testing.T) {
}
}
req, err := http.NewRequest("GET", "/v1/kv/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/kv/test", nil)
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -225,12 +187,7 @@ func TestKVSEndpoint_DELETE_CAS(t *testing.T) {
// Create a CAS request, bad index
{
buf := bytes.NewBuffer([]byte("zip"))
req, err := http.NewRequest("DELETE",
fmt.Sprintf("/v1/kv/test?cas=%d", d.ModifyIndex-1), buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("DELETE", fmt.Sprintf("/v1/kv/test?cas=%d", d.ModifyIndex-1), buf)
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -245,12 +202,7 @@ func TestKVSEndpoint_DELETE_CAS(t *testing.T) {
// Create a CAS request, good index
{
buf := bytes.NewBuffer([]byte("zip"))
req, err := http.NewRequest("DELETE",
fmt.Sprintf("/v1/kv/test?cas=%d", d.ModifyIndex), buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("DELETE", fmt.Sprintf("/v1/kv/test?cas=%d", d.ModifyIndex), buf)
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -281,11 +233,7 @@ func TestKVSEndpoint_CAS(t *testing.T) {
{
buf := bytes.NewBuffer([]byte("test"))
req, err := http.NewRequest("PUT", "/v1/kv/test?flags=50", buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/kv/test?flags=50", buf)
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -297,11 +245,7 @@ func TestKVSEndpoint_CAS(t *testing.T) {
}
}
req, err := http.NewRequest("GET", "/v1/kv/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/kv/test", nil)
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -317,12 +261,7 @@ func TestKVSEndpoint_CAS(t *testing.T) {
// Create a CAS request, bad index
{
buf := bytes.NewBuffer([]byte("zip"))
req, err := http.NewRequest("PUT",
fmt.Sprintf("/v1/kv/test?flags=42&cas=%d", d.ModifyIndex-1), buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", fmt.Sprintf("/v1/kv/test?flags=42&cas=%d", d.ModifyIndex-1), buf)
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -337,12 +276,7 @@ func TestKVSEndpoint_CAS(t *testing.T) {
// Create a CAS request, good index
{
buf := bytes.NewBuffer([]byte("zip"))
req, err := http.NewRequest("PUT",
fmt.Sprintf("/v1/kv/test?flags=42&cas=%d", d.ModifyIndex), buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", fmt.Sprintf("/v1/kv/test?flags=42&cas=%d", d.ModifyIndex), buf)
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -386,11 +320,7 @@ func TestKVSEndpoint_ListKeys(t *testing.T) {
for _, key := range keys {
buf := bytes.NewBuffer([]byte("test"))
req, err := http.NewRequest("PUT", "/v1/kv/"+key, buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/kv/"+key, buf)
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -404,11 +334,7 @@ func TestKVSEndpoint_ListKeys(t *testing.T) {
{
// Get all the keys
req, err := http.NewRequest("GET", "/v1/kv/?keys&seperator=/", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/kv/?keys&seperator=/", nil)
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -432,12 +358,7 @@ func TestKVSEndpoint_AcquireRelease(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
// Acquire the lock
id := makeTestSession(t, srv)
req, err := http.NewRequest("PUT",
"/v1/kv/test?acquire="+id, bytes.NewReader(nil))
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/kv/test?acquire="+id, bytes.NewReader(nil))
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -448,10 +369,7 @@ func TestKVSEndpoint_AcquireRelease(t *testing.T) {
}
// Verify we have the lock
req, err = http.NewRequest("GET", "/v1/kv/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/kv/test", nil)
resp = httptest.NewRecorder()
obj, err = srv.KVSEndpoint(resp, req)
if err != nil {
@ -465,11 +383,7 @@ func TestKVSEndpoint_AcquireRelease(t *testing.T) {
}
// Release the lock
req, err = http.NewRequest("PUT",
"/v1/kv/test?release="+id, bytes.NewReader(nil))
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("PUT", "/v1/kv/test?release="+id, bytes.NewReader(nil))
resp = httptest.NewRecorder()
obj, err = srv.KVSEndpoint(resp, req)
if err != nil {
@ -480,10 +394,7 @@ func TestKVSEndpoint_AcquireRelease(t *testing.T) {
}
// Verify we do not have the lock
req, err = http.NewRequest("GET", "/v1/kv/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/kv/test", nil)
resp = httptest.NewRecorder()
obj, err = srv.KVSEndpoint(resp, req)
if err != nil {
@ -501,10 +412,7 @@ func TestKVSEndpoint_AcquireRelease(t *testing.T) {
func TestKVSEndpoint_GET_Raw(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
buf := bytes.NewBuffer([]byte("test"))
req, err := http.NewRequest("PUT", "/v1/kv/test", buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/kv/test", buf)
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -514,10 +422,7 @@ func TestKVSEndpoint_GET_Raw(t *testing.T) {
t.Fatalf("should work")
}
req, err = http.NewRequest("GET", "/v1/kv/test?raw", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/kv/test?raw", nil)
resp = httptest.NewRecorder()
obj, err = srv.KVSEndpoint(resp, req)
if err != nil {
@ -534,11 +439,7 @@ func TestKVSEndpoint_GET_Raw(t *testing.T) {
func TestKVSEndpoint_PUT_ConflictingFlags(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
req, err := http.NewRequest("PUT", "/v1/kv/test?cas=0&acquire=xxx", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/kv/test?cas=0&acquire=xxx", nil)
resp := httptest.NewRecorder()
if _, err := srv.KVSEndpoint(resp, req); err != nil {
t.Fatalf("err: %v", err)
@ -555,11 +456,7 @@ func TestKVSEndpoint_PUT_ConflictingFlags(t *testing.T) {
func TestKVSEndpoint_DELETE_ConflictingFlags(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
req, err := http.NewRequest("DELETE", "/v1/kv/test?recurse&cas=0", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("DELETE", "/v1/kv/test?recurse&cas=0", nil)
resp := httptest.NewRecorder()
if _, err := srv.KVSEndpoint(resp, req); err != nil {
t.Fatalf("err: %v", err)

View File

@ -17,11 +17,7 @@ import (
func TestOperator_RaftConfiguration(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/operator/raft/configuration", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/operator/raft/configuration", body)
resp := httptest.NewRecorder()
obj, err := srv.OperatorRaftConfiguration(resp, req)
if err != nil {
@ -45,15 +41,11 @@ func TestOperator_RaftConfiguration(t *testing.T) {
func TestOperator_RaftPeer(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("DELETE", "/v1/operator/raft/peer?address=nope", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("DELETE", "/v1/operator/raft/peer?address=nope", body)
// If we get this error, it proves we sent the address all the
// way through.
resp := httptest.NewRecorder()
_, err = srv.OperatorRaftPeer(resp, req)
_, err := srv.OperatorRaftPeer(resp, req)
if err == nil || !strings.Contains(err.Error(),
"address \"nope\" was not found in the Raft configuration") {
t.Fatalf("err: %v", err)
@ -62,15 +54,11 @@ func TestOperator_RaftPeer(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("DELETE", "/v1/operator/raft/peer?id=nope", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("DELETE", "/v1/operator/raft/peer?id=nope", body)
// If we get this error, it proves we sent the ID all the
// way through.
resp := httptest.NewRecorder()
_, err = srv.OperatorRaftPeer(resp, req)
_, err := srv.OperatorRaftPeer(resp, req)
if err == nil || !strings.Contains(err.Error(),
"id \"nope\" was not found in the Raft configuration") {
t.Fatalf("err: %v", err)
@ -86,13 +74,9 @@ func TestOperator_KeyringInstall(t *testing.T) {
}
httpTestWithConfig(t, func(srv *HTTPServer) {
body := bytes.NewBufferString(fmt.Sprintf("{\"Key\":\"%s\"}", newKey))
req, err := http.NewRequest("POST", "/v1/operator/keyring", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("POST", "/v1/operator/keyring", body)
resp := httptest.NewRecorder()
_, err = srv.OperatorKeyringEndpoint(resp, req)
_, err := srv.OperatorKeyringEndpoint(resp, req)
if err != nil {
t.Fatalf("err: %s", err)
}
@ -123,11 +107,7 @@ func TestOperator_KeyringList(t *testing.T) {
c.EncryptKey = key
}
httpTestWithConfig(t, func(srv *HTTPServer) {
req, err := http.NewRequest("GET", "/v1/operator/keyring", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/operator/keyring", nil)
resp := httptest.NewRecorder()
r, err := srv.OperatorKeyringEndpoint(resp, req)
if err != nil {
@ -199,14 +179,9 @@ func TestOperator_KeyringRemove(t *testing.T) {
}
body := bytes.NewBufferString(fmt.Sprintf("{\"Key\":\"%s\"}", tempKey))
req, err := http.NewRequest("DELETE", "/v1/operator/keyring", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("DELETE", "/v1/operator/keyring", body)
resp := httptest.NewRecorder()
_, err = srv.OperatorKeyringEndpoint(resp, req)
if err != nil {
if _, err := srv.OperatorKeyringEndpoint(resp, req); err != nil {
t.Fatalf("err: %s", err)
}
@ -242,13 +217,9 @@ func TestOperator_KeyringUse(t *testing.T) {
}
body := bytes.NewBufferString(fmt.Sprintf("{\"Key\":\"%s\"}", newKey))
req, err := http.NewRequest("PUT", "/v1/operator/keyring", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/operator/keyring", body)
resp := httptest.NewRecorder()
_, err = srv.OperatorKeyringEndpoint(resp, req)
_, err := srv.OperatorKeyringEndpoint(resp, req)
if err != nil {
t.Fatalf("err: %s", err)
}
@ -288,13 +259,9 @@ func TestOperator_Keyring_InvalidRelayFactor(t *testing.T) {
"asdf": "Error parsing relay factor",
}
for relayFactor, errString := range cases {
req, err := http.NewRequest("GET", "/v1/operator/keyring?relay-factor="+relayFactor, nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/operator/keyring?relay-factor="+relayFactor, nil)
resp := httptest.NewRecorder()
_, err = srv.OperatorKeyringEndpoint(resp, req)
_, err := srv.OperatorKeyringEndpoint(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -309,11 +276,7 @@ func TestOperator_Keyring_InvalidRelayFactor(t *testing.T) {
func TestOperator_AutopilotGetConfiguration(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/operator/autopilot/configuration", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/operator/autopilot/configuration", body)
resp := httptest.NewRecorder()
obj, err := srv.OperatorAutopilotConfiguration(resp, req)
if err != nil {
@ -335,13 +298,9 @@ func TestOperator_AutopilotGetConfiguration(t *testing.T) {
func TestOperator_AutopilotSetConfiguration(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer([]byte(`{"CleanupDeadServers": false}`))
req, err := http.NewRequest("PUT", "/v1/operator/autopilot/configuration", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/operator/autopilot/configuration", body)
resp := httptest.NewRecorder()
if _, err = srv.OperatorAutopilotConfiguration(resp, req); err != nil {
if _, err := srv.OperatorAutopilotConfiguration(resp, req); err != nil {
t.Fatalf("err: %v", err)
}
if resp.Code != 200 {
@ -365,13 +324,9 @@ func TestOperator_AutopilotSetConfiguration(t *testing.T) {
func TestOperator_AutopilotCASConfiguration(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer([]byte(`{"CleanupDeadServers": false}`))
req, err := http.NewRequest("PUT", "/v1/operator/autopilot/configuration", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/operator/autopilot/configuration", body)
resp := httptest.NewRecorder()
if _, err = srv.OperatorAutopilotConfiguration(resp, req); err != nil {
if _, err := srv.OperatorAutopilotConfiguration(resp, req); err != nil {
t.Fatalf("err: %v", err)
}
if resp.Code != 200 {
@ -394,12 +349,7 @@ func TestOperator_AutopilotCASConfiguration(t *testing.T) {
// Create a CAS request, bad index
{
buf := bytes.NewBuffer([]byte(`{"CleanupDeadServers": true}`))
req, err := http.NewRequest("PUT",
fmt.Sprintf("/v1/operator/autopilot/configuration?cas=%d", reply.ModifyIndex-1), buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", fmt.Sprintf("/v1/operator/autopilot/configuration?cas=%d", reply.ModifyIndex-1), buf)
resp := httptest.NewRecorder()
obj, err := srv.OperatorAutopilotConfiguration(resp, req)
if err != nil {
@ -414,12 +364,7 @@ func TestOperator_AutopilotCASConfiguration(t *testing.T) {
// Create a CAS request, good index
{
buf := bytes.NewBuffer([]byte(`{"CleanupDeadServers": true}`))
req, err := http.NewRequest("PUT",
fmt.Sprintf("/v1/operator/autopilot/configuration?cas=%d", reply.ModifyIndex), buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", fmt.Sprintf("/v1/operator/autopilot/configuration?cas=%d", reply.ModifyIndex), buf)
resp := httptest.NewRecorder()
obj, err := srv.OperatorAutopilotConfiguration(resp, req)
if err != nil {
@ -447,10 +392,7 @@ func TestOperator_ServerHealth(t *testing.T) {
}
httpTestWithConfig(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/operator/autopilot/health", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/operator/autopilot/health", body)
retry.Run(t, func(r *retry.R) {
resp := httptest.NewRecorder()
obj, err := srv.OperatorServerHealth(resp, req)
@ -484,10 +426,7 @@ func TestOperator_ServerHealth_Unhealthy(t *testing.T) {
}
httpTestWithConfig(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/operator/autopilot/health", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/operator/autopilot/health", body)
retry.Run(t, func(r *retry.R) {
resp := httptest.NewRecorder()
obj, err := srv.OperatorServerHealth(resp, req)

View File

@ -131,11 +131,7 @@ func TestPreparedQuery_Create(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("POST", "/v1/query?token=my-token", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("POST", "/v1/query?token=my-token", body)
resp := httptest.NewRecorder()
obj, err := srv.PreparedQueryGeneral(resp, req)
if err != nil {
@ -167,11 +163,7 @@ func TestPreparedQuery_List(t *testing.T) {
}
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/query", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/query", body)
resp := httptest.NewRecorder()
obj, err := srv.PreparedQueryGeneral(resp, req)
if err != nil {
@ -215,11 +207,7 @@ func TestPreparedQuery_List(t *testing.T) {
}
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/query?token=my-token&consistent=true", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/query?token=my-token&consistent=true", body)
resp := httptest.NewRecorder()
obj, err := srv.PreparedQueryGeneral(resp, req)
if err != nil {
@ -251,11 +239,7 @@ func TestPreparedQuery_Execute(t *testing.T) {
}
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/query/my-id/execute", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/query/my-id/execute", body)
resp := httptest.NewRecorder()
obj, err := srv.PreparedQuerySpecific(resp, req)
if err != nil {
@ -307,11 +291,7 @@ func TestPreparedQuery_Execute(t *testing.T) {
}
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)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/query/my-id/execute?token=my-token&consistent=true&near=my-node&limit=5", body)
resp := httptest.NewRecorder()
obj, err := srv.PreparedQuerySpecific(resp, req)
if err != nil {
@ -350,11 +330,7 @@ func TestPreparedQuery_Execute(t *testing.T) {
return nil
}
req, err := http.NewRequest("GET", "/v1/query/my-id/execute", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/query/my-id/execute", nil)
resp := httptest.NewRecorder()
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
t.Fatalf("err: %v", err)
@ -382,11 +358,7 @@ func TestPreparedQuery_Execute(t *testing.T) {
}
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/query/my-id/execute?dc=dc2", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/query/my-id/execute?dc=dc2", body)
resp := httptest.NewRecorder()
obj, err := srv.PreparedQuerySpecific(resp, req)
if err != nil {
@ -433,11 +405,7 @@ func TestPreparedQuery_Execute(t *testing.T) {
}
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/query/my-id/execute?dc=dc2", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/query/my-id/execute?dc=dc2", body)
resp := httptest.NewRecorder()
obj, err := srv.PreparedQuerySpecific(resp, req)
if err != nil {
@ -465,14 +433,9 @@ func TestPreparedQuery_Execute(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/query/not-there/execute", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/query/not-there/execute", body)
resp := httptest.NewRecorder()
_, err = srv.PreparedQuerySpecific(resp, req)
if err != nil {
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
t.Fatalf("err: %v", err)
}
if resp.Code != 404 {
@ -516,11 +479,7 @@ func TestPreparedQuery_Explain(t *testing.T) {
}
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)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/query/my-id/explain?token=my-token&consistent=true&near=my-node&limit=5", body)
resp := httptest.NewRecorder()
obj, err := srv.PreparedQuerySpecific(resp, req)
if err != nil {
@ -540,14 +499,9 @@ func TestPreparedQuery_Explain(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/query/not-there/explain", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/query/not-there/explain", body)
resp := httptest.NewRecorder()
_, err = srv.PreparedQuerySpecific(resp, req)
if err != nil {
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
t.Fatalf("err: %v", err)
}
if resp.Code != 404 {
@ -584,11 +538,7 @@ func TestPreparedQuery_Get(t *testing.T) {
}
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/query/my-id?token=my-token&consistent=true", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/query/my-id?token=my-token&consistent=true", body)
resp := httptest.NewRecorder()
obj, err := srv.PreparedQuerySpecific(resp, req)
if err != nil {
@ -608,14 +558,9 @@ func TestPreparedQuery_Get(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/query/f004177f-2c28-83b7-4229-eacc25fe55d1", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/query/f004177f-2c28-83b7-4229-eacc25fe55d1", body)
resp := httptest.NewRecorder()
_, err = srv.PreparedQuerySpecific(resp, req)
if err != nil {
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
t.Fatalf("err: %v", err)
}
if resp.Code != 404 {
@ -689,14 +634,9 @@ func TestPreparedQuery_Update(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("PUT", "/v1/query/my-id?token=my-token", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/query/my-id?token=my-token", body)
resp := httptest.NewRecorder()
_, err = srv.PreparedQuerySpecific(resp, req)
if err != nil {
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
t.Fatalf("err: %v", err)
}
if resp.Code != 200 {
@ -740,14 +680,9 @@ func TestPreparedQuery_Delete(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("DELETE", "/v1/query/my-id?token=my-token", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("DELETE", "/v1/query/my-id?token=my-token", body)
resp := httptest.NewRecorder()
_, err = srv.PreparedQuerySpecific(resp, req)
if err != nil {
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
t.Fatalf("err: %v", err)
}
if resp.Code != 200 {
@ -759,14 +694,9 @@ func TestPreparedQuery_Delete(t *testing.T) {
func TestPreparedQuery_BadMethods(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("DELETE", "/v1/query", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("DELETE", "/v1/query", body)
resp := httptest.NewRecorder()
_, err = srv.PreparedQueryGeneral(resp, req)
if err != nil {
if _, err := srv.PreparedQueryGeneral(resp, req); err != nil {
t.Fatalf("err: %v", err)
}
if resp.Code != 405 {
@ -776,14 +706,9 @@ func TestPreparedQuery_BadMethods(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("POST", "/v1/query/my-id", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("POST", "/v1/query/my-id", body)
resp := httptest.NewRecorder()
_, err = srv.PreparedQuerySpecific(resp, req)
if err != nil {
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
t.Fatalf("err: %v", err)
}
if resp.Code != 405 {
@ -794,11 +719,7 @@ func TestPreparedQuery_BadMethods(t *testing.T) {
func TestPreparedQuery_parseLimit(t *testing.T) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/query", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/query", body)
limit := 99
if err := parseLimit(req, &limit); err != nil {
t.Fatalf("err: %v", err)
@ -807,10 +728,7 @@ func TestPreparedQuery_parseLimit(t *testing.T) {
t.Fatalf("bad limit: %d", limit)
}
req, err = http.NewRequest("GET", "/v1/query?limit=11", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/query?limit=11", body)
if err := parseLimit(req, &limit); err != nil {
t.Fatalf("err: %v", err)
}
@ -818,10 +736,7 @@ func TestPreparedQuery_parseLimit(t *testing.T) {
t.Fatalf("bad limit: %d", limit)
}
req, err = http.NewRequest("GET", "/v1/query?limit=bob", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/query?limit=bob", body)
if err := parseLimit(req, &limit); err == nil {
t.Fatalf("bad: %v", err)
}
@ -863,11 +778,7 @@ func TestPreparedQuery_Integration(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("POST", "/v1/query", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("POST", "/v1/query", body)
resp := httptest.NewRecorder()
obj, err := srv.PreparedQueryGeneral(resp, req)
if err != nil {
@ -886,11 +797,7 @@ func TestPreparedQuery_Integration(t *testing.T) {
// List them all.
{
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/query?token=root", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/query?token=root", body)
resp := httptest.NewRecorder()
obj, err := srv.PreparedQueryGeneral(resp, req)
if err != nil {
@ -911,11 +818,7 @@ func TestPreparedQuery_Integration(t *testing.T) {
// Execute it.
{
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/query/"+id+"/execute", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/query/"+id+"/execute", body)
resp := httptest.NewRecorder()
obj, err := srv.PreparedQuerySpecific(resp, req)
if err != nil {
@ -936,11 +839,7 @@ func TestPreparedQuery_Integration(t *testing.T) {
// Read it back.
{
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/query/"+id, body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/query/"+id, body)
resp := httptest.NewRecorder()
obj, err := srv.PreparedQuerySpecific(resp, req)
if err != nil {
@ -973,14 +872,9 @@ func TestPreparedQuery_Integration(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("PUT", "/v1/query/"+id, body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/query/"+id, body)
resp := httptest.NewRecorder()
_, err = srv.PreparedQuerySpecific(resp, req)
if err != nil {
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
t.Fatalf("err: %v", err)
}
if resp.Code != 200 {
@ -991,14 +885,9 @@ func TestPreparedQuery_Integration(t *testing.T) {
// Delete it.
{
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("DELETE", "/v1/query/"+id, body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("DELETE", "/v1/query/"+id, body)
resp := httptest.NewRecorder()
_, err = srv.PreparedQuerySpecific(resp, req)
if err != nil {
if _, err := srv.PreparedQuerySpecific(resp, req); err != nil {
t.Fatalf("err: %v", err)
}
if resp.Code != 200 {

View File

@ -45,11 +45,7 @@ func TestSessionCreate(t *testing.T) {
}
enc.Encode(raw)
req, err := http.NewRequest("PUT", "/v1/session/create", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/session/create", body)
resp := httptest.NewRecorder()
obj, err := srv.SessionCreate(resp, req)
if err != nil {
@ -94,11 +90,7 @@ func TestSessionCreateDelete(t *testing.T) {
}
enc.Encode(raw)
req, err := http.NewRequest("PUT", "/v1/session/create", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/session/create", body)
resp := httptest.NewRecorder()
obj, err := srv.SessionCreate(resp, req)
if err != nil {
@ -144,10 +136,7 @@ func TestFixupLockDelay(t *testing.T) {
}
func makeTestSession(t *testing.T, srv *HTTPServer) string {
req, err := http.NewRequest("PUT", "/v1/session/create", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/session/create", nil)
resp := httptest.NewRecorder()
obj, err := srv.SessionCreate(resp, req)
if err != nil {
@ -166,10 +155,7 @@ func makeTestSessionDelete(t *testing.T, srv *HTTPServer) string {
}
enc.Encode(raw)
req, err := http.NewRequest("PUT", "/v1/session/create", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/session/create", body)
resp := httptest.NewRecorder()
obj, err := srv.SessionCreate(resp, req)
if err != nil {
@ -188,10 +174,7 @@ func makeTestSessionTTL(t *testing.T, srv *HTTPServer, ttl string) string {
}
enc.Encode(raw)
req, err := http.NewRequest("PUT", "/v1/session/create", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/session/create", body)
resp := httptest.NewRecorder()
obj, err := srv.SessionCreate(resp, req)
if err != nil {
@ -205,7 +188,7 @@ func TestSessionDestroy(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
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()
obj, err := srv.SessionDestroy(resp, req)
if err != nil {
@ -235,8 +218,7 @@ func testSessionTTL(t *testing.T, ttl time.Duration, cb func(c *Config)) {
id := makeTestSessionTTL(t, srv, TTL)
req, err := http.NewRequest("GET",
"/v1/session/info/"+id, nil)
req, _ := http.NewRequest("GET", "/v1/session/info/"+id, nil)
resp := httptest.NewRecorder()
obj, err := srv.SessionGet(resp, req)
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)
req, err = http.NewRequest("GET",
"/v1/session/info/"+id, nil)
req, _ = http.NewRequest("GET", "/v1/session/info/"+id, nil)
resp = httptest.NewRecorder()
obj, err = srv.SessionGet(resp, req)
if err != nil {
@ -275,8 +256,7 @@ func TestSessionTTLRenew(t *testing.T) {
httpTestWithConfig(t, func(srv *HTTPServer) {
id := makeTestSessionTTL(t, srv, TTL)
req, err := http.NewRequest("GET",
"/v1/session/info/"+id, nil)
req, _ := http.NewRequest("GET", "/v1/session/info/"+id, nil)
resp := httptest.NewRecorder()
obj, err := srv.SessionGet(resp, req)
if err != nil {
@ -296,8 +276,7 @@ func TestSessionTTLRenew(t *testing.T) {
// Sleep to consume some time before renew
time.Sleep(ttl * (structs.SessionTTLMultiplier / 2))
req, err = http.NewRequest("PUT",
"/v1/session/renew/"+id, nil)
req, _ = http.NewRequest("PUT", "/v1/session/renew/"+id, nil)
resp = httptest.NewRecorder()
obj, err = srv.SessionRenew(resp, req)
if err != nil {
@ -314,8 +293,7 @@ func TestSessionTTLRenew(t *testing.T) {
// Sleep for ttl * TTL Multiplier
time.Sleep(ttl * structs.SessionTTLMultiplier)
req, err = http.NewRequest("GET",
"/v1/session/info/"+id, nil)
req, _ = http.NewRequest("GET", "/v1/session/info/"+id, nil)
resp = httptest.NewRecorder()
obj, err = srv.SessionGet(resp, req)
if err != nil {
@ -332,8 +310,7 @@ func TestSessionTTLRenew(t *testing.T) {
// now wait for timeout and expect session to get destroyed
time.Sleep(ttl * structs.SessionTTLMultiplier)
req, err = http.NewRequest("GET",
"/v1/session/info/"+id, nil)
req, _ = http.NewRequest("GET", "/v1/session/info/"+id, nil)
resp = httptest.NewRecorder()
obj, err = srv.SessionGet(resp, req)
if err != nil {
@ -351,7 +328,7 @@ func TestSessionTTLRenew(t *testing.T) {
func TestSessionGet(t *testing.T) {
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()
obj, err := srv.SessionGet(resp, req)
if err != nil {
@ -369,8 +346,7 @@ func TestSessionGet(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
id := makeTestSession(t, srv)
req, err := http.NewRequest("GET",
"/v1/session/info/"+id, nil)
req, _ := http.NewRequest("GET", "/v1/session/info/"+id, nil)
resp := httptest.NewRecorder()
obj, err := srv.SessionGet(resp, req)
if err != nil {
@ -388,7 +364,7 @@ func TestSessionGet(t *testing.T) {
func TestSessionList(t *testing.T) {
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()
obj, err := srv.SessionList(resp, req)
if err != nil {
@ -409,7 +385,7 @@ func TestSessionList(t *testing.T) {
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()
obj, err := srv.SessionList(resp, req)
if err != nil {
@ -427,8 +403,7 @@ func TestSessionList(t *testing.T) {
func TestSessionsForNode(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
req, err := http.NewRequest("GET",
"/v1/session/node/"+srv.agent.config.NodeName, nil)
req, _ := http.NewRequest("GET", "/v1/session/node/"+srv.agent.config.NodeName, nil)
resp := httptest.NewRecorder()
obj, err := srv.SessionsForNode(resp, req)
if err != nil {
@ -449,8 +424,7 @@ func TestSessionsForNode(t *testing.T) {
ids = append(ids, makeTestSession(t, srv))
}
req, err := http.NewRequest("GET",
"/v1/session/node/"+srv.agent.config.NodeName, nil)
req, _ := http.NewRequest("GET", "/v1/session/node/"+srv.agent.config.NodeName, nil)
resp := httptest.NewRecorder()
obj, err := srv.SessionsForNode(resp, req)
if err != nil {
@ -472,10 +446,7 @@ func TestSessionDeleteDestroy(t *testing.T) {
// now create a new key for the session and acquire it
buf := bytes.NewBuffer([]byte("test"))
req, err := http.NewRequest("PUT", "/v1/kv/ephemeral?acquire="+id, buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/kv/ephemeral?acquire="+id, buf)
resp := httptest.NewRecorder()
obj, err := srv.KVSEndpoint(resp, req)
if err != nil {
@ -487,7 +458,7 @@ func TestSessionDeleteDestroy(t *testing.T) {
}
// 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()
obj, err = srv.SessionDestroy(resp, req)
if err != nil {

View File

@ -13,14 +13,9 @@ func TestSnapshot(t *testing.T) {
var snap io.Reader
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("GET", "/v1/snapshot?token=root", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/snapshot?token=root", body)
resp := httptest.NewRecorder()
_, err = srv.Snapshot(resp, req)
if err != nil {
if _, err := srv.Snapshot(resp, req); err != nil {
t.Fatalf("err: %v", err)
}
snap = resp.Body
@ -40,14 +35,9 @@ func TestSnapshot(t *testing.T) {
})
httpTest(t, func(srv *HTTPServer) {
req, err := http.NewRequest("PUT", "/v1/snapshot?token=root", snap)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/snapshot?token=root", snap)
resp := httptest.NewRecorder()
_, err = srv.Snapshot(resp, req)
if err != nil {
if _, err := srv.Snapshot(resp, req); err != nil {
t.Fatalf("err: %v", err)
}
})
@ -57,13 +47,9 @@ func TestSnapshot_Options(t *testing.T) {
for _, method := range []string{"GET", "PUT"} {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest(method, "/v1/snapshot?token=anonymous", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest(method, "/v1/snapshot?token=anonymous", body)
resp := httptest.NewRecorder()
_, err = srv.Snapshot(resp, req)
_, err := srv.Snapshot(resp, req)
if err == nil || !strings.Contains(err.Error(), "Permission denied") {
t.Fatalf("err: %v", err)
}
@ -71,13 +57,9 @@ func TestSnapshot_Options(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest(method, "/v1/snapshot?dc=nope", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest(method, "/v1/snapshot?dc=nope", body)
resp := httptest.NewRecorder()
_, err = srv.Snapshot(resp, req)
_, err := srv.Snapshot(resp, req)
if err == nil || !strings.Contains(err.Error(), "No path to datacenter") {
t.Fatalf("err: %v", err)
}
@ -85,13 +67,9 @@ func TestSnapshot_Options(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest(method, "/v1/snapshot?token=root&stale", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest(method, "/v1/snapshot?token=root&stale", body)
resp := httptest.NewRecorder()
_, err = srv.Snapshot(resp, req)
_, err := srv.Snapshot(resp, req)
if method == "GET" {
if err != nil {
t.Fatalf("err: %v", err)
@ -108,13 +86,9 @@ func TestSnapshot_Options(t *testing.T) {
func TestSnapshot_BadMethods(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("POST", "/v1/snapshot", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("POST", "/v1/snapshot", body)
resp := httptest.NewRecorder()
_, err = srv.Snapshot(resp, req)
_, err := srv.Snapshot(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -125,13 +99,9 @@ func TestSnapshot_BadMethods(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
req, err := http.NewRequest("DELETE", "/v1/snapshot", body)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("DELETE", "/v1/snapshot", body)
resp := httptest.NewRecorder()
_, err = srv.Snapshot(resp, req)
_, err := srv.Snapshot(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}

View File

@ -15,11 +15,7 @@ import (
func TestTxnEndpoint_Bad_JSON(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
buf := bytes.NewBuffer([]byte("{"))
req, err := http.NewRequest("PUT", "/v1/txn", buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
resp := httptest.NewRecorder()
if _, err := srv.Txn(resp, req); err != nil {
t.Fatalf("err: %v", err)
@ -36,11 +32,7 @@ func TestTxnEndpoint_Bad_JSON(t *testing.T) {
func TestTxnEndpoint_Bad_Method(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
buf := bytes.NewBuffer([]byte("{}"))
req, err := http.NewRequest("GET", "/v1/txn", buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/txn", buf)
resp := httptest.NewRecorder()
if _, err := srv.Txn(resp, req); err != nil {
t.Fatalf("err: %v", err)
@ -64,11 +56,7 @@ func TestTxnEndpoint_Bad_Size_Item(t *testing.T) {
}
]
`, strings.Repeat("bad", 2*maxKVSize))))
req, err := http.NewRequest("PUT", "/v1/txn", buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
resp := httptest.NewRecorder()
if _, err := srv.Txn(resp, req); err != nil {
t.Fatalf("err: %v", err)
@ -107,11 +95,7 @@ func TestTxnEndpoint_Bad_Size_Net(t *testing.T) {
}
]
`, value, value, value)))
req, err := http.NewRequest("PUT", "/v1/txn", buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
resp := httptest.NewRecorder()
if _, err := srv.Txn(resp, req); err != nil {
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))))
req, err := http.NewRequest("PUT", "/v1/txn", buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
resp := httptest.NewRecorder()
if _, err := srv.Txn(resp, req); err != nil {
t.Fatalf("err: %v", err)
@ -177,11 +157,7 @@ func TestTxnEndpoint_KV_Actions(t *testing.T) {
}
]
`, id)))
req, err := http.NewRequest("PUT", "/v1/txn", buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
resp := httptest.NewRecorder()
obj, err := srv.Txn(resp, req)
if err != nil {
@ -253,11 +229,7 @@ func TestTxnEndpoint_KV_Actions(t *testing.T) {
}
]
`))
req, err := http.NewRequest("PUT", "/v1/txn", buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
resp := httptest.NewRecorder()
obj, err := srv.Txn(resp, req)
if err != nil {
@ -341,11 +313,7 @@ func TestTxnEndpoint_KV_Actions(t *testing.T) {
}
]
`, index)))
req, err := http.NewRequest("PUT", "/v1/txn", buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
resp := httptest.NewRecorder()
obj, err := srv.Txn(resp, req)
if err != nil {
@ -415,13 +383,9 @@ func TestTxnEndpoint_KV_Actions(t *testing.T) {
}
]
`))
req, err := http.NewRequest("PUT", "/v1/txn", buf)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
resp := httptest.NewRecorder()
if _, err = srv.Txn(resp, req); err != nil {
if _, err := srv.Txn(resp, req); err != nil {
t.Fatalf("err: %v", err)
}
if resp.Code != 409 {

View File

@ -41,10 +41,7 @@ func TestUiIndex(t *testing.T) {
}
// Register node
req, err := http.NewRequest("GET", "/ui/my-file", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/ui/my-file", nil)
req.URL.Scheme = "http"
req.URL.Host = srv.listener.Addr().String()
@ -87,11 +84,7 @@ func TestUiNodes(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/internal/ui/nodes/dc1", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", "/v1/internal/ui/nodes/dc1", nil)
resp := httptest.NewRecorder()
obj, err := srv.UINodes(resp, req)
if err != nil {
@ -120,12 +113,7 @@ func TestUiNodeInfo(t *testing.T) {
testrpc.WaitForLeader(t, srv.agent.RPC, "dc1")
req, err := http.NewRequest("GET",
fmt.Sprintf("/v1/internal/ui/node/%s", srv.agent.config.NodeName), nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ := http.NewRequest("GET", fmt.Sprintf("/v1/internal/ui/node/%s", srv.agent.config.NodeName), nil)
resp := httptest.NewRecorder()
obj, err := srv.UINodeInfo(resp, req)
if err != nil {
@ -151,11 +139,7 @@ func TestUiNodeInfo(t *testing.T) {
t.Fatalf("err: %v", err)
}
req, err = http.NewRequest("GET", "/v1/internal/ui/node/test", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, _ = http.NewRequest("GET", "/v1/internal/ui/node/test", nil)
resp = httptest.NewRecorder()
obj, err = srv.UINodeInfo(resp, req)
if err != nil {