mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 03:34:15 -06:00
7fbc7d019a
* refactoring store interface and init flow * fix import * fix linter * refactor resource calling * load with class * re-order args * fix tests * fix linter * remove old creator * add custom config struct * fix some tests * cleanup * fix * tackle plugins * fix linter * refactor and fix test * add connect failure error * add fix for azure, cloud monitoring and test data * restructure * remove unused err * add fake tracer for test * fix grafana ds plugin
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package influxdb
|
|
|
|
import (
|
|
"context"
|
|
"io/ioutil"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/tsdb/influxdb/models"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestExecutor_createRequest(t *testing.T) {
|
|
datasource := &models.DatasourceInfo{
|
|
URL: "http://awesome-influxdb:1337",
|
|
Database: "awesome-db",
|
|
HTTPMode: "GET",
|
|
}
|
|
query := "SELECT awesomeness FROM somewhere"
|
|
s := &Service{
|
|
queryParser: &InfluxdbQueryParser{},
|
|
responseParser: &ResponseParser{},
|
|
glog: log.New("test"),
|
|
}
|
|
|
|
t.Run("createRequest with GET httpMode", func(t *testing.T) {
|
|
req, err := s.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.HTTPMode = "POST"
|
|
req, err := s.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.HTTPMode = "PUT"
|
|
_, err := s.createRequest(context.Background(), datasource, query)
|
|
require.EqualError(t, err, ErrInvalidHttpMode.Error())
|
|
})
|
|
}
|