Commit 78d72007 by Emil Hessman Committed by GitHub

Chore: Rewrite tsdb cloudmonitoring test to standard library (#30090)

parent 6f72ae38
...@@ -5,29 +5,24 @@ import ( ...@@ -5,29 +5,24 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/tsdb" "github.com/grafana/grafana/pkg/tsdb"
"github.com/stretchr/testify/assert"
. "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/require"
) )
func TestCloudMonitoringAnnotationQuery(t *testing.T) { func TestCloudMonitoringExecutor_parseToAnnotations(t *testing.T) {
Convey("CloudMonitoring Annotation Query Executor", t, func() { data, err := loadTestFile("./test-data/2-series-response-no-agg.json")
executor := &CloudMonitoringExecutor{} require.NoError(t, err)
Convey("When parsing the cloud monitoring api response", func() { require.Len(t, data.TimeSeries, 3)
data, err := loadTestFile("./test-data/2-series-response-no-agg.json")
So(err, ShouldBeNil) res := &tsdb.QueryResult{Meta: simplejson.New(), RefId: "annotationQuery"}
So(len(data.TimeSeries), ShouldEqual, 3) query := &cloudMonitoringQuery{}
res := &tsdb.QueryResult{Meta: simplejson.New(), RefId: "annotationQuery"} executor := &CloudMonitoringExecutor{}
query := &cloudMonitoringQuery{} err = executor.parseToAnnotations(res, data, query, "atitle {{metric.label.instance_name}} {{metric.value}}", "atext {{resource.label.zone}}", "atag")
err = executor.parseToAnnotations(res, data, query, "atitle {{metric.label.instance_name}} {{metric.value}}", "atext {{resource.label.zone}}", "atag") require.NoError(t, err)
So(err, ShouldBeNil)
Convey("Should return annotations table", func() { require.Len(t, res.Tables, 1)
So(len(res.Tables), ShouldEqual, 1) require.Len(t, res.Tables[0].Rows, 9)
So(len(res.Tables[0].Rows), ShouldEqual, 9) assert.Equal(t, "atitle collector-asia-east-1 9.856650", res.Tables[0].Rows[0][1])
So(res.Tables[0].Rows[0][1], ShouldEqual, "atitle collector-asia-east-1 9.856650") assert.Equal(t, "atext asia-east1-a", res.Tables[0].Rows[0][3])
So(res.Tables[0].Rows[0][3], ShouldEqual, "atext asia-east1-a")
})
})
})
} }
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