2019-07-24 02:46:42 +00:00
|
|
|
package kv_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/influxdata/influxdb"
|
|
|
|
"github.com/influxdata/influxdb/kv"
|
|
|
|
influxdbtesting "github.com/influxdata/influxdb/testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBoltNotificationRuleStore(t *testing.T) {
|
2019-08-27 17:29:49 +00:00
|
|
|
t.Skip("https://github.com/influxdata/influxdb/issues/14799")
|
2019-07-24 02:46:42 +00:00
|
|
|
influxdbtesting.NotificationRuleStore(initBoltNotificationRuleStore, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNotificationRuleStore(t *testing.T) {
|
2019-08-27 17:29:49 +00:00
|
|
|
t.Skip("https://github.com/influxdata/influxdb/issues/14799")
|
2019-07-24 02:46:42 +00:00
|
|
|
influxdbtesting.NotificationRuleStore(initInmemNotificationRuleStore, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func initBoltNotificationRuleStore(f influxdbtesting.NotificationRuleFields, t *testing.T) (influxdb.NotificationRuleStore, func()) {
|
|
|
|
s, closeBolt, err := NewTestBoltStore()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to create new kv store: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
svc, closeSvc := initNotificationRuleStore(s, f, t)
|
|
|
|
return svc, func() {
|
|
|
|
closeSvc()
|
|
|
|
closeBolt()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func initInmemNotificationRuleStore(f influxdbtesting.NotificationRuleFields, t *testing.T) (influxdb.NotificationRuleStore, func()) {
|
|
|
|
s, closeBolt, err := NewTestInmemStore()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to create new kv store: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
svc, closeSvc := initNotificationRuleStore(s, f, t)
|
|
|
|
return svc, func() {
|
|
|
|
closeSvc()
|
|
|
|
closeBolt()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func initNotificationRuleStore(s kv.Store, f influxdbtesting.NotificationRuleFields, t *testing.T) (influxdb.NotificationRuleStore, func()) {
|
|
|
|
svc := kv.NewService(s)
|
|
|
|
svc.IDGenerator = f.IDGenerator
|
|
|
|
svc.TimeGenerator = f.TimeGenerator
|
|
|
|
if f.TimeGenerator == nil {
|
|
|
|
svc.TimeGenerator = influxdb.RealTimeGenerator{}
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
if err := svc.Initialize(ctx); err != nil {
|
|
|
|
t.Fatalf("error initializing user service: %v", err)
|
|
|
|
}
|
|
|
|
|
2019-08-27 17:29:49 +00:00
|
|
|
for _, o := range f.Orgs {
|
|
|
|
if err := svc.PutOrganization(ctx, o); err != nil {
|
|
|
|
t.Fatalf("failed to populate org: %v", err)
|
2019-07-24 02:46:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, m := range f.UserResourceMappings {
|
|
|
|
if err := svc.CreateUserResourceMapping(ctx, m); err != nil {
|
|
|
|
t.Fatalf("failed to populate user resource mapping: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 17:29:49 +00:00
|
|
|
for _, e := range f.Endpoints {
|
|
|
|
if err := svc.CreateNotificationEndpoint(ctx, e, 1); err != nil {
|
|
|
|
t.Fatalf("failed to populate notification endpoint: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, nr := range f.NotificationRules {
|
2019-09-18 20:19:51 +00:00
|
|
|
nrc := influxdb.NotificationRuleCreate{
|
|
|
|
NotificationRule: nr,
|
|
|
|
Status: influxdb.Active,
|
|
|
|
}
|
|
|
|
if err := svc.PutNotificationRule(ctx, nrc); err != nil {
|
2019-08-27 17:29:49 +00:00
|
|
|
t.Fatalf("failed to populate notification rule: %v", err)
|
2019-07-24 02:46:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-25 12:53:22 +00:00
|
|
|
for _, c := range f.Tasks {
|
|
|
|
if _, err := svc.CreateTask(ctx, c); err != nil {
|
|
|
|
t.Fatalf("failed to populate task: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 02:46:42 +00:00
|
|
|
return svc, func() {
|
|
|
|
for _, nr := range f.NotificationRules {
|
|
|
|
if err := svc.DeleteNotificationRule(ctx, nr.GetID()); err != nil {
|
|
|
|
t.Logf("failed to remove notification rule: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, urm := range f.UserResourceMappings {
|
|
|
|
if err := svc.DeleteUserResourceMapping(ctx, urm.ResourceID, urm.UserID); err != nil && influxdb.ErrorCode(err) != influxdb.ENotFound {
|
|
|
|
t.Logf("failed to remove urm rule: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, o := range f.Orgs {
|
|
|
|
if err := svc.DeleteOrganization(ctx, o.ID); err != nil {
|
|
|
|
t.Fatalf("failed to remove org: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|