forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard_test.go
90 lines (82 loc) · 1.65 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package influxdb_test
import (
"encoding/json"
"testing"
"github.com/google/go-cmp/cmp"
platform "github.com/influxdata/influxdb"
platformtesting "github.com/influxdata/influxdb/testing"
)
func TestView_MarshalJSON(t *testing.T) {
type args struct {
view platform.View
}
type wants struct {
json string
}
tests := []struct {
name string
args args
wants wants
}{
{
args: args{
view: platform.View{
ViewContents: platform.ViewContents{
ID: platformtesting.MustIDBase16("f01dab1ef005ba11"),
Name: "hello",
},
Properties: platform.XYViewProperties{
Type: "xy",
},
},
},
wants: wants{
json: `
{
"id": "f01dab1ef005ba11",
"name": "hello",
"properties": {
"shape": "chronograf-v2",
"queries": null,
"axes": null,
"type": "xy",
"colors": null,
"legend": {},
"geom": "",
"note": "",
"showNoteWhenEmpty": false,
"xColumn": "",
"yColumn": "",
"shadeBelow": false
}
}
`,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
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
}