-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph_test.go
44 lines (40 loc) · 1.18 KB
/
graph_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
package charts
import (
"encoding/json"
"fmt"
"testing"
)
func TestValidJSONParsing(t *testing.T) {
type testStruct struct {
Type GraphType
JSON string
}
for i, test := range []testStruct{
testStruct{GraphTypeTimeseries, "[]"},
testStruct{GraphTypePie, "[]"},
testStruct{GraphTypeLine, "[]"},
testStruct{GraphTypeTimeseries, `[{"timestamp": "2012-04-23T18:25:43.511Z", "value": 56}]`},
testStruct{GraphTypePie, `[{"percent": 50}]`},
testStruct{GraphTypeLine, `[{"x": 1, "y": 1}]`},
testStruct{GraphTypeTimeseries, `[{"timestamp": "2012-04-23T18:25:43.511Z", "value": 56.2}]`},
testStruct{GraphTypePie, `[{"percent": 50.29}]`},
testStruct{GraphTypeLine, `[{"x": 1.6, "y": 1.5}]`},
testStruct{GraphTypeTimeseries, `[{}]`},
testStruct{GraphTypePie, `[{}]`},
testStruct{GraphTypeLine, `[{}]`},
testStruct{GraphTypeLine, `[{"meta": []}]`},
testStruct{GraphTypeLine, `[{"meta": [{"key": "test", "value": "blargh"}]}]`},
} {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
var g Graph
g.Type = test.Type
err := g.parseJSONToData(json.RawMessage(test.JSON))
if err != nil {
t.Error(err)
}
if g.Data == nil {
t.Error("Data is empty!")
}
})
}
}