You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kratos/middleware/status/status_test.go

23 lines
539 B

4 years ago
package status
import (
"context"
4 years ago
"testing"
"github.com/go-kratos/kratos/v2/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func TestErrEncoder(t *testing.T) {
err := errors.BadRequest("InvalidArgument", "format")
en := encodeErr(context.Background(), err)
4 years ago
if code := status.Code(en); code != codes.InvalidArgument {
t.Errorf("expected %d got %d", codes.InvalidArgument, code)
}
de := decodeErr(context.Background(), en)
if !errors.IsBadRequest(de) {
4 years ago
t.Errorf("expected %v got %v", err, de)
}
}