mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Rewrite tsdb influxdb test to standard library (#30091)
This commit is contained in:
parent
fd1b2904cd
commit
2b9387210b
@ -8,11 +8,11 @@ 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/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInfluxDB(t *testing.T) {
|
func TestInfluxDBExecutor_createRequest(t *testing.T) {
|
||||||
Convey("InfluxDB", t, func() {
|
|
||||||
datasource := &models.DataSource{
|
datasource := &models.DataSource{
|
||||||
Url: "http://awesome-influxdb:1337",
|
Url: "http://awesome-influxdb:1337",
|
||||||
Database: "awesome-db",
|
Database: "awesome-db",
|
||||||
@ -23,54 +23,41 @@ func TestInfluxDB(t *testing.T) {
|
|||||||
QueryParser: &InfluxdbQueryParser{},
|
QueryParser: &InfluxdbQueryParser{},
|
||||||
ResponseParser: &ResponseParser{},
|
ResponseParser: &ResponseParser{},
|
||||||
}
|
}
|
||||||
Convey("createRequest with GET httpMode", func() {
|
|
||||||
|
t.Run("createRequest with GET httpMode", func(t *testing.T) {
|
||||||
req, err := e.createRequest(context.Background(), datasource, query)
|
req, err := e.createRequest(context.Background(), datasource, query)
|
||||||
So(err, ShouldBeNil)
|
require.NoError(t, err)
|
||||||
|
|
||||||
Convey("as default", func() {
|
assert.Equal(t, "GET", req.Method)
|
||||||
So(req.Method, ShouldEqual, "GET")
|
|
||||||
})
|
|
||||||
|
|
||||||
Convey("has a 'q' GET param that equals to query", func() {
|
|
||||||
q := req.URL.Query().Get("q")
|
q := req.URL.Query().Get("q")
|
||||||
So(q, ShouldEqual, query)
|
assert.Equal(t, query, q)
|
||||||
|
|
||||||
|
assert.Nil(t, req.Body)
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("has an empty body", func() {
|
t.Run("createRequest with POST httpMode", func(t *testing.T) {
|
||||||
So(req.Body, ShouldEqual, nil)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
Convey("createRequest with POST httpMode", func() {
|
|
||||||
datasource.JsonData.Set("httpMode", "POST")
|
datasource.JsonData.Set("httpMode", "POST")
|
||||||
req, err := e.createRequest(context.Background(), datasource, query)
|
req, err := e.createRequest(context.Background(), datasource, query)
|
||||||
So(err, ShouldBeNil)
|
require.NoError(t, err)
|
||||||
|
|
||||||
Convey("method should be POST", func() {
|
assert.Equal(t, "POST", req.Method)
|
||||||
So(req.Method, ShouldEqual, "POST")
|
|
||||||
})
|
|
||||||
|
|
||||||
Convey("has no 'q' GET param", func() {
|
|
||||||
q := req.URL.Query().Get("q")
|
q := req.URL.Query().Get("q")
|
||||||
So(q, ShouldEqual, "")
|
assert.Empty(t, q)
|
||||||
})
|
|
||||||
|
body, err := ioutil.ReadAll(req.Body)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
Convey("has the request as GET param in body", func() {
|
|
||||||
body, _ := ioutil.ReadAll(req.Body)
|
|
||||||
testBodyValues := url.Values{}
|
testBodyValues := url.Values{}
|
||||||
testBodyValues.Add("q", query)
|
testBodyValues.Add("q", query)
|
||||||
testBody := testBodyValues.Encode()
|
testBody := testBodyValues.Encode()
|
||||||
So(string(body), ShouldEqual, testBody)
|
assert.Equal(t, testBody, string(body))
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("createRequest with PUT httpMode", func() {
|
t.Run("createRequest with PUT httpMode", func(t *testing.T) {
|
||||||
datasource.JsonData.Set("httpMode", "PUT")
|
datasource.JsonData.Set("httpMode", "PUT")
|
||||||
_, err := e.createRequest(context.Background(), datasource, query)
|
_, err := e.createRequest(context.Background(), datasource, query)
|
||||||
|
require.EqualError(t, err, ErrInvalidHttpMode.Error())
|
||||||
Convey("should miserably fail", func() {
|
|
||||||
So(err, ShouldEqual, ErrInvalidHttpMode)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user