|
|
@@ -2,6 +2,7 @@ package fserr
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
+ "github.com/stretchr/testify/assert"
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
"net/http"
|
|
|
"testing"
|
|
|
@@ -117,7 +118,7 @@ func (s *TestPublicSuite) TestIsCode() {
|
|
|
}
|
|
|
|
|
|
func (s *TestPublicSuite) TestSetServiceCode() {
|
|
|
- SetServiceCode(300000)
|
|
|
+ SetAppCode(300000)
|
|
|
NewOK(2001, "ok")
|
|
|
err := WithCode(nil, 2001)
|
|
|
s.Equal(302001, ParseCode(err).BusinessCode)
|
|
|
@@ -126,3 +127,26 @@ func (s *TestPublicSuite) TestSetServiceCode() {
|
|
|
func TestPublic(t *testing.T) {
|
|
|
suite.Run(t, &TestPublicSuite{})
|
|
|
}
|
|
|
+
|
|
|
+func TestServiceCode(t *testing.T) {
|
|
|
+ SetAppCode(10)
|
|
|
+ NewBadRequest(ErrDb, "db error")
|
|
|
+ code := ParseCode(WithCode(nil, ErrDb))
|
|
|
+ assert.Equal(t, "db error", code.Msg)
|
|
|
+ assert.Equal(t, 100102, code.BusinessCode)
|
|
|
+ assert.Equal(t, http.StatusBadRequest, code.HttpCode)
|
|
|
+
|
|
|
+ SetAppCode(100000)
|
|
|
+ NewInternalError(ErrParam, "param error")
|
|
|
+ code = ParseCode(WithCode(nil, ErrParam))
|
|
|
+ assert.Equal(t, "param error", code.Msg)
|
|
|
+ assert.Equal(t, 100103, code.BusinessCode)
|
|
|
+ assert.Equal(t, http.StatusInternalServerError, code.HttpCode)
|
|
|
+
|
|
|
+ SetAppCode(1000)
|
|
|
+ NewConflict(ErrRetry, "retry error")
|
|
|
+ code = ParseCode(WithCode(nil, ErrRetry))
|
|
|
+ assert.Equal(t, 100104, code.BusinessCode)
|
|
|
+ assert.Equal(t, http.StatusConflict, code.HttpCode)
|
|
|
+ assert.Equal(t, "retry error", code.Msg)
|
|
|
+}
|