2019-01-08 00:37:16 +00:00
|
|
|
package influxdb_test
|
2018-07-05 22:07:53 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp"
|
2020-04-03 17:39:20 +00:00
|
|
|
platform "github.com/influxdata/influxdb/v2"
|
|
|
|
platformtesting "github.com/influxdata/influxdb/v2/testing"
|
2018-07-05 22:07:53 +00:00
|
|
|
)
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
func TestView_MarshalJSON(t *testing.T) {
|
2018-07-05 22:07:53 +00:00
|
|
|
type args struct {
|
2018-08-07 20:10:05 +00:00
|
|
|
view platform.View
|
2018-07-05 22:07:53 +00:00
|
|
|
}
|
|
|
|
type wants struct {
|
|
|
|
json string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
wants wants
|
|
|
|
}{
|
|
|
|
{
|
2020-11-09 18:40:20 +00:00
|
|
|
name: "xy",
|
2018-07-05 22:07:53 +00:00
|
|
|
args: args{
|
2018-08-07 20:10:05 +00:00
|
|
|
view: platform.View{
|
|
|
|
ViewContents: platform.ViewContents{
|
2019-04-15 22:00:40 +00:00
|
|
|
ID: platformtesting.MustIDBase16("f01dab1ef005ba11"),
|
2020-11-09 18:40:20 +00:00
|
|
|
Name: "XY widget",
|
2018-07-05 22:07:53 +00:00
|
|
|
},
|
2018-11-20 21:59:27 +00:00
|
|
|
Properties: platform.XYViewProperties{
|
|
|
|
Type: "xy",
|
2018-07-05 22:07:53 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wants: wants{
|
|
|
|
json: `
|
|
|
|
{
|
2019-04-15 22:00:40 +00:00
|
|
|
"id": "f01dab1ef005ba11",
|
2020-11-09 18:40:20 +00:00
|
|
|
"name": "XY widget",
|
2018-08-07 20:10:05 +00:00
|
|
|
"properties": {
|
2018-10-03 17:17:14 +00:00
|
|
|
"shape": "chronograf-v2",
|
2018-07-05 22:07:53 +00:00
|
|
|
"queries": null,
|
|
|
|
"axes": null,
|
2018-11-20 21:59:27 +00:00
|
|
|
"type": "xy",
|
2021-04-15 22:06:01 +00:00
|
|
|
"staticLegend": {},
|
2019-06-12 22:35:22 +00:00
|
|
|
"geom": "",
|
2020-11-09 18:40:20 +00:00
|
|
|
"colors": null,
|
2018-11-28 01:03:13 +00:00
|
|
|
"note": "",
|
2019-06-12 22:35:22 +00:00
|
|
|
"showNoteWhenEmpty": false,
|
2020-11-09 18:40:20 +00:00
|
|
|
"xColumn": "",
|
|
|
|
"generateXAxisTicks": null,
|
|
|
|
"xTotalTicks": 0,
|
|
|
|
"xTickStart": 0,
|
|
|
|
"xTickStep": 0,
|
|
|
|
"yColumn": "",
|
|
|
|
"generateYAxisTicks": null,
|
|
|
|
"yTotalTicks": 0,
|
|
|
|
"yTickStart": 0,
|
|
|
|
"yTickStep": 0,
|
2019-12-02 22:35:06 +00:00
|
|
|
"shadeBelow": false,
|
2020-11-09 18:40:20 +00:00
|
|
|
"position": "",
|
|
|
|
"timeFormat": "",
|
|
|
|
"hoverDimension": "",
|
|
|
|
"legendColorizeRows": false,
|
2021-05-25 17:31:50 +00:00
|
|
|
"legendHide": false,
|
2020-11-09 18:40:20 +00:00
|
|
|
"legendOpacity": 0,
|
|
|
|
"legendOrientationThreshold": 0
|
2018-07-05 22:07:53 +00:00
|
|
|
}
|
2020-11-09 18:40:20 +00:00
|
|
|
}`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "geo",
|
|
|
|
args: args{
|
|
|
|
view: platform.View{
|
|
|
|
ViewContents: platform.ViewContents{
|
|
|
|
ID: platformtesting.MustIDBase16("e21da111ef005b11"),
|
|
|
|
Name: "Circle Map",
|
|
|
|
},
|
|
|
|
Properties: platform.GeoViewProperties{
|
|
|
|
Type: platform.ViewPropertyTypeGeo,
|
|
|
|
Zoom: 2,
|
|
|
|
Center: platform.Datum{Lat: 50.4, Lon: 10.1},
|
|
|
|
AllowPanAndZoom: true,
|
|
|
|
GeoLayers: []platform.GeoLayer{
|
|
|
|
{
|
|
|
|
Type: "circleMap",
|
|
|
|
RadiusField: "radius",
|
|
|
|
ColorField: "color",
|
|
|
|
Radius: 12,
|
|
|
|
Blur: 20,
|
|
|
|
RadiusDimension: platform.Axis{
|
|
|
|
Label: "Frequency",
|
|
|
|
Bounds: []string{"10", "20"},
|
|
|
|
Suffix: "m",
|
|
|
|
},
|
|
|
|
ColorDimension: platform.Axis{
|
|
|
|
Label: "Severity",
|
|
|
|
Bounds: []string{"10.0", "40"},
|
|
|
|
Suffix: "%",
|
|
|
|
},
|
|
|
|
ViewColors: []platform.ViewColor{{
|
|
|
|
Type: "min",
|
|
|
|
Hex: "#FF0000",
|
|
|
|
}, {
|
|
|
|
Hex: "#000000",
|
|
|
|
Value: 10,
|
|
|
|
}, {
|
|
|
|
Hex: "#FFFFFF",
|
|
|
|
Value: 40,
|
|
|
|
}},
|
|
|
|
IntensityDimension: platform.Axis{
|
|
|
|
Label: "Impact",
|
|
|
|
Prefix: "$",
|
|
|
|
},
|
|
|
|
InterpolateColors: true,
|
|
|
|
TrackWidth: 2,
|
|
|
|
Speed: 1.0,
|
|
|
|
IsClustered: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Note: "Some more information",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wants: wants{
|
|
|
|
json: `
|
|
|
|
{
|
|
|
|
"id": "e21da111ef005b11",
|
|
|
|
"name": "Circle Map",
|
|
|
|
"properties": {
|
|
|
|
"shape": "chronograf-v2",
|
|
|
|
"type": "geo",
|
|
|
|
"queries": null,
|
|
|
|
"center": {
|
|
|
|
"lat": 50.4,
|
|
|
|
"lon": 10.1
|
|
|
|
},
|
|
|
|
"zoom": 2,
|
|
|
|
"mapStyle": "",
|
|
|
|
"allowPanAndZoom": true,
|
|
|
|
"detectCoordinateFields": false,
|
|
|
|
"colors": null,
|
|
|
|
"layers": [
|
|
|
|
{
|
|
|
|
"type": "circleMap",
|
|
|
|
"radiusField": "radius",
|
|
|
|
"colorField": "color",
|
|
|
|
"intensityField": "",
|
|
|
|
"colors": [
|
|
|
|
{
|
|
|
|
"id": "",
|
|
|
|
"type": "min",
|
|
|
|
"hex": "#FF0000",
|
|
|
|
"name": "",
|
|
|
|
"value": 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": "",
|
|
|
|
"type": "",
|
|
|
|
"hex": "#000000",
|
|
|
|
"name": "",
|
|
|
|
"value": 10
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": "",
|
|
|
|
"type": "",
|
|
|
|
"hex": "#FFFFFF",
|
|
|
|
"name": "",
|
|
|
|
"value": 40
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"radius": 12,
|
|
|
|
"blur": 20,
|
|
|
|
"radiusDimension": {
|
|
|
|
"bounds": [
|
|
|
|
"10",
|
|
|
|
"20"
|
|
|
|
],
|
|
|
|
"label": "Frequency",
|
|
|
|
"prefix": "",
|
|
|
|
"suffix": "m",
|
|
|
|
"base": "",
|
|
|
|
"scale": ""
|
|
|
|
},
|
|
|
|
"colorDimension": {
|
|
|
|
"bounds": [
|
|
|
|
"10.0",
|
|
|
|
"40"
|
|
|
|
],
|
|
|
|
"label": "Severity",
|
|
|
|
"prefix": "",
|
|
|
|
"suffix": "%",
|
|
|
|
"base": "",
|
|
|
|
"scale": ""
|
|
|
|
},
|
|
|
|
"intensityDimension": {
|
|
|
|
"bounds": null,
|
|
|
|
"label": "Impact",
|
|
|
|
"prefix": "$",
|
|
|
|
"suffix": "",
|
|
|
|
"base": "",
|
|
|
|
"scale": ""
|
|
|
|
},
|
|
|
|
"interpolateColors": true,
|
|
|
|
"trackWidth": 2,
|
|
|
|
"speed": 1,
|
|
|
|
"randomColors": false,
|
|
|
|
"isClustered": true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"note": "Some more information",
|
|
|
|
"showNoteWhenEmpty": false
|
|
|
|
}
|
|
|
|
}`,
|
2018-07-05 22:07:53 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2018-08-07 20:10:05 +00:00
|
|
|
b, err := json.MarshalIndent(tt.args.view, "", " ")
|
2018-07-05 22:07:53 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error marshalling json")
|
|
|
|
}
|
|
|
|
|
|
|
|
eq, err := jsonEqual(string(b), tt.wants.json)
|
|
|
|
if err != nil {
|
2018-10-03 17:17:14 +00:00
|
|
|
t.Fatalf("error marshalling json %v", err)
|
2018-07-05 22:07:53 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|