91 lines
2.9 KiB
Go
91 lines
2.9 KiB
Go
package permissions
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/stretchr/testify/mock"
|
|
"go.infratographer.com/x/gidx"
|
|
)
|
|
|
|
// MockClient implements Client for testing.
|
|
type MockClient struct {
|
|
mock.Mock
|
|
}
|
|
|
|
// AssignRole implements Client for testing.
|
|
func (c *MockClient) AssignRole(ctx context.Context, roleID gidx.PrefixedID, memberID gidx.PrefixedID) error {
|
|
args := c.Called(roleID, memberID)
|
|
|
|
return args.Error(0)
|
|
}
|
|
|
|
// CreateRole implements Client for testing.
|
|
func (c *MockClient) CreateRole(ctx context.Context, resourceID gidx.PrefixedID, actions []string) (gidx.PrefixedID, error) {
|
|
args := c.Called(resourceID, actions)
|
|
|
|
return args.Get(0).(gidx.PrefixedID), args.Error(1)
|
|
}
|
|
|
|
// DeleteResourceRelationship implements Client for testing.
|
|
func (c *MockClient) DeleteResourceRelationship(ctx context.Context, resourceID gidx.PrefixedID, relation string, relatedResourceID gidx.PrefixedID) error {
|
|
args := c.Called(resourceID, relation, relatedResourceID)
|
|
|
|
return args.Error(0)
|
|
}
|
|
|
|
// DeleteRole implements Client for testing.
|
|
func (c *MockClient) DeleteRole(ctx context.Context, roleID gidx.PrefixedID) error {
|
|
args := c.Called(roleID)
|
|
|
|
return args.Error(0)
|
|
}
|
|
|
|
// FindResourceRoleByActions implements Client for testing.
|
|
func (c *MockClient) FindResourceRoleByActions(ctx context.Context, resourceID gidx.PrefixedID, actions []string) (ResourceRole, error) {
|
|
args := c.Called(resourceID, actions)
|
|
|
|
return args.Get(0).(ResourceRole), args.Error(1)
|
|
}
|
|
|
|
// ListResourceRelationshipsFrom implements Client for testing.
|
|
func (c *MockClient) ListResourceRelationshipsFrom(ctx context.Context, resourceID gidx.PrefixedID) ([]ResourceRelationship, error) {
|
|
args := c.Called(resourceID)
|
|
|
|
return args.Get(0).([]ResourceRelationship), args.Error(1)
|
|
}
|
|
|
|
// ListResourceRelationshipsTo implements Client for testing.
|
|
func (c *MockClient) ListResourceRelationshipsTo(ctx context.Context, resourceID gidx.PrefixedID) ([]ResourceRelationship, error) {
|
|
args := c.Called(resourceID)
|
|
|
|
return args.Get(0).([]ResourceRelationship), args.Error(1)
|
|
}
|
|
|
|
// ListResourceRoles implements Client for testing.
|
|
func (c *MockClient) ListResourceRoles(ctx context.Context, resourceID gidx.PrefixedID) (ResourceRoles, error) {
|
|
args := c.Called(resourceID)
|
|
|
|
return args.Get(0).(ResourceRoles), args.Error(1)
|
|
}
|
|
|
|
// ListRoleAssignments implements Client for testing.
|
|
func (c *MockClient) ListRoleAssignments(ctx context.Context, roleID gidx.PrefixedID) ([]gidx.PrefixedID, error) {
|
|
args := c.Called(roleID)
|
|
|
|
return args.Get(0).([]gidx.PrefixedID), args.Error(1)
|
|
}
|
|
|
|
// RoleHasAssignment implements Client for testing.
|
|
func (c *MockClient) RoleHasAssignment(ctx context.Context, roleID gidx.PrefixedID, memberID gidx.PrefixedID) (bool, error) {
|
|
args := c.Called(roleID, memberID)
|
|
|
|
return args.Bool(0), args.Error(1)
|
|
}
|
|
|
|
// UnassignRole implements Client for testing.
|
|
func (c *MockClient) UnassignRole(ctx context.Context, roleID gidx.PrefixedID, memberID gidx.PrefixedID) error {
|
|
args := c.Called(roleID, memberID)
|
|
|
|
return args.Error(0)
|
|
}
|