influxdb/mock/auth_service.go

70 lines
3.4 KiB
Go
Raw Normal View History

package mock
import (
"context"
platform "github.com/influxdata/influxdb"
"go.uber.org/zap"
)
// AuthorizationService is a mock implementation of a retention.AuthorizationService, which
// also makes it a suitable mock to use wherever an platform.AuthorizationService is required.
type AuthorizationService struct {
// Methods for a retention.AuthorizationService
OpenFn func() error
CloseFn func() error
WithLoggerFn func(l *zap.Logger)
// Methods for an platform.AuthorizationService
FindAuthorizationByIDFn func(context.Context, platform.ID) (*platform.Authorization, error)
FindAuthorizationByTokenFn func(context.Context, string) (*platform.Authorization, error)
FindAuthorizationsFn func(context.Context, platform.AuthorizationFilter, ...platform.FindOptions) ([]*platform.Authorization, int, error)
CreateAuthorizationFn func(context.Context, *platform.Authorization) error
DeleteAuthorizationFn func(context.Context, platform.ID) error
2019-03-27 19:02:45 +00:00
UpdateAuthorizationFn func(context.Context, platform.ID, *platform.AuthorizationUpdate) error
}
// NewAuthorizationService returns a mock AuthorizationService where its methods will return
// zero values.
func NewAuthorizationService() *AuthorizationService {
return &AuthorizationService{
FindAuthorizationByIDFn: func(context.Context, platform.ID) (*platform.Authorization, error) { return nil, nil },
FindAuthorizationByTokenFn: func(context.Context, string) (*platform.Authorization, error) { return nil, nil },
FindAuthorizationsFn: func(context.Context, platform.AuthorizationFilter, ...platform.FindOptions) ([]*platform.Authorization, int, error) {
return nil, 0, nil
},
2019-03-27 19:02:45 +00:00
CreateAuthorizationFn: func(context.Context, *platform.Authorization) error { return nil },
DeleteAuthorizationFn: func(context.Context, platform.ID) error { return nil },
UpdateAuthorizationFn: func(context.Context, platform.ID, *platform.AuthorizationUpdate) error { return nil },
}
}
// FindAuthorizationByID returns a single authorization by ID.
func (s *AuthorizationService) FindAuthorizationByID(ctx context.Context, id platform.ID) (*platform.Authorization, error) {
return s.FindAuthorizationByIDFn(ctx, id)
}
func (s *AuthorizationService) FindAuthorizationByToken(ctx context.Context, t string) (*platform.Authorization, error) {
return s.FindAuthorizationByTokenFn(ctx, t)
}
// FindAuthorizations returns a list of authorizations that match filter and the total count of matching authorizations.
func (s *AuthorizationService) FindAuthorizations(ctx context.Context, filter platform.AuthorizationFilter, opts ...platform.FindOptions) ([]*platform.Authorization, int, error) {
return s.FindAuthorizationsFn(ctx, filter, opts...)
}
// CreateAuthorization creates a new authorization and sets b.ID with the new identifier.
func (s *AuthorizationService) CreateAuthorization(ctx context.Context, authorization *platform.Authorization) error {
return s.CreateAuthorizationFn(ctx, authorization)
}
// DeleteAuthorization removes a authorization by ID.
func (s *AuthorizationService) DeleteAuthorization(ctx context.Context, id platform.ID) error {
return s.DeleteAuthorizationFn(ctx, id)
}
2019-03-27 19:02:45 +00:00
// UpdateAuthorization updates the status and description if available.
func (s *AuthorizationService) UpdateAuthorization(ctx context.Context, id platform.ID, upd *platform.AuthorizationUpdate) error {
return s.UpdateAuthorizationFn(ctx, id, upd)
}