mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 22:02:22 +08:00

* Under feature flag `sqlExpressions` and is experimental * Excluded from arm32 * Will not work with the Query Service yet * Does not have limits in place yet * Does not working with alerting yet * Currently requires "prepare time series" Transform for time series viz --------- Co-authored-by: Sam Jewell <sam.jewell@grafana.com>
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package expr
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/grafana/grafana-plugin-sdk-go/data"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestConvertNumericMultiToLong(t *testing.T) {
|
|
input := data.Frames{
|
|
data.NewFrame("test",
|
|
data.NewField("Value", data.Labels{"city": "MIA"}, []int64{5})),
|
|
data.NewFrame("test",
|
|
data.NewField("Value", data.Labels{"city": "LGA"}, []int64{7}),
|
|
),
|
|
}
|
|
expectedFrame := data.NewFrame("",
|
|
data.NewField("Value", nil, []int64{5, 7}),
|
|
data.NewField("city", nil, []string{"MIA", "LGA"}),
|
|
)
|
|
output, err := convertNumericMultiToNumericLong(input)
|
|
require.NoError(t, err)
|
|
|
|
if diff := cmp.Diff(expectedFrame, output[0], data.FrameTestCompareOptions()...); diff != "" {
|
|
require.FailNowf(t, "Result mismatch (-want +got):%s\n", diff)
|
|
}
|
|
}
|
|
|
|
func TestConvertNumericWideToLong(t *testing.T) {
|
|
input := data.Frames{
|
|
data.NewFrame("test",
|
|
data.NewField("Value", data.Labels{"city": "MIA"}, []int64{5}),
|
|
data.NewField("Value", data.Labels{"city": "LGA"}, []int64{7}),
|
|
),
|
|
}
|
|
expectedFrame := data.NewFrame("",
|
|
data.NewField("Value", nil, []int64{5, 7}),
|
|
data.NewField("city", nil, []string{"MIA", "LGA"}),
|
|
)
|
|
output, err := convertNumericWideToNumericLong(input)
|
|
require.NoError(t, err)
|
|
|
|
if diff := cmp.Diff(expectedFrame, output[0], data.FrameTestCompareOptions()...); diff != "" {
|
|
require.FailNowf(t, "Result mismatch (-want +got):%s\n", diff)
|
|
}
|
|
}
|