27 lines
635 B
Go
27 lines
635 B
Go
package xerr
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
// TestToGRPCErrorCarriesReason 锁定服务底座要求的 gRPC code + ErrorInfo.reason 组合。
|
|
func TestToGRPCErrorCarriesReason(t *testing.T) {
|
|
err := ToGRPCError(New(PasswordAlreadySet, "password already set"))
|
|
|
|
st, ok := status.FromError(err)
|
|
if !ok {
|
|
t.Fatalf("expected grpc status")
|
|
}
|
|
|
|
if st.Code() != codes.AlreadyExists {
|
|
t.Fatalf("grpc code mismatch: got %s", st.Code())
|
|
}
|
|
|
|
if got := ReasonFromGRPC(err); got != PasswordAlreadySet {
|
|
t.Fatalf("reason mismatch: got %s want %s", got, PasswordAlreadySet)
|
|
}
|
|
}
|