From 1753724e0e1c62684323d8ed9d697385bbb306d8 Mon Sep 17 00:00:00 2001 From: philhassey Date: Tue, 3 Dec 2024 14:35:48 -0700 Subject: [PATCH] x/exp/batch: add test case showing context and callback errors being joined Addresses IDX-469 Signed-off-by: philhassey --- x/exp/batch/batch_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/x/exp/batch/batch_test.go b/x/exp/batch/batch_test.go index 7caf639..fd352cf 100644 --- a/x/exp/batch/batch_test.go +++ b/x/exp/batch/batch_test.go @@ -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"),