Files
grafana/pkg/expr/convert_to_long_test.go
Kyle Brandt d64f41afdc SQL Expressions: Re-implement feature using go-mysql-server (#99521)
* 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>
2025-02-06 07:27:28 -05:00

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)
}
}