influxdb/view_test.go

88 lines
1.6 KiB
Go
Raw Normal View History

package platform_test
import (
"encoding/json"
"testing"
"github.com/google/go-cmp/cmp"
feat(platform): move chronogaf v2 dashboards to platform test(testing): add tests for dashboards and cells test(bolt): all conformance tests for dashbaords and cells fix(bolt): rename dashboardV2Bucket to dashboardBucket feat(chronograf): introduce v2 dashboards Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): add tests for v2 dashboard reducer Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): create dashboard from dashboard index Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): move tests to same level of heirarchy as file tested chronograf(chore): implement import dashboard with v2 api chore(chronograf): delete dashboards from v2 api chore(chronograf): add source health handler chore(chronograf): move sources reducer to sources dir chore(chronograf): remove stutter in notify WIP stop namespacing by sourceID chore(chronograf): no longer namespace routes under sources/:sourceID WIP move dashtimeV1 to ranges WIP remove CEO chrore(chronograf): WIP Remove CEO and QueryMaker chore(chronograf): introduce updateDashboard v2 chore(chronograf): Change cell to view A dashboard's cell object now only contains positional information for the cell in it's grid and a reference to the cell's view data. A cell's view contains all necessary information for the cell's visualization. Add react-grid-layout types chore(chronograf): introduce add cell chore(chronograf): fix type errors Not on DashboardPage feat(platform): add cell methods to dashboard service interface feat(mock): update dashboard service with cell methods feat(testing): add cell methods to testing package feat(bolt): add dashboard cell methods to bolt dashbaord service feat(http): add cell routes to dashbaord handler feat(platform): add dependent create/destroy of views from cells chore(chronograf): introduce update dashboard cells endpoint WIP update cells FE fix(http): rename Cells to cells on dashboard cells response chore(chronograf): re-introduce dashboard cell dragging feat(platform): add copy dashboard cell to dashboard service chore(platform): rename cell to view across codebase feat(bolt): add replace dashboard tests Move Layouts to Cells Introduce delete cell Fix broken test fix(platform): update route for copying a a dashboard cell UI for delete cell Introduce copy cell feat(platform): add copy view options to AddDashboardCell feat(bolt): delete views when dashboard is removed. Cleanup Fix type errors Fix links not updating Remove annotations from RefreshingGraph Sources and types work fix(platform): add TODO.go files back fix(view): rename visualizationType to type in view JSON Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> fix(dashboardTime): change dashboardID to string Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> feat(http): add dashboard api to swagger documentation review(http): fix comments and function naming feat(http): update sources swagger documentation review(http): update the swagger to reflect the implementation feat(platform): add usingView options to POST /dashboard/:id/cells
2018-08-07 20:10:05 +00:00
"github.com/influxdata/platform"
platformtesting "github.com/influxdata/platform/testing"
)
feat(platform): move chronogaf v2 dashboards to platform test(testing): add tests for dashboards and cells test(bolt): all conformance tests for dashbaords and cells fix(bolt): rename dashboardV2Bucket to dashboardBucket feat(chronograf): introduce v2 dashboards Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): add tests for v2 dashboard reducer Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): create dashboard from dashboard index Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): move tests to same level of heirarchy as file tested chronograf(chore): implement import dashboard with v2 api chore(chronograf): delete dashboards from v2 api chore(chronograf): add source health handler chore(chronograf): move sources reducer to sources dir chore(chronograf): remove stutter in notify WIP stop namespacing by sourceID chore(chronograf): no longer namespace routes under sources/:sourceID WIP move dashtimeV1 to ranges WIP remove CEO chrore(chronograf): WIP Remove CEO and QueryMaker chore(chronograf): introduce updateDashboard v2 chore(chronograf): Change cell to view A dashboard's cell object now only contains positional information for the cell in it's grid and a reference to the cell's view data. A cell's view contains all necessary information for the cell's visualization. Add react-grid-layout types chore(chronograf): introduce add cell chore(chronograf): fix type errors Not on DashboardPage feat(platform): add cell methods to dashboard service interface feat(mock): update dashboard service with cell methods feat(testing): add cell methods to testing package feat(bolt): add dashboard cell methods to bolt dashbaord service feat(http): add cell routes to dashbaord handler feat(platform): add dependent create/destroy of views from cells chore(chronograf): introduce update dashboard cells endpoint WIP update cells FE fix(http): rename Cells to cells on dashboard cells response chore(chronograf): re-introduce dashboard cell dragging feat(platform): add copy dashboard cell to dashboard service chore(platform): rename cell to view across codebase feat(bolt): add replace dashboard tests Move Layouts to Cells Introduce delete cell Fix broken test fix(platform): update route for copying a a dashboard cell UI for delete cell Introduce copy cell feat(platform): add copy view options to AddDashboardCell feat(bolt): delete views when dashboard is removed. Cleanup Fix type errors Fix links not updating Remove annotations from RefreshingGraph Sources and types work fix(platform): add TODO.go files back fix(view): rename visualizationType to type in view JSON Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> fix(dashboardTime): change dashboardID to string Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> feat(http): add dashboard api to swagger documentation review(http): fix comments and function naming feat(http): update sources swagger documentation review(http): update the swagger to reflect the implementation feat(platform): add usingView options to POST /dashboard/:id/cells
2018-08-07 20:10:05 +00:00
func TestView_MarshalJSON(t *testing.T) {
type args struct {
feat(platform): move chronogaf v2 dashboards to platform test(testing): add tests for dashboards and cells test(bolt): all conformance tests for dashbaords and cells fix(bolt): rename dashboardV2Bucket to dashboardBucket feat(chronograf): introduce v2 dashboards Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): add tests for v2 dashboard reducer Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): create dashboard from dashboard index Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): move tests to same level of heirarchy as file tested chronograf(chore): implement import dashboard with v2 api chore(chronograf): delete dashboards from v2 api chore(chronograf): add source health handler chore(chronograf): move sources reducer to sources dir chore(chronograf): remove stutter in notify WIP stop namespacing by sourceID chore(chronograf): no longer namespace routes under sources/:sourceID WIP move dashtimeV1 to ranges WIP remove CEO chrore(chronograf): WIP Remove CEO and QueryMaker chore(chronograf): introduce updateDashboard v2 chore(chronograf): Change cell to view A dashboard's cell object now only contains positional information for the cell in it's grid and a reference to the cell's view data. A cell's view contains all necessary information for the cell's visualization. Add react-grid-layout types chore(chronograf): introduce add cell chore(chronograf): fix type errors Not on DashboardPage feat(platform): add cell methods to dashboard service interface feat(mock): update dashboard service with cell methods feat(testing): add cell methods to testing package feat(bolt): add dashboard cell methods to bolt dashbaord service feat(http): add cell routes to dashbaord handler feat(platform): add dependent create/destroy of views from cells chore(chronograf): introduce update dashboard cells endpoint WIP update cells FE fix(http): rename Cells to cells on dashboard cells response chore(chronograf): re-introduce dashboard cell dragging feat(platform): add copy dashboard cell to dashboard service chore(platform): rename cell to view across codebase feat(bolt): add replace dashboard tests Move Layouts to Cells Introduce delete cell Fix broken test fix(platform): update route for copying a a dashboard cell UI for delete cell Introduce copy cell feat(platform): add copy view options to AddDashboardCell feat(bolt): delete views when dashboard is removed. Cleanup Fix type errors Fix links not updating Remove annotations from RefreshingGraph Sources and types work fix(platform): add TODO.go files back fix(view): rename visualizationType to type in view JSON Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> fix(dashboardTime): change dashboardID to string Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> feat(http): add dashboard api to swagger documentation review(http): fix comments and function naming feat(http): update sources swagger documentation review(http): update the swagger to reflect the implementation feat(platform): add usingView options to POST /dashboard/:id/cells
2018-08-07 20:10:05 +00:00
view platform.View
}
type wants struct {
json string
}
tests := []struct {
name string
args args
wants wants
}{
{
args: args{
feat(platform): move chronogaf v2 dashboards to platform test(testing): add tests for dashboards and cells test(bolt): all conformance tests for dashbaords and cells fix(bolt): rename dashboardV2Bucket to dashboardBucket feat(chronograf): introduce v2 dashboards Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): add tests for v2 dashboard reducer Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): create dashboard from dashboard index Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): move tests to same level of heirarchy as file tested chronograf(chore): implement import dashboard with v2 api chore(chronograf): delete dashboards from v2 api chore(chronograf): add source health handler chore(chronograf): move sources reducer to sources dir chore(chronograf): remove stutter in notify WIP stop namespacing by sourceID chore(chronograf): no longer namespace routes under sources/:sourceID WIP move dashtimeV1 to ranges WIP remove CEO chrore(chronograf): WIP Remove CEO and QueryMaker chore(chronograf): introduce updateDashboard v2 chore(chronograf): Change cell to view A dashboard's cell object now only contains positional information for the cell in it's grid and a reference to the cell's view data. A cell's view contains all necessary information for the cell's visualization. Add react-grid-layout types chore(chronograf): introduce add cell chore(chronograf): fix type errors Not on DashboardPage feat(platform): add cell methods to dashboard service interface feat(mock): update dashboard service with cell methods feat(testing): add cell methods to testing package feat(bolt): add dashboard cell methods to bolt dashbaord service feat(http): add cell routes to dashbaord handler feat(platform): add dependent create/destroy of views from cells chore(chronograf): introduce update dashboard cells endpoint WIP update cells FE fix(http): rename Cells to cells on dashboard cells response chore(chronograf): re-introduce dashboard cell dragging feat(platform): add copy dashboard cell to dashboard service chore(platform): rename cell to view across codebase feat(bolt): add replace dashboard tests Move Layouts to Cells Introduce delete cell Fix broken test fix(platform): update route for copying a a dashboard cell UI for delete cell Introduce copy cell feat(platform): add copy view options to AddDashboardCell feat(bolt): delete views when dashboard is removed. Cleanup Fix type errors Fix links not updating Remove annotations from RefreshingGraph Sources and types work fix(platform): add TODO.go files back fix(view): rename visualizationType to type in view JSON Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> fix(dashboardTime): change dashboardID to string Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> feat(http): add dashboard api to swagger documentation review(http): fix comments and function naming feat(http): update sources swagger documentation review(http): update the swagger to reflect the implementation feat(platform): add usingView options to POST /dashboard/:id/cells
2018-08-07 20:10:05 +00:00
view: platform.View{
ViewContents: platform.ViewContents{
ID: platformtesting.MustIDBase16("f01dab1ef005ba11"),
Name: "hello",
},
Properties: platform.XYViewProperties{
Type: "xy",
},
},
},
wants: wants{
json: `
{
"id": "f01dab1ef005ba11",
"name": "hello",
feat(platform): move chronogaf v2 dashboards to platform test(testing): add tests for dashboards and cells test(bolt): all conformance tests for dashbaords and cells fix(bolt): rename dashboardV2Bucket to dashboardBucket feat(chronograf): introduce v2 dashboards Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): add tests for v2 dashboard reducer Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): create dashboard from dashboard index Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): move tests to same level of heirarchy as file tested chronograf(chore): implement import dashboard with v2 api chore(chronograf): delete dashboards from v2 api chore(chronograf): add source health handler chore(chronograf): move sources reducer to sources dir chore(chronograf): remove stutter in notify WIP stop namespacing by sourceID chore(chronograf): no longer namespace routes under sources/:sourceID WIP move dashtimeV1 to ranges WIP remove CEO chrore(chronograf): WIP Remove CEO and QueryMaker chore(chronograf): introduce updateDashboard v2 chore(chronograf): Change cell to view A dashboard's cell object now only contains positional information for the cell in it's grid and a reference to the cell's view data. A cell's view contains all necessary information for the cell's visualization. Add react-grid-layout types chore(chronograf): introduce add cell chore(chronograf): fix type errors Not on DashboardPage feat(platform): add cell methods to dashboard service interface feat(mock): update dashboard service with cell methods feat(testing): add cell methods to testing package feat(bolt): add dashboard cell methods to bolt dashbaord service feat(http): add cell routes to dashbaord handler feat(platform): add dependent create/destroy of views from cells chore(chronograf): introduce update dashboard cells endpoint WIP update cells FE fix(http): rename Cells to cells on dashboard cells response chore(chronograf): re-introduce dashboard cell dragging feat(platform): add copy dashboard cell to dashboard service chore(platform): rename cell to view across codebase feat(bolt): add replace dashboard tests Move Layouts to Cells Introduce delete cell Fix broken test fix(platform): update route for copying a a dashboard cell UI for delete cell Introduce copy cell feat(platform): add copy view options to AddDashboardCell feat(bolt): delete views when dashboard is removed. Cleanup Fix type errors Fix links not updating Remove annotations from RefreshingGraph Sources and types work fix(platform): add TODO.go files back fix(view): rename visualizationType to type in view JSON Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> fix(dashboardTime): change dashboardID to string Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> feat(http): add dashboard api to swagger documentation review(http): fix comments and function naming feat(http): update sources swagger documentation review(http): update the swagger to reflect the implementation feat(platform): add usingView options to POST /dashboard/:id/cells
2018-08-07 20:10:05 +00:00
"properties": {
"shape": "chronograf-v2",
"queries": null,
"axes": null,
"type": "xy",
"colors": null,
"legend": {},
"geom": "",
"note": "",
"showNoteWhenEmpty": false
}
}
`,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
feat(platform): move chronogaf v2 dashboards to platform test(testing): add tests for dashboards and cells test(bolt): all conformance tests for dashbaords and cells fix(bolt): rename dashboardV2Bucket to dashboardBucket feat(chronograf): introduce v2 dashboards Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): add tests for v2 dashboard reducer Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): create dashboard from dashboard index Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> chore(chronograf): move tests to same level of heirarchy as file tested chronograf(chore): implement import dashboard with v2 api chore(chronograf): delete dashboards from v2 api chore(chronograf): add source health handler chore(chronograf): move sources reducer to sources dir chore(chronograf): remove stutter in notify WIP stop namespacing by sourceID chore(chronograf): no longer namespace routes under sources/:sourceID WIP move dashtimeV1 to ranges WIP remove CEO chrore(chronograf): WIP Remove CEO and QueryMaker chore(chronograf): introduce updateDashboard v2 chore(chronograf): Change cell to view A dashboard's cell object now only contains positional information for the cell in it's grid and a reference to the cell's view data. A cell's view contains all necessary information for the cell's visualization. Add react-grid-layout types chore(chronograf): introduce add cell chore(chronograf): fix type errors Not on DashboardPage feat(platform): add cell methods to dashboard service interface feat(mock): update dashboard service with cell methods feat(testing): add cell methods to testing package feat(bolt): add dashboard cell methods to bolt dashbaord service feat(http): add cell routes to dashbaord handler feat(platform): add dependent create/destroy of views from cells chore(chronograf): introduce update dashboard cells endpoint WIP update cells FE fix(http): rename Cells to cells on dashboard cells response chore(chronograf): re-introduce dashboard cell dragging feat(platform): add copy dashboard cell to dashboard service chore(platform): rename cell to view across codebase feat(bolt): add replace dashboard tests Move Layouts to Cells Introduce delete cell Fix broken test fix(platform): update route for copying a a dashboard cell UI for delete cell Introduce copy cell feat(platform): add copy view options to AddDashboardCell feat(bolt): delete views when dashboard is removed. Cleanup Fix type errors Fix links not updating Remove annotations from RefreshingGraph Sources and types work fix(platform): add TODO.go files back fix(view): rename visualizationType to type in view JSON Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> fix(dashboardTime): change dashboardID to string Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> feat(http): add dashboard api to swagger documentation review(http): fix comments and function naming feat(http): update sources swagger documentation review(http): update the swagger to reflect the implementation feat(platform): add usingView options to POST /dashboard/:id/cells
2018-08-07 20:10:05 +00:00
b, err := json.MarshalIndent(tt.args.view, "", " ")
if err != nil {
t.Fatalf("error marshalling json")
}
eq, err := jsonEqual(string(b), tt.wants.json)
if err != nil {
t.Fatalf("error marshalling json %v", err)
}
if !eq {
t.Errorf("JSON did not match\nexpected:%s\ngot:\n%s\n", tt.wants.json, string(b))
}
})
}
}
func jsonEqual(s1, s2 string) (eq bool, err error) {
var o1, o2 interface{}
if err = json.Unmarshal([]byte(s1), &o1); err != nil {
return
}
if err = json.Unmarshal([]byte(s2), &o2); err != nil {
return
}
return cmp.Equal(o1, o2), nil
}