Skip to content

Commit

Permalink
test various Graphite JSON unmarshaling scenarios
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Ball <[email protected]>
  • Loading branch information
mdb committed Aug 10, 2021
1 parent ca49cf5 commit b85193c
Showing 1 changed file with 96 additions and 1 deletion.
97 changes: 96 additions & 1 deletion metricproviders/graphite/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestQuery(t *testing.T) {
"",
200,
}, {
"graphite returns data point JSON with only one item",
"graphite response data point JSON with only one item",
"target=sumSeries(app.http.*.*.count)&from=-2min",
"sumSeries(app.http.*.*.count)",
"-2min",
Expand All @@ -142,6 +142,101 @@ func TestQuery(t *testing.T) {
}
]`,
200,
}, {
"graphite response data point JSON with an invalid timestamp",
"target=sumSeries(app.http.*.*.count)&from=-2min",
"sumSeries(app.http.*.*.count)",
"-2min",
nil,
errors.New("strconv.ParseInt: parsing \"f\": invalid syntax"),
`[
{
"datapoints": [
[
100,
"f"
]
],
"target": "sumSeries(app.http.*.*.count)"
}
]`,
200,
}, {
"graphite response data point JSON with a string value",
"target=sumSeries(app.http.*.*.count)&from=-2min",
"sumSeries(app.http.*.*.count)",
"-2min",
&goodResult,
nil,
`[
{
"datapoints": [
[
"100",
1621348420
]
],
"target": "sumSeries(app.http.*.*.count)"
}
]`,
200,
}, {
"graphite response data point JSON triggers unmarshaling error",
"target=sumSeries(app.http.*.*.count)&from=-2min",
"sumSeries(app.http.*.*.count)",
"-2min",
nil,
errors.New("error unmarshaling value: []"),
`[
{
"datapoints": [
[
[],
1621348420
]
],
"target": "sumSeries(app.http.*.*.count)"
}
]`,
200,
}, {
"graphite response data point JSON with a string timestamp",
"target=sumSeries(app.http.*.*.count)&from=-2min",
"sumSeries(app.http.*.*.count)",
"-2min",
&goodResult,
nil,
`[
{
"datapoints": [
[
100,
"1621348420"
]
],
"target": "sumSeries(app.http.*.*.count)"
}
]`,
200,
}, {
"graphite response data point timestamp JSON triggers unmarshaling error",
"target=sumSeries(app.http.*.*.count)&from=-2min",
"sumSeries(app.http.*.*.count)",
"-2min",
nil,
errors.New("error unmarshaling timestamp: 100"),
`[
{
"datapoints": [
[
100,
[]
]
],
"target": "sumSeries(app.http.*.*.count)"
}
]`,
200,
}}

for _, test := range tests {
Expand Down

0 comments on commit b85193c

Please sign in to comment.