2020-03-17 19:23:00 +00:00
|
|
|
package tenant_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2020-04-03 17:39:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2"
|
|
|
|
"github.com/influxdata/influxdb/v2/kv"
|
|
|
|
"github.com/influxdata/influxdb/v2/tenant"
|
|
|
|
influxdbtesting "github.com/influxdata/influxdb/v2/testing"
|
2020-03-17 19:23:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBoltOrganizationService(t *testing.T) {
|
|
|
|
influxdbtesting.OrganizationService(initBoltOrganizationService, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func initBoltOrganizationService(f influxdbtesting.OrganizationFields, t *testing.T) (influxdb.OrganizationService, string, func()) {
|
2021-08-31 20:43:45 +00:00
|
|
|
s, closeBolt := influxdbtesting.NewTestBoltStore(t)
|
2020-03-17 19:23:00 +00:00
|
|
|
svc, op, closeSvc := initOrganizationService(s, f, t)
|
|
|
|
return svc, op, func() {
|
|
|
|
closeSvc()
|
|
|
|
closeBolt()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func initOrganizationService(s kv.Store, f influxdbtesting.OrganizationFields, t *testing.T) (influxdb.OrganizationService, string, func()) {
|
2020-07-01 11:08:20 +00:00
|
|
|
storage := tenant.NewStore(s)
|
2020-03-17 19:23:00 +00:00
|
|
|
|
2020-08-11 14:56:42 +00:00
|
|
|
if f.OrgBucketIDs != nil {
|
|
|
|
storage.OrgIDGen = f.OrgBucketIDs
|
|
|
|
storage.BucketIDGen = f.OrgBucketIDs
|
2020-03-17 19:23:00 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 14:56:42 +00:00
|
|
|
// go direct to storage for test data
|
|
|
|
if err := s.Update(context.Background(), func(tx kv.Tx) error {
|
2020-03-17 19:23:00 +00:00
|
|
|
for _, o := range f.Organizations {
|
2020-08-11 14:56:42 +00:00
|
|
|
if err := storage.CreateOrg(tx.Context(), tx, o); err != nil {
|
|
|
|
return err
|
2020-03-17 19:23:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-11 14:56:42 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
t.Fatalf("failed to populate organizations: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return tenant.NewService(storage), "tenant/", func() {
|
|
|
|
// go direct to storage for test data
|
|
|
|
if err := s.Update(context.Background(), func(tx kv.Tx) error {
|
|
|
|
for _, o := range f.Organizations {
|
|
|
|
if err := storage.DeleteOrg(tx.Context(), tx, o.ID); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
t.Logf("failed to remove organizations: %v", err)
|
|
|
|
}
|
2020-03-17 19:23:00 +00:00
|
|
|
}
|
|
|
|
}
|