| 1 |
// +build go1.13 |
| 2 |
|
| 3 |
package grpcstatus |
| 4 |
|
| 5 |
import ( |
| 6 |
"fmt" |
| 7 |
"github.com/stretchr/testify/require" |
| 8 |
"google.golang.org/grpc/codes" |
| 9 |
"google.golang.org/grpc/status" |
| 10 |
"testing" |
| 11 |
) |
| 12 |
|
| 13 |
func TestNativeErrorUnwrapping(t *testing.T) { |
| 14 |
gRPCCode := codes.FailedPrecondition |
| 15 |
gRPCError := status.Errorf(gRPCCode, "Userspace error.") |
| 16 |
expectedGRPCStatus, _ := status.FromError(gRPCError) |
| 17 |
testedErrors := []error{ |
| 18 |
fmt.Errorf("go native wrapped error: %w", gRPCError), |
| 19 |
} |
| 20 |
|
| 21 |
for _, e := range testedErrors { |
| 22 |
resultingStatus, ok := FromError(e) |
| 23 |
require.True(t, ok) |
| 24 |
require.Equal(t, expectedGRPCStatus, resultingStatus) |
| 25 |
} |
| 26 |
} |