Skip to content

Commit

Permalink
chore: test coverage for WithApproverFuncs
Browse files Browse the repository at this point in the history
  • Loading branch information
johnabass committed Aug 19, 2024
1 parent 135a281 commit 336432b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions authorizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand All @@ -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,
Expand All @@ -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() {
Expand Down

0 comments on commit 336432b

Please sign in to comment.