✨ Add SettableError
This commit is contained in:
parent
95c9d7282b
commit
c0dc44e28e
3 changed files with 88 additions and 5 deletions
|
|
@ -69,3 +69,36 @@ func (s *ErrorfTestSuite) TestWrapTwo() {
|
|||
s.Assert().Same(wrappedOne, unwrapped[0])
|
||||
s.Assert().Same(wrappedTwo, unwrapped[1])
|
||||
}
|
||||
|
||||
func (s *ErrorfTestSuite) TestSet() {
|
||||
var err SettableError = Errorf(http.StatusTeapot, "Unable to BREW")
|
||||
s.Assert().NotNil(err)
|
||||
|
||||
err.Status(http.StatusTooEarly).Msg("It's only %dAM", 2)
|
||||
s.Assert().Equal(http.StatusTooEarly, err.GetStatus())
|
||||
s.Assert().Equal("It's only 2AM", err.GetMsg())
|
||||
s.Assert().Equal("Unable to BREW", err.Error())
|
||||
|
||||
err.Msg("I am so great")
|
||||
s.Assert().Equal("I am so great", err.GetMsg())
|
||||
}
|
||||
|
||||
func (s *ErrorfTestSuite) TestGetStatusOutsideRange() {
|
||||
var err ResponsableError = Errorf(5, "Hello")
|
||||
s.Assert().NotNil(err)
|
||||
s.Assert().Equal(http.StatusInternalServerError, err.GetStatus())
|
||||
|
||||
err = Errorf(5, "Hello")
|
||||
s.Assert().NotNil(err)
|
||||
s.Assert().Equal(http.StatusInternalServerError, err.GetStatus())
|
||||
}
|
||||
|
||||
func (s *ErrorfTestSuite) TestSetStatusOutsideRange() {
|
||||
var err SettableError = Errorf(http.StatusPaymentRequired, "Hello")
|
||||
s.Assert().NotNil(err)
|
||||
|
||||
err.Status(10)
|
||||
s.Assert().Equal(http.StatusPaymentRequired, err.GetStatus())
|
||||
err.Status(600)
|
||||
s.Assert().Equal(http.StatusPaymentRequired, err.GetStatus())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue