2018-05-31 14:44:23 +00:00
|
|
|
package bolt_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
2019-01-14 03:53:31 +00:00
|
|
|
"time"
|
2018-05-31 14:44:23 +00:00
|
|
|
|
2019-01-08 00:37:16 +00:00
|
|
|
platform "github.com/influxdata/influxdb"
|
|
|
|
"github.com/influxdata/influxdb/bolt"
|
|
|
|
platformtesting "github.com/influxdata/influxdb/testing"
|
2018-05-31 14:44:23 +00:00
|
|
|
)
|
|
|
|
|
2018-12-11 18:38:24 +00:00
|
|
|
func initDashboardService(f platformtesting.DashboardFields, t *testing.T) (platform.DashboardService, string, func()) {
|
2018-05-31 14:44:23 +00:00
|
|
|
c, closeFn, err := NewTestClient()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to create new bolt client: %v", err)
|
|
|
|
}
|
2019-01-14 03:53:31 +00:00
|
|
|
|
|
|
|
if f.NowFn == nil {
|
|
|
|
f.NowFn = time.Now
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:44:23 +00:00
|
|
|
c.IDGenerator = f.IDGenerator
|
2018-10-16 13:52:52 +00:00
|
|
|
c.WithTime(f.NowFn)
|
2018-05-31 14:44:23 +00:00
|
|
|
ctx := context.TODO()
|
|
|
|
for _, b := range f.Dashboards {
|
|
|
|
if err := c.PutDashboard(ctx, b); err != nil {
|
|
|
|
t.Fatalf("failed to populate dashboards")
|
|
|
|
}
|
|
|
|
}
|
2018-12-11 18:38:24 +00:00
|
|
|
return c, bolt.OpPrefix, func() {
|
2018-05-31 14:44:23 +00:00
|
|
|
defer closeFn()
|
|
|
|
for _, b := range f.Dashboards {
|
2018-07-30 14:29:52 +00:00
|
|
|
if err := c.DeleteDashboard(ctx, b.ID); err != nil {
|
2018-05-31 14:44:23 +00:00
|
|
|
t.Logf("failed to remove dashboard: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-11 18:38:24 +00:00
|
|
|
func TestDashboardService(t *testing.T) {
|
|
|
|
platformtesting.DashboardService(initDashboardService, t)
|
2018-08-07 20:10:05 +00:00
|
|
|
}
|