Skip to content

Commit

Permalink
x/exp/batch: add test case showing context and callback errors being …
Browse files Browse the repository at this point in the history
…joined

Addresses IDX-469

Signed-off-by: philhassey <[email protected]>
  • Loading branch information
philhassey committed Dec 3, 2024
1 parent 0b9bd77 commit 1753724
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions x/exp/batch/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,30 @@ func TestBatchErrors(t *testing.T) {
testutil.Equals(t, total, 2)
})

t.Run("contextAndCallbackErrored", func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
errWant := fmt.Errorf("errWant")
err := Authorize(ctx, cedar.NewPolicySet(), types.EntityMap{}, Request{
Principal: types.NewEntityUID("Principal", "principal"),
Action: types.NewEntityUID("Action", "action"),
Resource: Variable("resource"),
Context: types.Record{},
Variables: Variables{
"resource": []types.Value{
types.NewEntityUID("Resource", "1"),
types.NewEntityUID("Resource", "2"),
types.NewEntityUID("Resource", "3"),
},
},
}, func(_ Result) error {
cancel()
return errWant
},
)
testutil.ErrorIs(t, err, context.Canceled)
testutil.ErrorIs(t, err, errWant)
})

t.Run("invalidPrincipal", func(t *testing.T) {
err := Authorize(context.Background(), cedar.NewPolicySet(), types.EntityMap{}, Request{
Principal: types.String("invalid"),
Expand Down

0 comments on commit 1753724

Please sign in to comment.