Commit 5c0094fe by Emil Hessman Committed by GitHub

Chore: Rewrite influxdb query parser test to standard library (#29940)

parent 4f0c9411
...@@ -6,17 +6,16 @@ import ( ...@@ -6,17 +6,16 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
. "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/require"
) )
func TestInfluxdbQueryParser(t *testing.T) { func TestInfluxdbQueryParser_Parse(t *testing.T) {
Convey("Influxdb query parser", t, func() {
parser := &InfluxdbQueryParser{} parser := &InfluxdbQueryParser{}
dsInfo := &models.DataSource{ dsInfo := &models.DataSource{
JsonData: simplejson.New(), JsonData: simplejson.New(),
} }
Convey("can parse influxdb json model", func() { t.Run("can parse influxdb json model", func(t *testing.T) {
json := ` json := `
{ {
"groupBy": [ "groupBy": [
...@@ -107,20 +106,20 @@ func TestInfluxdbQueryParser(t *testing.T) { ...@@ -107,20 +106,20 @@ func TestInfluxdbQueryParser(t *testing.T) {
} }
` `
dsInfo.JsonData.Set("timeInterval", ">20s") dsInfo.JsonData.Set("timeInterval", ">20s")
modelJson, err := simplejson.NewJson([]byte(json)) modelJSON, err := simplejson.NewJson([]byte(json))
So(err, ShouldBeNil) require.NoError(t, err)
res, err := parser.Parse(modelJson, dsInfo) res, err := parser.Parse(modelJSON, dsInfo)
So(err, ShouldBeNil) require.NoError(t, err)
So(len(res.GroupBy), ShouldEqual, 3) require.Len(t, res.GroupBy, 3)
So(len(res.Selects), ShouldEqual, 3) require.Len(t, res.Selects, 3)
So(len(res.Tags), ShouldEqual, 2) require.Len(t, res.Tags, 2)
So(res.Tz, ShouldEqual, "Europe/Paris") require.Equal(t, "Europe/Paris", res.Tz)
So(res.Interval, ShouldEqual, time.Second*20) require.Equal(t, time.Second*20, res.Interval)
So(res.Alias, ShouldEqual, "series alias") require.Equal(t, "series alias", res.Alias)
}) })
Convey("can part raw query json model", func() { t.Run("can parse raw query json model", func(t *testing.T) {
json := ` json := `
{ {
"groupBy": [ "groupBy": [
...@@ -165,16 +164,15 @@ func TestInfluxdbQueryParser(t *testing.T) { ...@@ -165,16 +164,15 @@ func TestInfluxdbQueryParser(t *testing.T) {
} }
` `
modelJson, err := simplejson.NewJson([]byte(json)) modelJSON, err := simplejson.NewJson([]byte(json))
So(err, ShouldBeNil) require.NoError(t, err)
res, err := parser.Parse(modelJson, dsInfo) res, err := parser.Parse(modelJSON, dsInfo)
So(err, ShouldBeNil) require.NoError(t, err)
So(res.RawQuery, ShouldEqual, "RawDummyQuery") require.Equal(t, "RawDummyQuery", res.RawQuery)
So(len(res.GroupBy), ShouldEqual, 2) require.Len(t, res.GroupBy, 2)
So(len(res.Selects), ShouldEqual, 1) require.Len(t, res.Selects, 1)
So(len(res.Tags), ShouldEqual, 0) require.Empty(t, res.Tags)
So(res.Interval, ShouldEqual, time.Second*10) require.Equal(t, time.Second*10, res.Interval)
})
}) })
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment