mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
InfluxDB: Fix parsing empty response (#77353)
Fix parsing empty response
This commit is contained in:
parent
8d2b3f973e
commit
4ed36cbc1d
@ -83,6 +83,10 @@ func transformRows(rows []models.Row, query models.Query) data.Frames {
|
||||
}
|
||||
}
|
||||
|
||||
if len(rows) == 0 {
|
||||
return make([]*data.Frame, 0)
|
||||
}
|
||||
|
||||
// Preallocate for the worst-case scenario
|
||||
frames := make([]*data.Frame, 0, len(rows)*len(rows[0].Columns))
|
||||
|
||||
|
@ -407,6 +407,7 @@ func TestInfluxdbResponseParser(t *testing.T) {
|
||||
)
|
||||
testFrame.Meta = &data.FrameMeta{PreferredVisualization: graphVisType, ExecutedQueryString: "Test raw query"}
|
||||
result := ResponseParse(prepare(response), 200, generateQuery(query))
|
||||
|
||||
t.Run("should parse aliases", func(t *testing.T) {
|
||||
if diff := cmp.Diff(testFrame, result.Frames[0], data.FrameTestCompareOptions()...); diff != "" {
|
||||
t.Errorf("Result mismatch (-want +got):\n%s", diff)
|
||||
@ -575,6 +576,7 @@ func TestInfluxdbResponseParser(t *testing.T) {
|
||||
t.Errorf("Result mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("shouldn't parse aliases", func(t *testing.T) {
|
||||
query = models.Query{Alias: "alias words with no brackets"}
|
||||
result = ResponseParse(prepare(response), 200, generateQuery(query))
|
||||
@ -681,6 +683,23 @@ func TestInfluxdbResponseParser(t *testing.T) {
|
||||
_, err := parseTimestamp("hello")
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("InfluxDB returns empty DataResponse when there is empty response", func(t *testing.T) {
|
||||
response := `
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"statement_id": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
|
||||
query := models.Query{}
|
||||
result := ResponseParse(prepare(response), 200, generateQuery(query))
|
||||
assert.NotNil(t, result.Frames)
|
||||
assert.Equal(t, 0, len(result.Frames))
|
||||
})
|
||||
}
|
||||
|
||||
func TestResponseParser_Parse_RetentionPolicy(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user