test for known pprof endpoints

This commit is contained in:
Drew Bailey
2019-12-06 16:27:26 -05:00
parent 240c0ee0ec
commit 3575f1777f
2 changed files with 28 additions and 5 deletions

View File

@@ -415,13 +415,11 @@ func (s *HTTPServer) agentPprofReq(reqType profile.ReqType, profile string, resp
}
if rpcErr != nil {
// TODO: rpcErr should return codedErr
return nil, rpcErr
}
// resp.Write(reply.Payload)
return reply.Payload, nil
// return string(reply.Payload), rpcErr
}
// AgentServersRequest is used to query the list of servers used by the Nomad

View File

@@ -394,7 +394,7 @@ func TestAgent_PprofRequest(t *testing.T) {
url string
addNodeID bool
addServerID bool
expectedErr error
expectedErr string
expectedStatus int
}{
{
@@ -403,6 +403,31 @@ func TestAgent_PprofRequest(t *testing.T) {
addNodeID: true,
expectedStatus: 200,
},
{
desc: "cpu profile request",
url: "/v1/agent/pprof/profile",
addNodeID: true,
expectedStatus: 200,
},
{
desc: "trace request",
url: "/v1/agent/pprof/trace",
addNodeID: true,
expectedStatus: 200,
},
{
desc: "pprof lookup request",
url: "/v1/agent/pprof/goroutine",
addNodeID: true,
expectedStatus: 200,
},
{
desc: "unknown pprof lookup request",
url: "/v1/agent/pprof/latency",
addNodeID: true,
expectedStatus: 404,
expectedErr: "Unknown profile: latency",
},
}
for _, tc := range cases {
@@ -423,7 +448,7 @@ func TestAgent_PprofRequest(t *testing.T) {
resp, err := s.Server.AgentPprofRequest(respW, req)
if tc.expectedErr != nil {
if tc.expectedErr != "" {
require.Error(t, err)
} else {
require.NoError(t, err)