mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudWatch/Logs: Don't group dataframes for non time series queries (#37998)
* Don't split response when there is no time field * Refactor grouping to separate function * Add test
This commit is contained in:
31
pkg/tsdb/cloudwatch/live_test.go
Normal file
31
pkg/tsdb/cloudwatch/live_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package cloudwatch
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGroupResponseFrame(t *testing.T) {
|
||||
t.Run("Doesn't group results without time field", func(t *testing.T) {
|
||||
frame := data.NewFrameOfFieldTypes("test", 0, data.FieldTypeString, data.FieldTypeInt32)
|
||||
frame.AppendRow("val1", int32(10))
|
||||
frame.AppendRow("val2", int32(20))
|
||||
frame.AppendRow("val3", int32(30))
|
||||
|
||||
groupedFrame, err := groupResponseFrame(frame, []string{"something"})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 3, groupedFrame[0].Rows())
|
||||
require.Equal(t, []interface{}{"val1", "val2", "val3"}, asArray(groupedFrame[0].Fields[0]))
|
||||
require.Equal(t, []interface{}{int32(10), int32(20), int32(30)}, asArray(groupedFrame[0].Fields[1]))
|
||||
})
|
||||
}
|
||||
|
||||
func asArray(field *data.Field) []interface{} {
|
||||
var vals []interface{}
|
||||
for i := 0; i < field.Len(); i++ {
|
||||
vals = append(vals, field.At(i))
|
||||
}
|
||||
return vals
|
||||
}
|
||||
Reference in New Issue
Block a user