diff options
Diffstat (limited to 'vendor/github.com/authzed/spicedb/pkg/spiceerrors/testutil.go')
| -rw-r--r-- | vendor/github.com/authzed/spicedb/pkg/spiceerrors/testutil.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/vendor/github.com/authzed/spicedb/pkg/spiceerrors/testutil.go b/vendor/github.com/authzed/spicedb/pkg/spiceerrors/testutil.go new file mode 100644 index 0000000..db71540 --- /dev/null +++ b/vendor/github.com/authzed/spicedb/pkg/spiceerrors/testutil.go @@ -0,0 +1,28 @@ +package spiceerrors + +import ( + "testing" + + "github.com/stretchr/testify/require" + "google.golang.org/genproto/googleapis/rpc/errdetails" + "google.golang.org/grpc/status" + + v1 "github.com/authzed/authzed-go/proto/authzed/api/v1" +) + +// RequireReason asserts that an error is a gRPC error and returns the expected +// reason in the ErrorInfo. +// TODO(jschorr): Move into grpcutil. +func RequireReason(t testing.TB, reason v1.ErrorReason, err error, expectedMetadataKeys ...string) { + require.Error(t, err) + withStatus, ok := status.FromError(err) + require.True(t, ok) + require.True(t, len(withStatus.Details()) > 0) + + info := withStatus.Details()[0].(*errdetails.ErrorInfo) + require.Equal(t, v1.ErrorReason_name[int32(reason)], info.GetReason()) + + for _, expectedKey := range expectedMetadataKeys { + require.Contains(t, info.Metadata, expectedKey) + } +} |
