Skip to content

Commit

Permalink
fix: when buckets are looked with a org name and bucket name (#18200)
Browse files Browse the repository at this point in the history
We needed to look up the org id from the org name before we could
check to confirm we were making the correct function call
  • Loading branch information
lyondhill authored May 22, 2020
1 parent 27b7a5d commit 083f72a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
17 changes: 9 additions & 8 deletions tenant/service_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,6 @@ func (s *Service) FindBuckets(ctx context.Context, filter influxdb.BucketFilter,
return []*influxdb.Bucket{b}, 1, nil
}

if filter.Name != nil && filter.OrganizationID != nil {
b, err := s.FindBucketByName(ctx, *filter.OrganizationID, *filter.Name)
if err != nil {
return nil, 0, err
}
return []*influxdb.Bucket{b}, 1, nil
}

var buckets []*influxdb.Bucket
err := s.store.View(ctx, func(tx kv.Tx) error {
if filter.OrganizationID == nil && filter.Org != nil {
Expand All @@ -100,6 +92,15 @@ func (s *Service) FindBuckets(ctx context.Context, filter influxdb.BucketFilter,
filter.OrganizationID = &org.ID
}

if filter.Name != nil && filter.OrganizationID != nil {
b, err := s.store.GetBucketByName(ctx, tx, *filter.OrganizationID, *filter.Name)
if err != nil {
return err
}
buckets = []*influxdb.Bucket{b}
return nil
}

bs, err := s.store.ListBuckets(ctx, tx, BucketFilter{
Name: filter.Name,
OrganizationID: filter.OrganizationID,
Expand Down
29 changes: 29 additions & 0 deletions tenant/service_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,32 @@ func initBucketService(s kv.Store, f influxdbtesting.BucketFields, t *testing.T)
}
}
}

func TestBucketFind(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)
}
name := "thebucket"
_, _, err = svc.FindBuckets(context.Background(), influxdb.BucketFilter{
Name: &name,
Org: &o.Name,
})
if err.Error() != `bucket "thebucket" not found` {
t.Fatal(err)
}
}

0 comments on commit 083f72a

Please sign in to comment.