mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 21:19:28 -06:00
b79e61656a
* Introduce TSDB service Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> Co-authored-by: Erik Sundell <erik.sundell87@gmail.com> Co-authored-by: Will Browne <will.browne@grafana.com> Co-authored-by: Torkel Ödegaard <torkel@grafana.org> Co-authored-by: Will Browne <wbrowne@users.noreply.github.com> Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package influxdb
|
|
|
|
import (
|
|
"context"
|
|
"io/ioutil"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestExecutor_createRequest(t *testing.T) {
|
|
datasource := &models.DataSource{
|
|
Url: "http://awesome-influxdb:1337",
|
|
Database: "awesome-db",
|
|
JsonData: simplejson.New(),
|
|
}
|
|
query := "SELECT awesomeness FROM somewhere"
|
|
e := &Executor{
|
|
QueryParser: &InfluxdbQueryParser{},
|
|
ResponseParser: &ResponseParser{},
|
|
}
|
|
|
|
t.Run("createRequest with GET httpMode", func(t *testing.T) {
|
|
req, err := e.createRequest(context.Background(), datasource, query)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "GET", req.Method)
|
|
|
|
q := req.URL.Query().Get("q")
|
|
assert.Equal(t, query, q)
|
|
|
|
assert.Nil(t, req.Body)
|
|
})
|
|
|
|
t.Run("createRequest with POST httpMode", func(t *testing.T) {
|
|
datasource.JsonData.Set("httpMode", "POST")
|
|
req, err := e.createRequest(context.Background(), datasource, query)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "POST", req.Method)
|
|
|
|
q := req.URL.Query().Get("q")
|
|
assert.Empty(t, q)
|
|
|
|
body, err := ioutil.ReadAll(req.Body)
|
|
require.NoError(t, err)
|
|
|
|
testBodyValues := url.Values{}
|
|
testBodyValues.Add("q", query)
|
|
testBody := testBodyValues.Encode()
|
|
assert.Equal(t, testBody, string(body))
|
|
})
|
|
|
|
t.Run("createRequest with PUT httpMode", func(t *testing.T) {
|
|
datasource.JsonData.Set("httpMode", "PUT")
|
|
_, err := e.createRequest(context.Background(), datasource, query)
|
|
require.EqualError(t, err, ErrInvalidHttpMode.Error())
|
|
})
|
|
}
|