2018-09-10 20:56:11 +00:00
|
|
|
package mock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-04-03 17:39:20 +00:00
|
|
|
platform "github.com/influxdata/influxdb/v2"
|
2021-09-13 19:12:35 +00:00
|
|
|
platform2 "github.com/influxdata/influxdb/v2/kit/platform"
|
2018-09-10 20:56:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
2019-12-04 23:10:23 +00:00
|
|
|
OpenFn func() error
|
|
|
|
CloseFn func() error
|
2018-09-10 20:56:11 +00:00
|
|
|
|
|
|
|
// Methods for an platform.AuthorizationService
|
2021-03-30 18:10:02 +00:00
|
|
|
FindAuthorizationByIDFn func(context.Context, platform2.ID) (*platform.Authorization, error)
|
2018-09-10 20:56:11 +00:00
|
|
|
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
|
2021-03-30 18:10:02 +00:00
|
|
|
DeleteAuthorizationFn func(context.Context, platform2.ID) error
|
|
|
|
UpdateAuthorizationFn func(context.Context, platform2.ID, *platform.AuthorizationUpdate) (*platform.Authorization, error)
|
2018-09-10 20:56:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewAuthorizationService returns a mock AuthorizationService where its methods will return
|
|
|
|
// zero values.
|
|
|
|
func NewAuthorizationService() *AuthorizationService {
|
|
|
|
return &AuthorizationService{
|
2021-03-30 18:10:02 +00:00
|
|
|
FindAuthorizationByIDFn: func(context.Context, platform2.ID) (*platform.Authorization, error) { return nil, nil },
|
2018-09-10 20:56:11 +00:00
|
|
|
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 },
|
2021-03-30 18:10:02 +00:00
|
|
|
DeleteAuthorizationFn: func(context.Context, platform2.ID) error { return nil },
|
|
|
|
UpdateAuthorizationFn: func(context.Context, platform2.ID, *platform.AuthorizationUpdate) (*platform.Authorization, error) {
|
2019-04-01 16:16:37 +00:00
|
|
|
return nil, nil
|
|
|
|
},
|
2018-09-10 20:56:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FindAuthorizationByID returns a single authorization by ID.
|
2021-03-30 18:10:02 +00:00
|
|
|
func (s *AuthorizationService) FindAuthorizationByID(ctx context.Context, id platform2.ID) (*platform.Authorization, error) {
|
2018-09-10 20:56:11 +00:00
|
|
|
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.
|
2021-03-30 18:10:02 +00:00
|
|
|
func (s *AuthorizationService) DeleteAuthorization(ctx context.Context, id platform2.ID) error {
|
2018-09-10 20:56:11 +00:00
|
|
|
return s.DeleteAuthorizationFn(ctx, id)
|
|
|
|
}
|
|
|
|
|
2019-03-27 19:02:45 +00:00
|
|
|
// UpdateAuthorization updates the status and description if available.
|
2021-03-30 18:10:02 +00:00
|
|
|
func (s *AuthorizationService) UpdateAuthorization(ctx context.Context, id platform2.ID, upd *platform.AuthorizationUpdate) (*platform.Authorization, error) {
|
2019-03-27 19:02:45 +00:00
|
|
|
return s.UpdateAuthorizationFn(ctx, id, upd)
|
2018-09-10 20:56:11 +00:00
|
|
|
}
|