22 lines
577 B
Go
22 lines
577 B
Go
|
|
package haiyuapi
|
||
|
|
|
||
|
|
import (
|
||
|
|
"errors"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestMapBusinessError(t *testing.T) {
|
||
|
|
if err := mapBusinessError(CodeSuccess, ""); err != nil {
|
||
|
|
t.Fatalf("code 0 should be nil, got %v", err)
|
||
|
|
}
|
||
|
|
if !errors.Is(mapBusinessError(CodeQueryEmpty, "查无"), ErrNotFound) {
|
||
|
|
t.Fatal("expected ErrNotFound for 1000")
|
||
|
|
}
|
||
|
|
if !errors.Is(mapBusinessError(CodeBusiness, "业务失败"), ErrDatasource) {
|
||
|
|
t.Fatal("expected ErrDatasource for 2001")
|
||
|
|
}
|
||
|
|
if !errors.Is(mapBusinessError(CodeRequestParam, "参数错误"), ErrSystem) {
|
||
|
|
t.Fatal("expected ErrSystem for 1003")
|
||
|
|
}
|
||
|
|
}
|