func TestUpdateNeeded(t *testing.T) { p := newWatch("test") ti := time.Now() p.lastCheck = ti p.lastStatus = health.Passing res := health.Result{ Status: health.Critical, } Assert(t).AreEqual(true, p.updateNeeded(res, 1000), "should need update since Result.Status changed") res.Status = health.Passing Assert(t).AreEqual(true, p.updateNeeded(res, 0), "TTL is 0 so should always need update") Assert(t).AreEqual(false, p.updateNeeded(res, 1000), "TTL is >> than time since ti was created and status is unchanged") }
func (sc *StatusChecker) resultFromCheck(resp *http.Response, err error) (health.Result, error) { res := health.Result{ ID: sc.ID, Node: sc.Node, Service: string(sc.ID), } if err != nil || resp == nil { res.Status = health.Critical return res, nil } if resp.StatusCode >= 200 && resp.StatusCode < 300 { res.Status = health.Passing } else { res.Status = health.Critical } return res, err }
func resultFromCheck(resp *http.Response, err error) (health.Result, error) { res := health.Result{} if err != nil || resp == nil { res.Status = health.Critical if err != nil { res.Output = err.Error() } return res, nil } res.Output, err = getBody(resp) if resp.StatusCode >= 200 && resp.StatusCode < 300 { res.Status = health.Passing } else { res.Status = health.Critical } return res, err }