-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
dashboard_test.go
56 lines (47 loc) · 1.45 KB
/
dashboard_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package kv_test
import (
"context"
"testing"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kv"
influxdbtesting "github.com/influxdata/influxdb/v2/testing"
"go.uber.org/zap/zaptest"
)
func TestBoltDashboardService(t *testing.T) {
influxdbtesting.DashboardService(initBoltDashboardService, t)
}
func initBoltDashboardService(f influxdbtesting.DashboardFields, t *testing.T) (influxdb.DashboardService, string, func()) {
s, closeBolt, err := NewTestBoltStore(t)
if err != nil {
t.Fatalf("failed to create new kv store: %v", err)
}
svc, op, closeSvc := initDashboardService(s, f, t)
return svc, op, func() {
closeSvc()
closeBolt()
}
}
func initDashboardService(s kv.Store, f influxdbtesting.DashboardFields, t *testing.T) (influxdb.DashboardService, string, func()) {
if f.TimeGenerator == nil {
f.TimeGenerator = influxdb.RealTimeGenerator{}
}
svc := kv.NewService(zaptest.NewLogger(t), s)
svc.IDGenerator = f.IDGenerator
svc.TimeGenerator = f.TimeGenerator
ctx := context.Background()
if err := svc.Initialize(ctx); err != nil {
t.Fatalf("error initializing organization service: %v", err)
}
for _, b := range f.Dashboards {
if err := svc.PutDashboard(ctx, b); err != nil {
t.Fatalf("failed to populate dashboards")
}
}
return svc, kv.OpPrefix, func() {
for _, b := range f.Dashboards {
if err := svc.DeleteDashboard(ctx, b.ID); err != nil {
t.Logf("failed to remove dashboard: %v", err)
}
}
}
}