diff --git a/authorizer.go b/authorizer.go index 28e96fd..6cad639 100644 --- a/authorizer.go +++ b/authorizer.go @@ -62,6 +62,8 @@ func WithApprovers[R any](more ...Approver[R]) AuthorizerOption[R] { ) } +// WithApproverFuncs is a closure variant of WithApprovers that eases the +// syntactical pain of dealing with approvers that are functions. func WithApproverFuncs[R any](more ...ApproverFunc[R]) AuthorizerOption[R] { return authorizerOptionFunc[R]( func(a *Authorizer[R]) error { diff --git a/authorizer_test.go b/authorizer_test.go index bfa688e..6e376ad 100644 --- a/authorizer_test.go +++ b/authorizer_test.go @@ -61,12 +61,14 @@ func (suite *AuthorizerTestSuite) TestFullSuccess() { approver1 = new(mockApprover[string]) approver2 = new(mockApprover[string]) + approver3 = new(mockApprover[string]) listener1 = new(mockAuthorizeListener[string]) listener2 = new(mockAuthorizeListener[string]) a = suite.newAuthorizer( WithApprovers(approver1, approver2), + WithApproverFuncs(approver3.Approve), WithAuthorizeListeners(listener1), WithAuthorizeListenerFuncs(listener2.OnEvent), ) @@ -76,6 +78,8 @@ func (suite *AuthorizerTestSuite) TestFullSuccess() { Return(nil).Once() approver2.ExpectApprove(expectedCtx, expectedResource, expectedToken). Return(nil).Once() + approver3.ExpectApprove(expectedCtx, expectedResource, expectedToken). + Return(nil).Once() listener1.ExpectOnEvent(AuthorizeEvent[string]{ Resource: expectedResource, @@ -96,6 +100,7 @@ func (suite *AuthorizerTestSuite) TestFullSuccess() { listener2.AssertExpectations(suite.T()) approver1.AssertExpectations(suite.T()) approver2.AssertExpectations(suite.T()) + approver3.AssertExpectations(suite.T()) } func (suite *AuthorizerTestSuite) TestFullFirstApproverFail() {