Skip to content

Commit

Permalink
fix: dont add system buckets when filtering by name (#18227)
Browse files Browse the repository at this point in the history
* fix: dont add system buckets when filtering by name
  • Loading branch information
lyondhill authored May 26, 2020
1 parent 30f8978 commit a1f78ec
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tenant/service_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ func (s *Service) FindBuckets(ctx context.Context, filter influxdb.BucketFilter,
return buckets, len(buckets), nil
}

// if a name is provided dont fill in system buckets
if filter.Name != nil {
return buckets, len(buckets), nil
}

// NOTE: this is a remnant of the old system.
// There are org that do not have system buckets stored, but still need to be displayed.
needsSystemBuckets := true
Expand Down
36 changes: 36 additions & 0 deletions tenant/service_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,39 @@ func TestBucketFind(t *testing.T) {
t.Fatal(err)
}
}

func TestSystemBucketsInNameFind(t *testing.T) {
s, close, err := NewTestInmemStore(t)
if err != nil {
t.Fatal(err)
}
defer close()
storage, err := tenant.NewStore(s)
if err != nil {
t.Fatal(err)
}

svc := tenant.NewService(storage)
o := &influxdb.Organization{
Name: "theorg",
}

if err := svc.CreateOrganization(context.Background(), o); err != nil {
t.Fatal(err)
}
b := &influxdb.Bucket{
OrgID: o.ID,
Name: "thebucket",
}
if err := svc.CreateBucket(context.Background(), b); err != nil {
t.Fatal(err)
}
name := "thebucket"
buckets, _, _ := svc.FindBuckets(context.Background(), influxdb.BucketFilter{
Name: &name,
Org: &o.Name,
})
if len(buckets) != 1 {
t.Fatal("failed to return a single bucket when doing a bucket lookup by name")
}
}

0 comments on commit a1f78ec

Please sign in to comment.