This commit is contained in:
2026-07-27 12:37:29 +08:00
parent dc9a98e893
commit 9429e4f6e0
20 changed files with 1066 additions and 61 deletions

View File

@@ -0,0 +1,28 @@
package fadada
import (
"errors"
"fmt"
"testing"
)
func TestIsAuthAlreadyGranted(t *testing.T) {
if !IsAuthAlreadyGranted(NewAPIError("op", CodeAuthScopeDuplicate, "授权范围重复获取", "1")) {
t.Fatal("210002 should match")
}
if !IsAuthAlreadyGranted(NewAPIError("op", CodeAuthScopeDuplicateCorp, "授权范围重复获取", "2")) {
t.Fatal("210013 should match")
}
if IsAuthAlreadyGranted(NewAPIError("op", CodeParamIllegal, "请求参数非法", "3")) {
t.Fatal("100011 should not match")
}
if !IsAuthAlreadyGranted(fmt.Errorf("wrap: %w", NewAPIError("op", CodeAuthScopeDuplicate, "x", "4"))) {
t.Fatal("wrapped 210002 should match")
}
if !IsAuthAlreadyGranted(errors.New("fail: code=210013 msg=授权范围重复获取 requestId=x")) {
t.Fatal("legacy string 210013 should match")
}
if IsAuthAlreadyGranted(errors.New("无需重复操作")) {
t.Fatal("msg-only must not match per official docs")
}
}