-
Notifications
You must be signed in to change notification settings - Fork 24
/
dashboard_test.go
87 lines (79 loc) · 1.55 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
package platform_test
import (
"encoding/json"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/influxdata/platform"
)
func TestDashboardCell_MarshalJSON(t *testing.T) {
type args struct {
cell platform.DashboardCell
}
type wants struct {
json string
}
tests := []struct {
name string
args args
wants wants
}{
{
args: args{
cell: platform.DashboardCell{
DashboardCellContents: platform.DashboardCellContents{
ID: platform.ID("0"), // This ends up being id 30 encoded
Name: "hello",
X: 10,
Y: 10,
W: 100,
H: 12,
},
Visualization: platform.CommonVisualization{
Query: "SELECT * FROM foo",
},
},
},
wants: wants{
json: `
{
"id": "30",
"name": "hello",
"x": 10,
"y": 10,
"w": 100,
"h": 12,
"visualization": {
"type": "common",
"query": "SELECT * FROM foo"
}
}
`,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
b, err := json.MarshalIndent(tt.args.cell, "", " ")
if err != nil {
t.Fatalf("error marshalling json")
}
eq, err := jsonEqual(string(b), tt.wants.json)
if err != nil {
t.Fatalf("error marshalling json")
}
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
}