2019-01-09 13:35:25 +00:00
|
|
|
package storage_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2020-07-30 01:08:04 +00:00
|
|
|
"github.com/golang/mock/gomock"
|
2020-04-03 17:39:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2"
|
|
|
|
"github.com/influxdata/influxdb/v2/inmem"
|
2020-07-01 11:08:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/kv/migration/all"
|
2020-04-03 17:39:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/storage"
|
2020-07-30 01:08:04 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/storage/mocks"
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/tenant"
|
2019-12-28 00:58:57 +00:00
|
|
|
"go.uber.org/zap/zaptest"
|
2019-01-09 13:35:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBucketService(t *testing.T) {
|
2020-07-30 01:08:04 +00:00
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
defer ctrl.Finish()
|
2019-01-09 13:35:25 +00:00
|
|
|
|
2020-03-12 18:32:52 +00:00
|
|
|
i, err := influxdb.IDFromString("2222222222222222")
|
2019-01-09 13:35:25 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2020-07-30 01:08:04 +00:00
|
|
|
engine := mocks.NewMockEngineSchema(ctrl)
|
2019-01-09 13:35:25 +00:00
|
|
|
|
2020-11-02 22:51:52 +00:00
|
|
|
logger := zaptest.NewLogger(t)
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
inmemService := newTenantService(t)
|
2020-11-02 22:51:52 +00:00
|
|
|
service := storage.NewBucketService(logger, inmemService, engine)
|
2019-01-09 13:35:25 +00:00
|
|
|
|
|
|
|
if err := service.DeleteBucket(context.TODO(), *i); err == nil {
|
|
|
|
t.Fatal("expected error, got nil")
|
|
|
|
}
|
|
|
|
|
2020-03-12 18:32:52 +00:00
|
|
|
org := &influxdb.Organization{Name: "org1"}
|
2019-04-09 18:24:40 +00:00
|
|
|
if err := inmemService.CreateOrganization(context.TODO(), org); err != nil {
|
2019-01-09 13:35:25 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2020-03-12 18:32:52 +00:00
|
|
|
bucket := &influxdb.Bucket{OrgID: org.ID}
|
2019-04-09 18:24:40 +00:00
|
|
|
if err := inmemService.CreateBucket(context.TODO(), bucket); err != nil {
|
2019-01-09 13:35:25 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2020-07-30 01:08:04 +00:00
|
|
|
engine.EXPECT().DeleteBucket(gomock.Any(), org.ID, bucket.ID)
|
|
|
|
|
2019-01-09 13:35:25 +00:00
|
|
|
// Test deleting a bucket calls into the deleter.
|
2020-11-02 22:51:52 +00:00
|
|
|
service = storage.NewBucketService(logger, inmemService, engine)
|
2019-01-09 13:35:25 +00:00
|
|
|
|
|
|
|
if err := service.DeleteBucket(context.TODO(), bucket.ID); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2019-12-28 00:58:57 +00:00
|
|
|
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
func newTenantService(t *testing.T) *tenant.Service {
|
2019-12-28 00:58:57 +00:00
|
|
|
t.Helper()
|
|
|
|
|
2020-07-01 11:08:20 +00:00
|
|
|
logger := zaptest.NewLogger(t)
|
|
|
|
store := inmem.NewKVStore()
|
|
|
|
if err := all.Up(context.Background(), logger, store); err != nil {
|
2019-12-28 00:58:57 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-07-01 11:08:20 +00:00
|
|
|
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
return tenant.NewService(tenant.NewStore(store))
|
2019-12-28 00:58:57 +00:00
|
|
|
}
|