func (s *handlerSuite) TestServeTraceEvents(c *gc.C) { httpHandler := newHTTPHandler(&debugstatus.Handler{ CheckTraceAllowed: func(req *http.Request) (bool, error) { if req.Header.Get("Authorization") == "" { return false, errUnauthorized } return false, nil }, }) authHeader := make(http.Header) authHeader.Set("Authorization", "let me in") for i, path := range debugTracePaths { c.Logf("%d. %s", i, path) httptesting.AssertJSONCall(c, httptesting.JSONCallParams{ Handler: httpHandler, URL: path, ExpectStatus: http.StatusUnauthorized, ExpectBody: httprequest.RemoteError{ Code: "unauthorized", Message: "you shall not pass!", }, }) rr := httptesting.DoRequest(c, httptesting.DoRequestParams{ Handler: httpHandler, URL: path, Header: authHeader, }) c.Assert(rr.Code, gc.Equals, http.StatusOK) } }
func (*requestsSuite) TestDoRequestWithInferrableContentLength(c *gc.C) { text := "hello, world" for i, f := range bodyReaderFuncs { c.Logf("test %d", i) called := false httptesting.DoRequest(c, httptesting.DoRequestParams{ Handler: http.HandlerFunc(func(_ http.ResponseWriter, req *http.Request) { c.Check(req.ContentLength, gc.Equals, int64(len(text))) called = true }), Body: f(text), }) c.Assert(called, gc.Equals, true) } }