diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-22 17:35:49 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-22 17:35:49 -0600 |
| commit | 20ef0d92694465ac86b550df139e8366a0a2b4fa (patch) | |
| tree | 3f14589e1ce6eb9306a3af31c3a1f9e1af5ed637 /vendor/github.com/authzed/spicedb/pkg/spiceerrors/testutil.go | |
| parent | 44e0d272c040cdc53a98b9f1dc58ae7da67752e6 (diff) | |
feat: connect to spicedb
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) + } +} |
