Documentation
¶
Overview ¶
Package authorizationmock provides moq-generated mock implementations of interfaces in the authorization package. The primary consumer is external tests that need to mock authorization.PolicyResolver — authorization's own tests do not depend on this package.
Note that there is nothing here for the request-time types. Grants is a struct, so a test builds the authority it wants directly with NewGrants, AllowAll, or DenyAll; and GrantsExtractor is a function, so a fake is a closure. Only policy resolution — the part that may do I/O — has an interface worth mocking.
Index ¶
- type PolicyResolverMock
- func (mock *PolicyResolverMock) PermissionsForRoles(ctx context.Context, roles ...string) (*authorization.PermissionSet, error)
- func (mock *PolicyResolverMock) PermissionsForRolesCalls() []struct{ ... }
- func (mock *PolicyResolverMock) Roles(ctx context.Context) ([]authorization.Role, error)
- func (mock *PolicyResolverMock) RolesCalls() []struct{ ... }
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PolicyResolverMock ¶
type PolicyResolverMock struct {
// PermissionsForRolesFunc mocks the PermissionsForRoles method.
PermissionsForRolesFunc func(ctx context.Context, roles ...string) (*authorization.PermissionSet, error)
// RolesFunc mocks the Roles method.
RolesFunc func(ctx context.Context) ([]authorization.Role, error)
// contains filtered or unexported fields
}
PolicyResolverMock is a mock implementation of authorization.PolicyResolver.
func TestSomethingThatUsesPolicyResolver(t *testing.T) {
// make and configure a mocked authorization.PolicyResolver
mockedPolicyResolver := &PolicyResolverMock{
PermissionsForRolesFunc: func(ctx context.Context, roles ...string) (*authorization.PermissionSet, error) {
panic("mock out the PermissionsForRoles method")
},
RolesFunc: func(ctx context.Context) ([]authorization.Role, error) {
panic("mock out the Roles method")
},
}
// use mockedPolicyResolver in code that requires authorization.PolicyResolver
// and then make assertions.
}
func (*PolicyResolverMock) PermissionsForRoles ¶
func (mock *PolicyResolverMock) PermissionsForRoles(ctx context.Context, roles ...string) (*authorization.PermissionSet, error)
PermissionsForRoles calls PermissionsForRolesFunc.
func (*PolicyResolverMock) PermissionsForRolesCalls ¶
func (mock *PolicyResolverMock) PermissionsForRolesCalls() []struct { Ctx context.Context Roles []string }
PermissionsForRolesCalls gets all the calls that were made to PermissionsForRoles. Check the length with:
len(mockedPolicyResolver.PermissionsForRolesCalls())
func (*PolicyResolverMock) Roles ¶
func (mock *PolicyResolverMock) Roles(ctx context.Context) ([]authorization.Role, error)
Roles calls RolesFunc.
func (*PolicyResolverMock) RolesCalls ¶
func (mock *PolicyResolverMock) RolesCalls() []struct { Ctx context.Context }
RolesCalls gets all the calls that were made to Roles. Check the length with:
len(mockedPolicyResolver.RolesCalls())