29 lines
939 B
Go
29 lines
939 B
Go
|
|
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")
|
||
|
|
}
|
||
|
|
}
|