2020-04-20 16:55:23 +00:00
|
|
|
package dbrp_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/influxdata/influxdb/v2"
|
|
|
|
"github.com/influxdata/influxdb/v2/dbrp"
|
2021-08-30 22:27:11 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/kit/platform"
|
2020-04-20 16:55:23 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/mock"
|
|
|
|
itesting "github.com/influxdata/influxdb/v2/testing"
|
|
|
|
)
|
|
|
|
|
2021-08-30 22:27:11 +00:00
|
|
|
func initDBRPMappingService(f itesting.DBRPMappingFields, t *testing.T) (influxdb.DBRPMappingService, func()) {
|
2021-08-31 20:43:45 +00:00
|
|
|
s, closeStore := itesting.NewTestBoltStore(t)
|
2020-04-20 16:55:23 +00:00
|
|
|
if f.BucketSvc == nil {
|
|
|
|
f.BucketSvc = &mock.BucketService{
|
2021-03-30 18:10:02 +00:00
|
|
|
FindBucketByIDFn: func(ctx context.Context, id platform.ID) (*influxdb.Bucket, error) {
|
2020-04-20 16:55:23 +00:00
|
|
|
// always find a bucket.
|
|
|
|
return &influxdb.Bucket{
|
|
|
|
ID: id,
|
|
|
|
Name: fmt.Sprintf("bucket-%v", id),
|
|
|
|
}, nil
|
|
|
|
},
|
2022-08-03 21:44:04 +00:00
|
|
|
FindBucketsFn: func(ctx context.Context, bf influxdb.BucketFilter, fo ...influxdb.FindOptions) ([]*influxdb.Bucket, int, error) {
|
|
|
|
return []*influxdb.Bucket{}, 0, nil
|
|
|
|
},
|
2020-04-20 16:55:23 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-01 11:08:20 +00:00
|
|
|
|
|
|
|
svc := dbrp.NewService(context.Background(), f.BucketSvc, s)
|
|
|
|
|
2020-04-20 16:55:23 +00:00
|
|
|
if err := f.Populate(context.Background(), svc); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return svc, func() {
|
|
|
|
if err := itesting.CleanupDBRPMappingsV2(context.Background(), svc); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
closeStore()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-30 22:27:11 +00:00
|
|
|
func TestBoltDBRPMappingService(t *testing.T) {
|
2020-04-20 16:55:23 +00:00
|
|
|
t.Parallel()
|
2021-08-30 22:27:11 +00:00
|
|
|
itesting.DBRPMappingService(initDBRPMappingService, t)
|
2020-04-20 16:55:23 +00:00
|
|
|
}
|