2018-05-14 16:26:38 +00:00
|
|
|
package mock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-10-16 21:25:07 +00:00
|
|
|
"time"
|
2018-05-14 16:26:38 +00:00
|
|
|
|
2019-01-08 00:37:16 +00:00
|
|
|
platform "github.com/influxdata/influxdb"
|
2018-05-14 16:26:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// BucketService is a mock implementation of a retention.BucketService, which
|
|
|
|
// also makes it a suitable mock to use wherever an platform.BucketService is required.
|
|
|
|
type BucketService struct {
|
|
|
|
// Methods for a retention.BucketService
|
2019-12-04 23:10:23 +00:00
|
|
|
OpenFn func() error
|
|
|
|
CloseFn func() error
|
2018-05-14 16:26:38 +00:00
|
|
|
|
|
|
|
// Methods for an platform.BucketService
|
2019-10-16 21:25:07 +00:00
|
|
|
FindBucketByIDFn func(context.Context, platform.ID) (*platform.Bucket, error)
|
|
|
|
FindBucketByNameFn func(context.Context, platform.ID, string) (*platform.Bucket, error)
|
|
|
|
FindBucketFn func(context.Context, platform.BucketFilter) (*platform.Bucket, error)
|
|
|
|
FindBucketsFn func(context.Context, platform.BucketFilter, ...platform.FindOptions) ([]*platform.Bucket, int, error)
|
|
|
|
CreateBucketFn func(context.Context, *platform.Bucket) error
|
|
|
|
UpdateBucketFn func(context.Context, platform.ID, platform.BucketUpdate) (*platform.Bucket, error)
|
|
|
|
DeleteBucketFn func(context.Context, platform.ID) error
|
2018-05-14 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 20:37:25 +00:00
|
|
|
// NewBucketService returns a mock BucketService where its methods will return
|
2018-05-14 16:26:38 +00:00
|
|
|
// zero values.
|
|
|
|
func NewBucketService() *BucketService {
|
|
|
|
return &BucketService{
|
|
|
|
OpenFn: func() error { return nil },
|
|
|
|
CloseFn: func() error { return nil },
|
|
|
|
FindBucketByIDFn: func(context.Context, platform.ID) (*platform.Bucket, error) { return nil, nil },
|
2019-10-16 21:25:07 +00:00
|
|
|
FindBucketByNameFn: func(context.Context, platform.ID, string) (*platform.Bucket, error) {
|
|
|
|
return &platform.Bucket{
|
|
|
|
ID: platform.TasksSystemBucketID,
|
|
|
|
Type: platform.BucketTypeSystem,
|
|
|
|
Name: "_tasks",
|
|
|
|
RetentionPeriod: time.Hour * 24 * 3,
|
|
|
|
Description: "System bucket for task logs",
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
FindBucketFn: func(context.Context, platform.BucketFilter) (*platform.Bucket, error) { return nil, nil },
|
2018-05-14 16:26:38 +00:00
|
|
|
FindBucketsFn: func(context.Context, platform.BucketFilter, ...platform.FindOptions) ([]*platform.Bucket, int, error) {
|
|
|
|
return nil, 0, nil
|
|
|
|
},
|
|
|
|
CreateBucketFn: func(context.Context, *platform.Bucket) error { return nil },
|
|
|
|
UpdateBucketFn: func(context.Context, platform.ID, platform.BucketUpdate) (*platform.Bucket, error) { return nil, nil },
|
|
|
|
DeleteBucketFn: func(context.Context, platform.ID) error { return nil },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open opens the BucketService.
|
|
|
|
func (s *BucketService) Open() error { return s.OpenFn() }
|
|
|
|
|
|
|
|
// Close closes the BucketService.
|
|
|
|
func (s *BucketService) Close() error { return s.CloseFn() }
|
|
|
|
|
|
|
|
// FindBucketByID returns a single bucket by ID.
|
|
|
|
func (s *BucketService) FindBucketByID(ctx context.Context, id platform.ID) (*platform.Bucket, error) {
|
|
|
|
return s.FindBucketByIDFn(ctx, id)
|
|
|
|
}
|
|
|
|
|
2019-10-16 21:25:07 +00:00
|
|
|
// FindBucketByName returns a single bucket by name.
|
|
|
|
func (s *BucketService) FindBucketByName(ctx context.Context, orgID platform.ID, name string) (*platform.Bucket, error) {
|
|
|
|
return s.FindBucketByNameFn(ctx, orgID, name)
|
|
|
|
}
|
|
|
|
|
2018-05-14 16:26:38 +00:00
|
|
|
// FindBucket returns the first bucket that matches filter.
|
|
|
|
func (s *BucketService) FindBucket(ctx context.Context, filter platform.BucketFilter) (*platform.Bucket, error) {
|
|
|
|
return s.FindBucketFn(ctx, filter)
|
|
|
|
}
|
|
|
|
|
|
|
|
// FindBuckets returns a list of buckets that match filter and the total count of matching buckets.
|
|
|
|
func (s *BucketService) FindBuckets(ctx context.Context, filter platform.BucketFilter, opts ...platform.FindOptions) ([]*platform.Bucket, int, error) {
|
|
|
|
return s.FindBucketsFn(ctx, filter, opts...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateBucket creates a new bucket and sets b.ID with the new identifier.
|
|
|
|
func (s *BucketService) CreateBucket(ctx context.Context, bucket *platform.Bucket) error {
|
|
|
|
return s.CreateBucketFn(ctx, bucket)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateBucket updates a single bucket with changeset.
|
|
|
|
func (s *BucketService) UpdateBucket(ctx context.Context, id platform.ID, upd platform.BucketUpdate) (*platform.Bucket, error) {
|
|
|
|
return s.UpdateBucketFn(ctx, id, upd)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteBucket removes a bucket by ID.
|
|
|
|
func (s *BucketService) DeleteBucket(ctx context.Context, id platform.ID) error {
|
2018-09-10 19:26:08 +00:00
|
|
|
return s.DeleteBucketFn(ctx, id)
|
2018-05-14 16:26:38 +00:00
|
|
|
}
|