code_test.go 896 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package fserr
  2. import (
  3. "github.com/stretchr/testify/suite"
  4. "net/http"
  5. "testing"
  6. )
  7. type TestCodeSuite struct {
  8. suite.Suite
  9. }
  10. func (s *TestCodeSuite) SetupTest() {
  11. NewInternalError(ErrBasic, "basic error")
  12. NewBadRequest(100102, "customer error")
  13. SetDefault(http.StatusInternalServerError, 100101, "default")
  14. }
  15. func (s *TestCodeSuite) TestBuiltinErrCode() {
  16. errCode := getCode(ErrBasic)
  17. s.Equal(http.StatusInternalServerError, errCode.HttpCode)
  18. s.Equal("basic error", errCode.Message)
  19. }
  20. func (s *TestCodeSuite) TestDefaultErrCode() {
  21. s.Equal(http.StatusInternalServerError, defaultErrCode.HttpCode)
  22. s.Equal("default", defaultErrCode.Message)
  23. }
  24. func (s *TestCodeSuite) TestCustomerErrCode() {
  25. errCode := getCode(100102)
  26. s.Equal(http.StatusBadRequest, errCode.HttpCode)
  27. s.Equal("customer error", errCode.Message)
  28. }
  29. func TestCode(t *testing.T) {
  30. suite.Run(t, &TestCodeSuite{})
  31. }