2018-05-31 14:44:23 +00:00
|
|
|
package testing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
"github.com/influxdata/platform"
|
|
|
|
"github.com/influxdata/platform/mock"
|
|
|
|
)
|
|
|
|
|
2018-07-20 17:43:22 +00:00
|
|
|
const (
|
|
|
|
dashOneID = "020f755c3c082000"
|
|
|
|
dashTwoID = "020f755c3c082001"
|
|
|
|
dashThreeID = "020f755c3c082002"
|
|
|
|
)
|
|
|
|
|
2018-10-08 21:03:53 +00:00
|
|
|
func idPtr(id platform.ID) *platform.ID {
|
|
|
|
return &id
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:44:23 +00:00
|
|
|
var dashboardCmpOptions = cmp.Options{
|
|
|
|
cmp.Comparer(func(x, y []byte) bool {
|
|
|
|
return bytes.Equal(x, y)
|
|
|
|
}),
|
|
|
|
cmp.Transformer("Sort", func(in []*platform.Dashboard) []*platform.Dashboard {
|
|
|
|
out := append([]*platform.Dashboard(nil), in...) // Copy input to avoid mutating it
|
|
|
|
sort.Slice(out, func(i, j int) bool {
|
|
|
|
return out[i].ID.String() > out[j].ID.String()
|
|
|
|
})
|
|
|
|
return out
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
|
|
|
// DashboardFields will include the IDGenerator, and dashboards
|
|
|
|
type DashboardFields struct {
|
2018-08-07 20:10:05 +00:00
|
|
|
IDGenerator platform.IDGenerator
|
|
|
|
Dashboards []*platform.Dashboard
|
|
|
|
Views []*platform.View
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
|
2018-09-17 02:39:46 +00:00
|
|
|
// DashboardService tests all the service functions.
|
|
|
|
func DashboardService(
|
|
|
|
init func(DashboardFields, *testing.T) (platform.DashboardService, func()), t *testing.T,
|
|
|
|
) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fn func(init func(DashboardFields, *testing.T) (platform.DashboardService, func()),
|
|
|
|
t *testing.T)
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "FindDashboardByID",
|
|
|
|
fn: FindDashboardByID,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "FindDashboards",
|
|
|
|
fn: FindDashboards,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "CreateDashboard",
|
|
|
|
fn: CreateDashboard,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "UpdateDashboard",
|
|
|
|
fn: UpdateDashboard,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "AddDashboardCell",
|
|
|
|
fn: AddDashboardCell,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "RemoveDashboardCell",
|
|
|
|
fn: RemoveDashboardCell,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "UpdateDashboardCell",
|
|
|
|
fn: UpdateDashboardCell,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ReplaceDashboardCells",
|
|
|
|
fn: ReplaceDashboardCells,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
tt.fn(init, t)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:44:23 +00:00
|
|
|
// CreateDashboard testing
|
|
|
|
func CreateDashboard(
|
|
|
|
init func(DashboardFields, *testing.T) (platform.DashboardService, func()),
|
|
|
|
t *testing.T,
|
|
|
|
) {
|
|
|
|
type args struct {
|
|
|
|
dashboard *platform.Dashboard
|
|
|
|
}
|
|
|
|
type wants struct {
|
|
|
|
err error
|
|
|
|
dashboards []*platform.Dashboard
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields DashboardFields
|
|
|
|
args args
|
|
|
|
wants wants
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "basic create dashboard",
|
|
|
|
fields: DashboardFields{
|
|
|
|
IDGenerator: &mock.IDGenerator{
|
2018-07-30 14:29:52 +00:00
|
|
|
IDFn: func() platform.ID {
|
2018-09-12 11:24:37 +00:00
|
|
|
return MustIDFromString(dashTwoID)
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard1",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
dashboard: &platform.Dashboard{
|
2018-09-25 16:54:01 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard2",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wants: wants{
|
|
|
|
dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard1",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard2",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s, done := init(tt.fields, t)
|
|
|
|
defer done()
|
2018-09-17 02:39:46 +00:00
|
|
|
ctx := context.Background()
|
2018-05-31 14:44:23 +00:00
|
|
|
err := s.CreateDashboard(ctx, tt.args.dashboard)
|
|
|
|
if (err != nil) != (tt.wants.err != nil) {
|
|
|
|
t.Fatalf("expected error '%v' got '%v'", tt.wants.err, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil && tt.wants.err != nil {
|
|
|
|
if err.Error() != tt.wants.err.Error() {
|
|
|
|
t.Fatalf("expected error messages to match '%v' got '%v'", tt.wants.err, err.Error())
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 14:29:52 +00:00
|
|
|
defer s.DeleteDashboard(ctx, tt.args.dashboard.ID)
|
2018-05-31 14:44:23 +00:00
|
|
|
|
|
|
|
dashboards, _, err := s.FindDashboards(ctx, platform.DashboardFilter{})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to retrieve dashboards: %v", err)
|
|
|
|
}
|
|
|
|
if diff := cmp.Diff(dashboards, tt.wants.dashboards, dashboardCmpOptions...); diff != "" {
|
|
|
|
t.Errorf("dashboards are different -got/+want\ndiff %s", diff)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// AddDashboardCell testing
|
|
|
|
func AddDashboardCell(
|
2018-05-31 14:44:23 +00:00
|
|
|
init func(DashboardFields, *testing.T) (platform.DashboardService, func()),
|
|
|
|
t *testing.T,
|
|
|
|
) {
|
|
|
|
type args struct {
|
2018-08-07 20:10:05 +00:00
|
|
|
dashboardID platform.ID
|
|
|
|
cell *platform.Cell
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
type wants struct {
|
|
|
|
err error
|
2018-08-07 20:10:05 +00:00
|
|
|
dashboards []*platform.Dashboard
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
2018-08-07 20:10:05 +00:00
|
|
|
|
2018-05-31 14:44:23 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields DashboardFields
|
|
|
|
args args
|
|
|
|
wants wants
|
|
|
|
}{
|
|
|
|
{
|
2018-08-07 20:10:05 +00:00
|
|
|
name: "basic add cell",
|
2018-05-31 14:44:23 +00:00
|
|
|
fields: DashboardFields{
|
2018-08-07 20:10:05 +00:00
|
|
|
IDGenerator: &mock.IDGenerator{
|
|
|
|
IDFn: func() platform.ID {
|
2018-09-12 11:24:37 +00:00
|
|
|
return MustIDFromString(dashTwoID)
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard1",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
2018-09-26 16:04:11 +00:00
|
|
|
Views: []*platform.View{
|
|
|
|
{
|
|
|
|
ViewContents: platform.ViewContents{
|
|
|
|
ID: MustIDFromString(dashTwoID),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
args: args{
|
2018-09-12 11:24:37 +00:00
|
|
|
dashboardID: MustIDFromString(dashOneID),
|
2018-09-26 16:04:11 +00:00
|
|
|
cell: &platform.Cell{
|
|
|
|
ID: MustIDFromString(dashTwoID),
|
|
|
|
ViewID: MustIDFromString(dashTwoID),
|
|
|
|
},
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
wants: wants{
|
|
|
|
dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard1",
|
|
|
|
Cells: []*platform.Cell{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
|
|
|
ViewID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
},
|
|
|
|
},
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s, done := init(tt.fields, t)
|
|
|
|
defer done()
|
2018-09-17 02:39:46 +00:00
|
|
|
ctx := context.Background()
|
2018-08-07 20:10:05 +00:00
|
|
|
err := s.AddDashboardCell(ctx, tt.args.dashboardID, tt.args.cell, platform.AddDashboardCellOptions{})
|
2018-05-31 14:44:23 +00:00
|
|
|
if (err != nil) != (tt.wants.err != nil) {
|
2018-08-07 20:10:05 +00:00
|
|
|
t.Fatalf("expected error '%v' got '%v'", tt.wants.err, err)
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil && tt.wants.err != nil {
|
|
|
|
if err.Error() != tt.wants.err.Error() {
|
2018-08-07 20:10:05 +00:00
|
|
|
t.Fatalf("expected error messages to match '%v' got '%v'", tt.wants.err, err.Error())
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-07 20:10:05 +00:00
|
|
|
defer s.DeleteDashboard(ctx, tt.args.dashboardID)
|
2018-05-31 14:44:23 +00:00
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
dashboards, _, err := s.FindDashboards(ctx, platform.DashboardFilter{})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to retrieve dashboards: %v", err)
|
|
|
|
}
|
2018-05-31 14:44:23 +00:00
|
|
|
if diff := cmp.Diff(dashboards, tt.wants.dashboards, dashboardCmpOptions...); diff != "" {
|
|
|
|
t.Errorf("dashboards are different -got/+want\ndiff %s", diff)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// FindDashboardByID testing
|
|
|
|
func FindDashboardByID(
|
2018-05-31 14:44:23 +00:00
|
|
|
init func(DashboardFields, *testing.T) (platform.DashboardService, func()),
|
|
|
|
t *testing.T,
|
|
|
|
) {
|
|
|
|
type args struct {
|
2018-08-07 20:10:05 +00:00
|
|
|
id platform.ID
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
type wants struct {
|
2018-08-07 20:10:05 +00:00
|
|
|
err error
|
|
|
|
dashboard *platform.Dashboard
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
2018-08-07 20:10:05 +00:00
|
|
|
|
2018-05-31 14:44:23 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields DashboardFields
|
|
|
|
args args
|
|
|
|
wants wants
|
|
|
|
}{
|
|
|
|
{
|
2018-08-07 20:10:05 +00:00
|
|
|
name: "basic find dashboard by id",
|
2018-05-31 14:44:23 +00:00
|
|
|
fields: DashboardFields{
|
|
|
|
Dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard1",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard2",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
2018-09-12 11:24:37 +00:00
|
|
|
id: MustIDFromString(dashTwoID),
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
wants: wants{
|
2018-08-07 20:10:05 +00:00
|
|
|
dashboard: &platform.Dashboard{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard2",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s, done := init(tt.fields, t)
|
|
|
|
defer done()
|
2018-09-17 02:39:46 +00:00
|
|
|
ctx := context.Background()
|
2018-05-31 14:44:23 +00:00
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
dashboard, err := s.FindDashboardByID(ctx, tt.args.id)
|
2018-05-31 14:44:23 +00:00
|
|
|
if (err != nil) != (tt.wants.err != nil) {
|
|
|
|
t.Fatalf("expected errors to be equal '%v' got '%v'", tt.wants.err, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil && tt.wants.err != nil {
|
|
|
|
if err.Error() != tt.wants.err.Error() {
|
|
|
|
t.Fatalf("expected error '%v' got '%v'", tt.wants.err, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
if diff := cmp.Diff(dashboard, tt.wants.dashboard, dashboardCmpOptions...); diff != "" {
|
|
|
|
t.Errorf("dashboard is different -got/+want\ndiff %s", diff)
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FindDashboards testing
|
|
|
|
func FindDashboards(
|
|
|
|
init func(DashboardFields, *testing.T) (platform.DashboardService, func()),
|
|
|
|
t *testing.T,
|
|
|
|
) {
|
|
|
|
type args struct {
|
2018-10-08 08:56:18 +00:00
|
|
|
IDs []*platform.ID
|
2018-08-07 20:10:05 +00:00
|
|
|
name string
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type wants struct {
|
|
|
|
dashboards []*platform.Dashboard
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields DashboardFields
|
|
|
|
args args
|
|
|
|
wants wants
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "find all dashboards",
|
|
|
|
fields: DashboardFields{
|
|
|
|
Dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "abc",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "xyz",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{},
|
|
|
|
wants: wants{
|
|
|
|
dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "abc",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "xyz",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "find dashboard by id",
|
|
|
|
fields: DashboardFields{
|
|
|
|
Dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "abc",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "xyz",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
2018-10-08 08:56:18 +00:00
|
|
|
IDs: []*platform.ID{
|
2018-09-12 11:24:37 +00:00
|
|
|
idPtr(MustIDFromString(dashTwoID)),
|
2018-10-08 21:03:53 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
wants: wants{
|
|
|
|
dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-10-08 21:03:53 +00:00
|
|
|
Name: "xyz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "find multiple dashboards by id",
|
|
|
|
fields: DashboardFields{
|
|
|
|
Dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-10-08 21:03:53 +00:00
|
|
|
Name: "abc",
|
|
|
|
},
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-10-08 21:03:53 +00:00
|
|
|
Name: "xyz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
IDs: []*platform.ID{
|
2018-09-12 11:24:37 +00:00
|
|
|
idPtr(MustIDFromString(dashOneID)),
|
|
|
|
idPtr(MustIDFromString(dashTwoID)),
|
2018-10-08 08:56:18 +00:00
|
|
|
},
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
wants: wants{
|
|
|
|
dashboards: []*platform.Dashboard{
|
2018-10-08 21:03:53 +00:00
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-10-08 21:03:53 +00:00
|
|
|
Name: "abc",
|
|
|
|
},
|
2018-05-31 14:44:23 +00:00
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "xyz",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s, done := init(tt.fields, t)
|
|
|
|
defer done()
|
2018-09-17 02:39:46 +00:00
|
|
|
ctx := context.Background()
|
2018-05-31 14:44:23 +00:00
|
|
|
|
|
|
|
filter := platform.DashboardFilter{}
|
2018-10-08 08:56:18 +00:00
|
|
|
if tt.args.IDs != nil {
|
|
|
|
filter.IDs = tt.args.IDs
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dashboards, _, err := s.FindDashboards(ctx, filter)
|
|
|
|
if (err != nil) != (tt.wants.err != nil) {
|
|
|
|
t.Fatalf("expected errors to be equal '%v' got '%v'", tt.wants.err, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil && tt.wants.err != nil {
|
|
|
|
if err.Error() != tt.wants.err.Error() {
|
|
|
|
t.Fatalf("expected error '%v' got '%v'", tt.wants.err, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if diff := cmp.Diff(dashboards, tt.wants.dashboards, dashboardCmpOptions...); diff != "" {
|
|
|
|
t.Errorf("dashboards are different -got/+want\ndiff %s", diff)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteDashboard testing
|
|
|
|
func DeleteDashboard(
|
|
|
|
init func(DashboardFields, *testing.T) (platform.DashboardService, func()),
|
|
|
|
t *testing.T,
|
|
|
|
) {
|
|
|
|
type args struct {
|
2018-07-30 14:29:52 +00:00
|
|
|
ID platform.ID
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
type wants struct {
|
|
|
|
err error
|
|
|
|
dashboards []*platform.Dashboard
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields DashboardFields
|
|
|
|
args args
|
|
|
|
wants wants
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "delete dashboards using exist id",
|
|
|
|
fields: DashboardFields{
|
|
|
|
Dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "A",
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
{
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "B",
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
wants: wants{
|
|
|
|
dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "B",
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "delete dashboards using id that does not exist",
|
|
|
|
fields: DashboardFields{
|
|
|
|
Dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "A",
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
{
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "B",
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashThreeID),
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
wants: wants{
|
|
|
|
err: fmt.Errorf("dashboard not found"),
|
|
|
|
dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "A",
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
{
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "B",
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s, done := init(tt.fields, t)
|
|
|
|
defer done()
|
2018-09-17 02:39:46 +00:00
|
|
|
ctx := context.Background()
|
2018-07-30 14:29:52 +00:00
|
|
|
err := s.DeleteDashboard(ctx, tt.args.ID)
|
2018-05-31 14:44:23 +00:00
|
|
|
if (err != nil) != (tt.wants.err != nil) {
|
|
|
|
t.Fatalf("expected error '%v' got '%v'", tt.wants.err, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil && tt.wants.err != nil {
|
|
|
|
if err.Error() != tt.wants.err.Error() {
|
|
|
|
t.Fatalf("expected error messages to match '%v' got '%v'", tt.wants.err, err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
filter := platform.DashboardFilter{}
|
|
|
|
dashboards, _, err := s.FindDashboards(ctx, filter)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to retrieve dashboards: %v", err)
|
|
|
|
}
|
|
|
|
if diff := cmp.Diff(dashboards, tt.wants.dashboards, dashboardCmpOptions...); diff != "" {
|
|
|
|
t.Errorf("dashboards are different -got/+want\ndiff %s", diff)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateDashboard testing
|
|
|
|
func UpdateDashboard(
|
|
|
|
init func(DashboardFields, *testing.T) (platform.DashboardService, func()),
|
|
|
|
t *testing.T,
|
|
|
|
) {
|
|
|
|
type args struct {
|
|
|
|
name string
|
2018-07-30 14:29:52 +00:00
|
|
|
id platform.ID
|
2018-05-31 14:44:23 +00:00
|
|
|
retention int
|
|
|
|
}
|
|
|
|
type wants struct {
|
|
|
|
err error
|
|
|
|
dashboard *platform.Dashboard
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields DashboardFields
|
|
|
|
args args
|
|
|
|
wants wants
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "update name",
|
|
|
|
fields: DashboardFields{
|
|
|
|
Dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard1",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard2",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
2018-09-12 11:24:37 +00:00
|
|
|
id: MustIDFromString(dashOneID),
|
2018-05-31 14:44:23 +00:00
|
|
|
name: "changed",
|
|
|
|
},
|
|
|
|
wants: wants{
|
|
|
|
dashboard: &platform.Dashboard{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "changed",
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s, done := init(tt.fields, t)
|
|
|
|
defer done()
|
2018-09-17 02:39:46 +00:00
|
|
|
ctx := context.Background()
|
2018-05-31 14:44:23 +00:00
|
|
|
|
|
|
|
upd := platform.DashboardUpdate{}
|
|
|
|
if tt.args.name != "" {
|
|
|
|
upd.Name = &tt.args.name
|
|
|
|
}
|
|
|
|
|
2018-07-30 14:29:52 +00:00
|
|
|
dashboard, err := s.UpdateDashboard(ctx, tt.args.id, upd)
|
2018-05-31 14:44:23 +00:00
|
|
|
if (err != nil) != (tt.wants.err != nil) {
|
|
|
|
t.Fatalf("expected error '%v' got '%v'", tt.wants.err, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil && tt.wants.err != nil {
|
|
|
|
if err.Error() != tt.wants.err.Error() {
|
|
|
|
t.Fatalf("expected error messages to match '%v' got '%v'", tt.wants.err, err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if diff := cmp.Diff(dashboard, tt.wants.dashboard, dashboardCmpOptions...); diff != "" {
|
|
|
|
t.Errorf("dashboard is different -got/+want\ndiff %s", diff)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// RemoveDashboardCell testing
|
|
|
|
func RemoveDashboardCell(
|
2018-05-31 14:44:23 +00:00
|
|
|
init func(DashboardFields, *testing.T) (platform.DashboardService, func()),
|
|
|
|
t *testing.T,
|
|
|
|
) {
|
|
|
|
type args struct {
|
2018-07-30 14:29:52 +00:00
|
|
|
dashboardID platform.ID
|
2018-08-07 20:10:05 +00:00
|
|
|
cellID platform.ID
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
type wants struct {
|
|
|
|
err error
|
2018-08-07 20:10:05 +00:00
|
|
|
dashboards []*platform.Dashboard
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
2018-08-07 20:10:05 +00:00
|
|
|
|
2018-05-31 14:44:23 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields DashboardFields
|
|
|
|
args args
|
|
|
|
wants wants
|
|
|
|
}{
|
|
|
|
{
|
2018-08-07 20:10:05 +00:00
|
|
|
name: "basic remove cell",
|
2018-05-31 14:44:23 +00:00
|
|
|
fields: DashboardFields{
|
2018-08-07 20:10:05 +00:00
|
|
|
IDGenerator: &mock.IDGenerator{
|
|
|
|
IDFn: func() platform.ID {
|
2018-09-12 11:24:37 +00:00
|
|
|
return MustIDFromString(dashTwoID)
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard1",
|
|
|
|
Cells: []*platform.Cell{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
|
|
|
ViewID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
},
|
|
|
|
{
|
2018-09-26 14:12:02 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
|
|
|
ViewID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Views: []*platform.View{
|
|
|
|
{
|
|
|
|
ViewContents: platform.ViewContents{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
},
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
2018-09-12 11:24:37 +00:00
|
|
|
dashboardID: MustIDFromString(dashOneID),
|
|
|
|
cellID: MustIDFromString(dashTwoID),
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
wants: wants{
|
|
|
|
dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard1",
|
|
|
|
Cells: []*platform.Cell{
|
2018-05-31 14:44:23 +00:00
|
|
|
{
|
2018-09-26 14:12:02 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
|
|
|
ViewID: MustIDFromString(dashOneID),
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s, done := init(tt.fields, t)
|
|
|
|
defer done()
|
2018-09-17 02:39:46 +00:00
|
|
|
ctx := context.Background()
|
2018-08-07 20:10:05 +00:00
|
|
|
err := s.RemoveDashboardCell(ctx, tt.args.dashboardID, tt.args.cellID)
|
2018-05-31 14:44:23 +00:00
|
|
|
if (err != nil) != (tt.wants.err != nil) {
|
2018-08-07 20:10:05 +00:00
|
|
|
t.Fatalf("expected error '%v' got '%v'", tt.wants.err, err)
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil && tt.wants.err != nil {
|
|
|
|
if err.Error() != tt.wants.err.Error() {
|
2018-08-07 20:10:05 +00:00
|
|
|
t.Fatalf("expected error messages to match '%v' got '%v'", tt.wants.err, err.Error())
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-07 20:10:05 +00:00
|
|
|
defer s.DeleteDashboard(ctx, tt.args.dashboardID)
|
2018-05-31 14:44:23 +00:00
|
|
|
|
|
|
|
dashboards, _, err := s.FindDashboards(ctx, platform.DashboardFilter{})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to retrieve dashboards: %v", err)
|
|
|
|
}
|
|
|
|
if diff := cmp.Diff(dashboards, tt.wants.dashboards, dashboardCmpOptions...); diff != "" {
|
|
|
|
t.Errorf("dashboards are different -got/+want\ndiff %s", diff)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// UpdateDashboardCell testing
|
|
|
|
func UpdateDashboardCell(
|
2018-05-31 14:44:23 +00:00
|
|
|
init func(DashboardFields, *testing.T) (platform.DashboardService, func()),
|
|
|
|
t *testing.T,
|
|
|
|
) {
|
|
|
|
type args struct {
|
|
|
|
dashboardID platform.ID
|
|
|
|
cellID platform.ID
|
2018-09-26 16:04:11 +00:00
|
|
|
cellUpdate platform.CellUpdate
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
type wants struct {
|
|
|
|
err error
|
2018-08-07 20:10:05 +00:00
|
|
|
dashboards []*platform.Dashboard
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
2018-08-07 20:10:05 +00:00
|
|
|
|
2018-05-31 14:44:23 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields DashboardFields
|
|
|
|
args args
|
|
|
|
wants wants
|
|
|
|
}{
|
|
|
|
{
|
2018-08-07 20:10:05 +00:00
|
|
|
name: "basic remove cell",
|
2018-05-31 14:44:23 +00:00
|
|
|
fields: DashboardFields{
|
2018-08-07 20:10:05 +00:00
|
|
|
IDGenerator: &mock.IDGenerator{
|
|
|
|
IDFn: func() platform.ID {
|
2018-09-12 11:24:37 +00:00
|
|
|
return MustIDFromString(dashTwoID)
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard1",
|
|
|
|
Cells: []*platform.Cell{
|
2018-05-31 14:44:23 +00:00
|
|
|
{
|
2018-09-26 14:12:02 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
|
|
|
ViewID: MustIDFromString(dashTwoID),
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
{
|
2018-09-26 14:12:02 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
|
|
|
ViewID: MustIDFromString(dashOneID),
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
2018-09-12 11:24:37 +00:00
|
|
|
dashboardID: MustIDFromString(dashOneID),
|
|
|
|
cellID: MustIDFromString(dashTwoID),
|
2018-09-26 16:04:11 +00:00
|
|
|
cellUpdate: platform.CellUpdate{
|
|
|
|
X: func(i int32) *int32 { return &i }(int32(10)),
|
|
|
|
ViewID: MustIDFromString(dashTwoID),
|
|
|
|
},
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
wants: wants{
|
|
|
|
dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard1",
|
|
|
|
Cells: []*platform.Cell{
|
2018-05-31 14:44:23 +00:00
|
|
|
{
|
2018-09-26 14:12:02 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
|
|
|
ViewID: MustIDFromString(dashTwoID),
|
|
|
|
X: 10,
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
{
|
2018-09-26 14:12:02 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
|
|
|
ViewID: MustIDFromString(dashOneID),
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s, done := init(tt.fields, t)
|
|
|
|
defer done()
|
2018-09-17 02:39:46 +00:00
|
|
|
ctx := context.Background()
|
2018-09-26 16:04:11 +00:00
|
|
|
_, err := s.UpdateDashboardCell(ctx, tt.args.dashboardID, tt.args.cellID, tt.args.cellUpdate)
|
2018-05-31 14:44:23 +00:00
|
|
|
if (err != nil) != (tt.wants.err != nil) {
|
2018-08-07 20:10:05 +00:00
|
|
|
t.Fatalf("expected error '%v' got '%v'", tt.wants.err, err)
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil && tt.wants.err != nil {
|
|
|
|
if err.Error() != tt.wants.err.Error() {
|
2018-08-07 20:10:05 +00:00
|
|
|
t.Fatalf("expected error messages to match '%v' got '%v'", tt.wants.err, err.Error())
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-07 20:10:05 +00:00
|
|
|
defer s.DeleteDashboard(ctx, tt.args.dashboardID)
|
2018-05-31 14:44:23 +00:00
|
|
|
|
|
|
|
dashboards, _, err := s.FindDashboards(ctx, platform.DashboardFilter{})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to retrieve dashboards: %v", err)
|
|
|
|
}
|
|
|
|
if diff := cmp.Diff(dashboards, tt.wants.dashboards, dashboardCmpOptions...); diff != "" {
|
|
|
|
t.Errorf("dashboards are different -got/+want\ndiff %s", diff)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// ReplaceDashboardCells testing
|
|
|
|
func ReplaceDashboardCells(
|
2018-05-31 14:44:23 +00:00
|
|
|
init func(DashboardFields, *testing.T) (platform.DashboardService, func()),
|
|
|
|
t *testing.T,
|
|
|
|
) {
|
|
|
|
type args struct {
|
|
|
|
dashboardID platform.ID
|
2018-08-07 20:10:05 +00:00
|
|
|
cells []*platform.Cell
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
type wants struct {
|
|
|
|
err error
|
2018-08-07 20:10:05 +00:00
|
|
|
dashboards []*platform.Dashboard
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
2018-08-07 20:10:05 +00:00
|
|
|
|
2018-05-31 14:44:23 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields DashboardFields
|
|
|
|
args args
|
|
|
|
wants wants
|
|
|
|
}{
|
|
|
|
{
|
2018-08-07 20:10:05 +00:00
|
|
|
name: "basic replace cells",
|
2018-05-31 14:44:23 +00:00
|
|
|
fields: DashboardFields{
|
2018-08-07 20:10:05 +00:00
|
|
|
IDGenerator: &mock.IDGenerator{
|
|
|
|
IDFn: func() platform.ID {
|
2018-09-12 11:24:37 +00:00
|
|
|
return MustIDFromString(dashTwoID)
|
2018-08-07 20:10:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Views: []*platform.View{
|
2018-05-31 14:44:23 +00:00
|
|
|
{
|
2018-08-07 20:10:05 +00:00
|
|
|
ViewContents: platform.ViewContents{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ViewContents: platform.ViewContents{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
},
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard1",
|
|
|
|
Cells: []*platform.Cell{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
|
|
|
ViewID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
},
|
2018-05-31 14:44:23 +00:00
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
|
|
|
ViewID: MustIDFromString(dashOneID),
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
2018-09-12 11:24:37 +00:00
|
|
|
dashboardID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
cells: []*platform.Cell{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
|
|
|
ViewID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
X: 10,
|
|
|
|
},
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
|
|
|
ViewID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Y: 11,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wants: wants{
|
|
|
|
dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard1",
|
|
|
|
Cells: []*platform.Cell{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
|
|
|
ViewID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
X: 10,
|
|
|
|
},
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
|
|
|
ViewID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Y: 11,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "try to add a cell that didn't previously exist",
|
|
|
|
fields: DashboardFields{
|
|
|
|
IDGenerator: &mock.IDGenerator{
|
|
|
|
IDFn: func() platform.ID {
|
2018-09-12 11:24:37 +00:00
|
|
|
return MustIDFromString(dashTwoID)
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
2018-08-07 20:10:05 +00:00
|
|
|
},
|
|
|
|
Views: []*platform.View{
|
|
|
|
{
|
|
|
|
ViewContents: platform.ViewContents{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard1",
|
|
|
|
Cells: []*platform.Cell{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
|
|
|
ViewID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
2018-09-12 11:24:37 +00:00
|
|
|
dashboardID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
cells: []*platform.Cell{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
|
|
|
ViewID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
X: 10,
|
|
|
|
},
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
|
|
|
ViewID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Y: 11,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wants: wants{
|
|
|
|
err: fmt.Errorf("cannot replace cells that were not already present"),
|
|
|
|
dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard1",
|
|
|
|
Cells: []*platform.Cell{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
|
|
|
ViewID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "try to update a view during a replace",
|
|
|
|
fields: DashboardFields{
|
|
|
|
IDGenerator: &mock.IDGenerator{
|
|
|
|
IDFn: func() platform.ID {
|
2018-09-12 11:24:37 +00:00
|
|
|
return MustIDFromString(dashTwoID)
|
2018-08-07 20:10:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Views: []*platform.View{
|
|
|
|
{
|
|
|
|
ViewContents: platform.ViewContents{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ViewContents: platform.ViewContents{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard1",
|
|
|
|
Cells: []*platform.Cell{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
|
|
|
ViewID: MustIDFromString(dashTwoID),
|
2018-08-07 20:10:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
2018-09-12 11:24:37 +00:00
|
|
|
dashboardID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
cells: []*platform.Cell{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
|
|
|
ViewID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
X: 10,
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wants: wants{
|
2018-08-07 20:10:05 +00:00
|
|
|
err: fmt.Errorf("cannot update view id in replace"),
|
2018-05-31 14:44:23 +00:00
|
|
|
dashboards: []*platform.Dashboard{
|
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashOneID),
|
2018-08-07 20:10:05 +00:00
|
|
|
Name: "dashboard1",
|
|
|
|
Cells: []*platform.Cell{
|
2018-05-31 14:44:23 +00:00
|
|
|
{
|
2018-09-12 11:24:37 +00:00
|
|
|
ID: MustIDFromString(dashTwoID),
|
|
|
|
ViewID: MustIDFromString(dashTwoID),
|
2018-05-31 14:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s, done := init(tt.fields, t)
|
|
|
|
defer done()
|
2018-09-17 02:39:46 +00:00
|
|
|
ctx := context.Background()
|
2018-08-07 20:10:05 +00:00
|
|
|
err := s.ReplaceDashboardCells(ctx, tt.args.dashboardID, tt.args.cells)
|
2018-05-31 14:44:23 +00:00
|
|
|
if (err != nil) != (tt.wants.err != nil) {
|
2018-08-07 20:10:05 +00:00
|
|
|
t.Fatalf("expected error '%v' got '%v'", tt.wants.err, err)
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil && tt.wants.err != nil {
|
|
|
|
if err.Error() != tt.wants.err.Error() {
|
2018-08-07 20:10:05 +00:00
|
|
|
t.Fatalf("expected error messages to match '%v' got '%v'", tt.wants.err, err.Error())
|
2018-05-31 14:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-07 20:10:05 +00:00
|
|
|
defer s.DeleteDashboard(ctx, tt.args.dashboardID)
|
2018-05-31 14:44:23 +00:00
|
|
|
|
|
|
|
dashboards, _, err := s.FindDashboards(ctx, platform.DashboardFilter{})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to retrieve dashboards: %v", err)
|
|
|
|
}
|
|
|
|
if diff := cmp.Diff(dashboards, tt.wants.dashboards, dashboardCmpOptions...); diff != "" {
|
|
|
|
t.Errorf("dashboards are different -got/+want\ndiff %s", diff)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|