mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
elastic: improve error-messages, first step, tests only (#61847)
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
type queryDataTestRoundTripper struct {
|
||||
requestCallback func(req *http.Request) error
|
||||
body []byte
|
||||
statusCode int
|
||||
}
|
||||
|
||||
// we fake the http-request-call. we return a fixed byte-array (defined by the test snapshot),
|
||||
@@ -28,16 +29,16 @@ func (rt *queryDataTestRoundTripper) RoundTrip(req *http.Request) (*http.Respons
|
||||
}
|
||||
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
StatusCode: rt.statusCode,
|
||||
Header: http.Header{},
|
||||
Body: io.NopCloser(bytes.NewReader(rt.body)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// we setup a fake datasource-info
|
||||
func newFlowTestDsInfo(body []byte, reuestCallback func(req *http.Request) error) *es.DatasourceInfo {
|
||||
func newFlowTestDsInfo(body []byte, statusCode int, reuestCallback func(req *http.Request) error) *es.DatasourceInfo {
|
||||
client := http.Client{
|
||||
Transport: &queryDataTestRoundTripper{body: body, requestCallback: reuestCallback},
|
||||
Transport: &queryDataTestRoundTripper{body: body, statusCode: statusCode, requestCallback: reuestCallback},
|
||||
}
|
||||
return &es.DatasourceInfo{
|
||||
ESVersion: semver.MustParse("8.5.0"),
|
||||
@@ -104,7 +105,7 @@ type queryDataTestResult struct {
|
||||
requestBytes []byte
|
||||
}
|
||||
|
||||
func queryDataTest(queriesBytes []byte, responseBytes []byte) (queryDataTestResult, error) {
|
||||
func queryDataTestWithResponseCode(queriesBytes []byte, responseStatusCode int, responseBytes []byte) (queryDataTestResult, error) {
|
||||
queries, err := newFlowTestQueries(queriesBytes)
|
||||
if err != nil {
|
||||
return queryDataTestResult{}, err
|
||||
@@ -113,7 +114,7 @@ func queryDataTest(queriesBytes []byte, responseBytes []byte) (queryDataTestResu
|
||||
requestBytesStored := false
|
||||
var requestBytes []byte
|
||||
|
||||
dsInfo := newFlowTestDsInfo(responseBytes, func(req *http.Request) error {
|
||||
dsInfo := newFlowTestDsInfo(responseBytes, responseStatusCode, func(req *http.Request) error {
|
||||
requestBytes, err = io.ReadAll(req.Body)
|
||||
|
||||
bodyCloseError := req.Body.Close()
|
||||
@@ -144,3 +145,7 @@ func queryDataTest(queriesBytes []byte, responseBytes []byte) (queryDataTestResu
|
||||
requestBytes: requestBytes,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func queryDataTest(queriesBytes []byte, responseBytes []byte) (queryDataTestResult, error) {
|
||||
return queryDataTestWithResponseCode(queriesBytes, 200, responseBytes)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user