fix(query): add LookupName method to dependency interfaces (needed by flux to()) (#14498)
parent
0cefcf1597
commit
e142f6ca7c
|
@ -0,0 +1,41 @@
|
||||||
|
package mock
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
platform "github.com/influxdata/influxdb"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BucketLookup implements the BucketLookup interface needed by flux "from" and "to".
|
||||||
|
type BucketLookup struct{}
|
||||||
|
|
||||||
|
func (BucketLookup) Lookup(_ context.Context, orgID platform.ID, name string) (platform.ID, bool) {
|
||||||
|
if name == "my-bucket" {
|
||||||
|
return platform.ID(1), true
|
||||||
|
}
|
||||||
|
return platform.InvalidID(), false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (BucketLookup) LookupName(_ context.Context, orgID platform.ID, id platform.ID) string {
|
||||||
|
if id == 1 {
|
||||||
|
return "my-bucket"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// OrganizationLookup implements the OrganizationLookup interface needed by flux "from" and "to".
|
||||||
|
type OrganizationLookup struct{}
|
||||||
|
|
||||||
|
func (OrganizationLookup) Lookup(_ context.Context, name string) (platform.ID, bool) {
|
||||||
|
if name == "my-org" {
|
||||||
|
return platform.ID(2), true
|
||||||
|
}
|
||||||
|
return platform.InvalidID(), false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (OrganizationLookup) LookupName(_ context.Context, id platform.ID) string {
|
||||||
|
if id == 2 {
|
||||||
|
return "my-org"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
|
@ -31,6 +31,21 @@ func (b *BucketLookup) Lookup(ctx context.Context, orgID platform.ID, name strin
|
||||||
return bucket.ID, true
|
return bucket.ID, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LookupName returns an bucket name given its organization ID and its bucket ID.
|
||||||
|
func (b *BucketLookup) LookupName(ctx context.Context, orgID platform.ID, id platform.ID) string {
|
||||||
|
oid := platform.ID(orgID)
|
||||||
|
id = platform.ID(id)
|
||||||
|
filter := platform.BucketFilter{
|
||||||
|
OrganizationID: &oid,
|
||||||
|
ID: &id,
|
||||||
|
}
|
||||||
|
bucket, err := b.BucketService.FindBucket(ctx, filter)
|
||||||
|
if err != nil || bucket == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return bucket.Name
|
||||||
|
}
|
||||||
|
|
||||||
func (b *BucketLookup) FindAllBuckets(ctx context.Context, orgID platform.ID) ([]*platform.Bucket, int) {
|
func (b *BucketLookup) FindAllBuckets(ctx context.Context, orgID platform.ID) ([]*platform.Bucket, int) {
|
||||||
oid := platform.ID(orgID)
|
oid := platform.ID(orgID)
|
||||||
filter := platform.BucketFilter{
|
filter := platform.BucketFilter{
|
||||||
|
@ -66,3 +81,19 @@ func (o *OrganizationLookup) Lookup(ctx context.Context, name string) (platform.
|
||||||
}
|
}
|
||||||
return org.ID, true
|
return org.ID, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LookupName returns an organization name given its ID.
|
||||||
|
func (o *OrganizationLookup) LookupName(ctx context.Context, id platform.ID) string {
|
||||||
|
id = platform.ID(id)
|
||||||
|
org, err := o.OrganizationService.FindOrganization(
|
||||||
|
ctx,
|
||||||
|
platform.OrganizationFilter{
|
||||||
|
ID: &id,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil || org == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return org.Name
|
||||||
|
}
|
||||||
|
|
|
@ -20,10 +20,12 @@ type HostLookup interface {
|
||||||
|
|
||||||
type BucketLookup interface {
|
type BucketLookup interface {
|
||||||
Lookup(ctx context.Context, orgID platform.ID, name string) (platform.ID, bool)
|
Lookup(ctx context.Context, orgID platform.ID, name string) (platform.ID, bool)
|
||||||
|
LookupName(ctx context.Context, orgID platform.ID, id platform.ID) string
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrganizationLookup interface {
|
type OrganizationLookup interface {
|
||||||
Lookup(ctx context.Context, name string) (platform.ID, bool)
|
Lookup(ctx context.Context, name string) (platform.ID, bool)
|
||||||
|
LookupName(ctx context.Context, id platform.ID) string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Dependencies struct {
|
type Dependencies struct {
|
||||||
|
|
|
@ -116,8 +116,8 @@ func TestToOpSpec_BucketsAccessed(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTo_Process(t *testing.T) {
|
func TestTo_Process(t *testing.T) {
|
||||||
oid, _ := (mockOrgLookup{}).Lookup(context.Background(), "my-org")
|
oid, _ := mock.OrganizationLookup{}.Lookup(context.Background(), "my-org")
|
||||||
bid, _ := (mockBucketLookup{}).Lookup(context.Background(), oid, "my-bucket")
|
bid, _ := mock.BucketLookup{}.Lookup(context.Background(), oid, "my-bucket")
|
||||||
type wanted struct {
|
type wanted struct {
|
||||||
result *mock.PointsWriter
|
result *mock.PointsWriter
|
||||||
tables []*executetest.Table
|
tables []*executetest.Table
|
||||||
|
@ -739,30 +739,12 @@ c _hello=4 41`),
|
||||||
|
|
||||||
func mockDependencies() influxdb.ToDependencies {
|
func mockDependencies() influxdb.ToDependencies {
|
||||||
return influxdb.ToDependencies{
|
return influxdb.ToDependencies{
|
||||||
BucketLookup: mockBucketLookup{},
|
BucketLookup: mock.BucketLookup{},
|
||||||
OrganizationLookup: mockOrgLookup{},
|
OrganizationLookup: mock.OrganizationLookup{},
|
||||||
PointsWriter: new(mock.PointsWriter),
|
PointsWriter: new(mock.PointsWriter),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockBucketLookup struct{}
|
|
||||||
|
|
||||||
func (mockBucketLookup) Lookup(_ context.Context, orgID platform.ID, name string) (platform.ID, bool) {
|
|
||||||
if name == "my-bucket" {
|
|
||||||
return platform.ID(1), true
|
|
||||||
}
|
|
||||||
return platform.InvalidID(), false
|
|
||||||
}
|
|
||||||
|
|
||||||
type mockOrgLookup struct{}
|
|
||||||
|
|
||||||
func (mockOrgLookup) Lookup(_ context.Context, name string) (platform.ID, bool) {
|
|
||||||
if name == "my-org" {
|
|
||||||
return platform.ID(2), true
|
|
||||||
}
|
|
||||||
return platform.InvalidID(), false
|
|
||||||
}
|
|
||||||
|
|
||||||
func pointsToStr(points []models.Point) string {
|
func pointsToStr(points []models.Point) string {
|
||||||
outStr := ""
|
outStr := ""
|
||||||
for _, x := range points {
|
for _, x := range points {
|
||||||
|
|
Loading…
Reference in New Issue