Ejemplo n.º 1
0
func (s *handlerSuite) TestServeDebugStatus(c *gc.C) {
	httpHandler := newHTTPHandler(&debugstatus.Handler{
		Check: func() map[string]debugstatus.CheckResult {
			return debugstatus.Check(debugstatus.ServerStartTime)
		},
	})
	httptesting.AssertJSONCall(c, httptesting.JSONCallParams{
		Handler: httpHandler,
		URL:     "/debug/status",
		ExpectBody: httptesting.BodyAsserter(func(c *gc.C, body json.RawMessage) {
			var result map[string]debugstatus.CheckResult
			err := json.Unmarshal(body, &result)
			c.Assert(err, gc.IsNil)
			for k, v := range result {
				v.Duration = 0
				result[k] = v
			}
			c.Assert(result, jc.DeepEquals, map[string]debugstatus.CheckResult{
				"server_started": {
					Name:   "Server started",
					Value:  debugstatus.StartTime.String(),
					Passed: true,
				},
			})
		}),
	})
}
Ejemplo n.º 2
0
func (*requestsSuite) TestAssertJSONCallWithBodyAsserter(c *gc.C) {
	called := false
	params := httptesting.JSONCallParams{
		URL:     "/",
		Handler: makeHandler(c, http.StatusOK, "application/json"),
		ExpectBody: httptesting.BodyAsserter(func(c1 *gc.C, body json.RawMessage) {
			c.Assert(c1, gc.Equals, c)
			c.Assert(string(body), jc.JSONEquals, handlerResponse{
				URL:    "/",
				Method: "GET",
				Header: make(http.Header),
			})
			called = true
		}),
	}
	httptesting.AssertJSONCall(c, params)
	c.Assert(called, gc.Equals, true)
}