From b85193c7e66c7848934aad8acc80991c6fc5567e Mon Sep 17 00:00:00 2001 From: Mike Ball Date: Mon, 9 Aug 2021 21:13:08 -0400 Subject: [PATCH] test various Graphite JSON unmarshaling scenarios Signed-off-by: Mike Ball --- metricproviders/graphite/api_test.go | 97 +++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/metricproviders/graphite/api_test.go b/metricproviders/graphite/api_test.go index 2fbfc16e40..ade46d733f 100644 --- a/metricproviders/graphite/api_test.go +++ b/metricproviders/graphite/api_test.go @@ -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", @@ -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 {