2019-07-08 20:44:41 +02:00
|
|
|
// +build integration
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2019-09-05 16:55:38 +02:00
|
|
|
"io"
|
2019-07-08 20:44:41 +02:00
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"reflect"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2019-09-05 16:55:38 +02:00
|
|
|
testutil "github.com/VictoriaMetrics/VictoriaMetrics/app/victoria-metrics/test"
|
2019-07-08 20:44:41 +02:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmstorage"
|
2019-09-05 10:12:02 +02:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fs"
|
2019-07-08 20:44:41 +02:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2019-09-05 16:55:38 +02:00
|
|
|
testFixturesDir = "testdata"
|
|
|
|
testStorageSuffix = "vm-test-storage"
|
|
|
|
testHTTPListenAddr = ":7654"
|
|
|
|
testStatsDListenAddr = ":2003"
|
|
|
|
testOpenTSDBListenAddr = ":4242"
|
|
|
|
testOpenTSDBHTTPListenAddr = ":4243"
|
|
|
|
testLogLevel = "INFO"
|
2019-07-08 20:44:41 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2019-09-05 16:55:38 +02:00
|
|
|
testReadHTTPPath = "http://127.0.0.1" + testHTTPListenAddr
|
|
|
|
testWriteHTTPPath = "http://127.0.0.1" + testHTTPListenAddr + "/write"
|
|
|
|
testOpenTSDBWriteHTTPPath = "http://127.0.0.1" + testOpenTSDBHTTPListenAddr + "/api/put"
|
|
|
|
testPromWriteHTTPPath = "http://127.0.0.1" + testHTTPListenAddr + "/api/v1/write"
|
|
|
|
testHealthHTTPPath = "http://127.0.0.1" + testHTTPListenAddr + "/health"
|
2019-07-08 20:44:41 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
testStorageInitTimeout = 10 * time.Second
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
storagePath string
|
|
|
|
insertionTime = time.Now().UTC()
|
|
|
|
)
|
|
|
|
|
|
|
|
type test struct {
|
2019-09-27 08:48:53 +02:00
|
|
|
Name string `json:"name"`
|
2019-09-30 10:25:54 +02:00
|
|
|
Data []string `json:"data"`
|
2019-09-27 08:48:53 +02:00
|
|
|
Query []string `json:"query"`
|
|
|
|
ResultMetrics []Metric `json:"result_metrics"`
|
|
|
|
ResultSeries Series `json:"result_series"`
|
2019-09-30 10:25:54 +02:00
|
|
|
ResultQuery Query `json:"result_query"`
|
2019-09-27 08:48:53 +02:00
|
|
|
Issue string `json:"issue"`
|
2019-07-08 20:44:41 +02:00
|
|
|
}
|
|
|
|
|
2019-09-27 08:48:53 +02:00
|
|
|
type Metric struct {
|
2019-07-08 20:44:41 +02:00
|
|
|
Metric map[string]string `json:"metric"`
|
|
|
|
Values []float64 `json:"values"`
|
|
|
|
Timestamps []int64 `json:"timestamps"`
|
|
|
|
}
|
|
|
|
|
2019-09-30 10:25:54 +02:00
|
|
|
func (r *Metric) UnmarshalJSON(b []byte) error {
|
|
|
|
type plain Metric
|
|
|
|
return json.Unmarshal(testutil.PopulateTimeTpl(b, insertionTime), (*plain)(r))
|
|
|
|
}
|
|
|
|
|
2019-09-27 08:48:53 +02:00
|
|
|
type Series struct {
|
|
|
|
Status string `json:"status"`
|
|
|
|
Data []map[string]string `json:"data"`
|
|
|
|
}
|
2019-09-30 10:25:54 +02:00
|
|
|
type Query struct {
|
|
|
|
Status string `json:"status"`
|
|
|
|
Data QueryData `json:"data"`
|
|
|
|
}
|
|
|
|
type QueryData struct {
|
|
|
|
ResultType string `json:"resultType"`
|
|
|
|
Result []QueryDataResult `json:"result"`
|
|
|
|
}
|
2019-09-27 08:48:53 +02:00
|
|
|
|
2019-09-30 10:25:54 +02:00
|
|
|
type QueryDataResult struct {
|
|
|
|
Metric map[string]string `json:"metric"`
|
|
|
|
Value []interface{} `json:"value"`
|
2019-09-08 18:48:38 +02:00
|
|
|
}
|
|
|
|
|
2019-09-30 10:25:54 +02:00
|
|
|
func (r *QueryDataResult) UnmarshalJSON(b []byte) error {
|
|
|
|
type plain QueryDataResult
|
|
|
|
return json.Unmarshal(testutil.PopulateTimeTpl(b, insertionTime), (*plain)(r))
|
2019-09-08 18:48:38 +02:00
|
|
|
}
|
|
|
|
|
2019-07-08 20:44:41 +02:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
setUp()
|
|
|
|
code := m.Run()
|
|
|
|
tearDown()
|
|
|
|
os.Exit(code)
|
|
|
|
}
|
|
|
|
|
|
|
|
func setUp() {
|
|
|
|
storagePath = filepath.Join(os.TempDir(), testStorageSuffix)
|
|
|
|
processFlags()
|
|
|
|
logger.Init()
|
|
|
|
vmstorage.InitWithoutMetrics()
|
|
|
|
vmselect.Init()
|
|
|
|
vminsert.Init()
|
|
|
|
go httpserver.Serve(*httpListenAddr, requestHandler)
|
|
|
|
readyStorageCheckFunc := func() bool {
|
|
|
|
resp, err := http.Get(testHealthHTTPPath)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
resp.Body.Close()
|
|
|
|
return resp.StatusCode == 200
|
|
|
|
}
|
|
|
|
if err := waitFor(testStorageInitTimeout, readyStorageCheckFunc); err != nil {
|
|
|
|
log.Fatalf("http server can't start for %s seconds, err %s", testStorageInitTimeout, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func processFlags() {
|
|
|
|
flag.Parse()
|
2019-09-05 10:12:02 +02:00
|
|
|
for _, fv := range []struct {
|
2019-07-08 20:44:41 +02:00
|
|
|
flag string
|
|
|
|
value string
|
|
|
|
}{
|
|
|
|
{flag: "storageDataPath", value: storagePath},
|
|
|
|
{flag: "httpListenAddr", value: testHTTPListenAddr},
|
|
|
|
{flag: "graphiteListenAddr", value: testStatsDListenAddr},
|
|
|
|
{flag: "opentsdbListenAddr", value: testOpenTSDBListenAddr},
|
|
|
|
{flag: "loggerLevel", value: testLogLevel},
|
2019-09-05 16:55:38 +02:00
|
|
|
{flag: "opentsdbHTTPListenAddr", value: testOpenTSDBHTTPListenAddr},
|
2019-07-08 20:44:41 +02:00
|
|
|
} {
|
|
|
|
// panics if flag doesn't exist
|
2019-09-05 10:12:02 +02:00
|
|
|
if err := flag.Lookup(fv.flag).Value.Set(fv.value); err != nil {
|
|
|
|
log.Fatalf("unable to set %q with value %q, err: %v", fv.flag, fv.value, err)
|
2019-07-08 20:44:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func waitFor(timeout time.Duration, f func() bool) error {
|
|
|
|
fraction := timeout / 10
|
|
|
|
for i := fraction; i < timeout; i += fraction {
|
|
|
|
if f() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
time.Sleep(fraction)
|
|
|
|
}
|
|
|
|
return fmt.Errorf("timeout")
|
|
|
|
}
|
|
|
|
|
|
|
|
func tearDown() {
|
|
|
|
if err := httpserver.Stop(*httpListenAddr); err != nil {
|
2019-09-05 16:55:38 +02:00
|
|
|
log.Printf("cannot stop the webservice: %s", err)
|
2019-07-08 20:44:41 +02:00
|
|
|
}
|
2019-09-05 10:12:02 +02:00
|
|
|
vminsert.Stop()
|
|
|
|
vmstorage.Stop()
|
|
|
|
vmselect.Stop()
|
|
|
|
fs.MustRemoveAll(storagePath)
|
|
|
|
fs.MustStopDirRemover()
|
2019-07-08 20:44:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestWriteRead(t *testing.T) {
|
|
|
|
t.Run("write", testWrite)
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
vmstorage.Stop()
|
|
|
|
// open storage after stop in write
|
|
|
|
vmstorage.InitWithoutMetrics()
|
|
|
|
t.Run("read", testRead)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testWrite(t *testing.T) {
|
2019-09-05 16:55:38 +02:00
|
|
|
t.Run("prometheus", func(t *testing.T) {
|
2019-09-30 10:25:54 +02:00
|
|
|
for _, test := range readIn("prometheus", t, insertionTime) {
|
2019-09-05 16:55:38 +02:00
|
|
|
s := newSuite(t)
|
|
|
|
r := testutil.WriteRequest{}
|
2019-09-30 10:25:54 +02:00
|
|
|
s.noError(json.Unmarshal([]byte(strings.Join(test.Data, "\n")), &r.Timeseries))
|
2019-09-05 16:55:38 +02:00
|
|
|
data, err := testutil.Compress(r)
|
|
|
|
s.greaterThan(len(r.Timeseries), 0)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("error compressing %v %s", r, err)
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
httpWrite(t, testPromWriteHTTPPath, bytes.NewBuffer(data))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-07-08 20:44:41 +02:00
|
|
|
t.Run("influxdb", func(t *testing.T) {
|
2019-09-30 10:25:54 +02:00
|
|
|
for _, x := range readIn("influxdb", t, insertionTime) {
|
2019-09-05 16:55:38 +02:00
|
|
|
test := x
|
2019-07-08 20:44:41 +02:00
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
2019-09-30 10:25:54 +02:00
|
|
|
httpWrite(t, testWriteHTTPPath, bytes.NewBufferString(strings.Join(test.Data, "\n")))
|
2019-07-08 20:44:41 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("graphite", func(t *testing.T) {
|
2019-09-30 10:25:54 +02:00
|
|
|
for _, x := range readIn("graphite", t, insertionTime) {
|
2019-09-05 16:55:38 +02:00
|
|
|
test := x
|
2019-07-08 20:44:41 +02:00
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
2019-09-30 10:25:54 +02:00
|
|
|
tcpWrite(t, "127.0.0.1"+testStatsDListenAddr, strings.Join(test.Data, "\n"))
|
2019-07-08 20:44:41 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("opentsdb", func(t *testing.T) {
|
2019-09-30 10:25:54 +02:00
|
|
|
for _, x := range readIn("opentsdb", t, insertionTime) {
|
2019-09-05 16:55:38 +02:00
|
|
|
test := x
|
2019-07-08 20:44:41 +02:00
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
2019-09-30 10:25:54 +02:00
|
|
|
tcpWrite(t, "127.0.0.1"+testOpenTSDBListenAddr, strings.Join(test.Data, "\n"))
|
2019-07-08 20:44:41 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2019-09-05 16:55:38 +02:00
|
|
|
t.Run("opentsdbhttp", func(t *testing.T) {
|
2019-09-30 10:25:54 +02:00
|
|
|
for _, x := range readIn("opentsdbhttp", t, insertionTime) {
|
2019-09-05 16:55:38 +02:00
|
|
|
test := x
|
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
logger.Infof("writing %s", test.Data)
|
2019-09-30 10:25:54 +02:00
|
|
|
httpWrite(t, testOpenTSDBWriteHTTPPath, bytes.NewBufferString(strings.Join(test.Data, "\n")))
|
2019-09-05 16:55:38 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2019-07-08 20:44:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func testRead(t *testing.T) {
|
2019-09-05 16:55:38 +02:00
|
|
|
for _, engine := range []string{"prometheus", "graphite", "opentsdb", "influxdb", "opentsdbhttp"} {
|
2019-07-08 20:44:41 +02:00
|
|
|
t.Run(engine, func(t *testing.T) {
|
2019-09-30 10:25:54 +02:00
|
|
|
for _, x := range readIn(engine, t, insertionTime) {
|
2019-09-05 16:55:38 +02:00
|
|
|
test := x
|
2019-07-08 20:44:41 +02:00
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
2019-09-27 08:48:53 +02:00
|
|
|
for _, q := range test.Query {
|
2019-09-30 10:25:54 +02:00
|
|
|
q = testutil.PopulateTimeTplString(q, insertionTime)
|
2019-09-27 08:48:53 +02:00
|
|
|
switch true {
|
|
|
|
case strings.HasPrefix(q, "/api/v1/export"):
|
|
|
|
checkMetricsResult(t, httpReadMetrics(t, testReadHTTPPath, q), test.ResultMetrics, q, test.Issue)
|
|
|
|
case strings.HasPrefix(q, "/api/v1/series"):
|
2019-09-30 10:25:54 +02:00
|
|
|
s := Series{}
|
|
|
|
httpReadStruct(t, testReadHTTPPath, q, &s)
|
|
|
|
checkSeriesResult(t, s, test.ResultSeries, q, test.Issue)
|
|
|
|
case strings.HasPrefix(q, "/api/v1/query_range"):
|
|
|
|
t.Fatalf("unsupported read query %s", q)
|
|
|
|
case strings.HasPrefix(q, "/api/v1/query"):
|
|
|
|
queryResult := Query{}
|
|
|
|
httpReadStruct(t, testReadHTTPPath, q, &queryResult)
|
|
|
|
checkQueryResult(t, queryResult, test.ResultQuery, q, test.Issue)
|
2019-09-27 08:48:53 +02:00
|
|
|
default:
|
|
|
|
t.Fatalf("unsupported read query %s", q)
|
|
|
|
}
|
|
|
|
}
|
2019-07-08 20:44:41 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-30 10:25:54 +02:00
|
|
|
func readIn(readFor string, t *testing.T, insertTime time.Time) []test {
|
2019-07-08 20:44:41 +02:00
|
|
|
t.Helper()
|
|
|
|
s := newSuite(t)
|
|
|
|
var tt []test
|
|
|
|
s.noError(filepath.Walk(filepath.Join(testFixturesDir, readFor), func(path string, info os.FileInfo, err error) error {
|
|
|
|
if filepath.Ext(path) != ".json" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
b, err := ioutil.ReadFile(path)
|
|
|
|
s.noError(err)
|
|
|
|
item := test{}
|
|
|
|
s.noError(json.Unmarshal(b, &item))
|
2019-09-30 10:25:54 +02:00
|
|
|
for i := range item.Data {
|
|
|
|
item.Data[i] = testutil.PopulateTimeTplString(item.Data[i], insertTime)
|
|
|
|
}
|
2019-07-08 20:44:41 +02:00
|
|
|
tt = append(tt, item)
|
|
|
|
return nil
|
|
|
|
}))
|
|
|
|
if len(tt) == 0 {
|
|
|
|
t.Fatalf("no test found in %s", filepath.Join(testFixturesDir, readFor))
|
|
|
|
}
|
|
|
|
return tt
|
|
|
|
}
|
|
|
|
|
2019-09-05 16:55:38 +02:00
|
|
|
func httpWrite(t *testing.T, address string, r io.Reader) {
|
2019-07-08 20:44:41 +02:00
|
|
|
t.Helper()
|
|
|
|
s := newSuite(t)
|
2019-09-05 16:55:38 +02:00
|
|
|
resp, err := http.Post(address, "", r)
|
2019-07-08 20:44:41 +02:00
|
|
|
s.noError(err)
|
|
|
|
s.noError(resp.Body.Close())
|
|
|
|
s.equalInt(resp.StatusCode, 204)
|
|
|
|
}
|
|
|
|
|
|
|
|
func tcpWrite(t *testing.T, address string, data string) {
|
|
|
|
t.Helper()
|
|
|
|
s := newSuite(t)
|
|
|
|
conn, err := net.Dial("tcp", address)
|
|
|
|
s.noError(err)
|
|
|
|
defer conn.Close()
|
|
|
|
n, err := conn.Write([]byte(data))
|
|
|
|
s.noError(err)
|
|
|
|
s.equalInt(n, len(data))
|
|
|
|
}
|
|
|
|
|
2019-09-27 08:48:53 +02:00
|
|
|
func httpReadMetrics(t *testing.T, address, query string) []Metric {
|
2019-07-08 20:44:41 +02:00
|
|
|
t.Helper()
|
|
|
|
s := newSuite(t)
|
|
|
|
resp, err := http.Get(address + query)
|
|
|
|
s.noError(err)
|
|
|
|
defer resp.Body.Close()
|
|
|
|
s.equalInt(resp.StatusCode, 200)
|
2019-09-27 08:48:53 +02:00
|
|
|
var rows []Metric
|
2019-07-08 20:44:41 +02:00
|
|
|
for dec := json.NewDecoder(resp.Body); dec.More(); {
|
2019-09-27 08:48:53 +02:00
|
|
|
var row Metric
|
2019-07-08 20:44:41 +02:00
|
|
|
s.noError(dec.Decode(&row))
|
|
|
|
rows = append(rows, row)
|
|
|
|
}
|
|
|
|
return rows
|
|
|
|
}
|
2019-09-30 10:25:54 +02:00
|
|
|
func httpReadStruct(t *testing.T, address, query string, dst interface{}) {
|
2019-07-08 20:44:41 +02:00
|
|
|
t.Helper()
|
2019-09-27 08:48:53 +02:00
|
|
|
s := newSuite(t)
|
|
|
|
resp, err := http.Get(address + query)
|
|
|
|
s.noError(err)
|
|
|
|
defer resp.Body.Close()
|
|
|
|
s.equalInt(resp.StatusCode, 200)
|
2019-09-30 10:25:54 +02:00
|
|
|
s.noError(json.NewDecoder(resp.Body).Decode(dst))
|
2019-09-27 08:48:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func checkMetricsResult(t *testing.T, got, want []Metric, query, issue string) {
|
|
|
|
t.Helper()
|
|
|
|
for _, r := range append([]Metric(nil), got...) {
|
|
|
|
want = removeIfFoundMetrics(r, want)
|
|
|
|
}
|
|
|
|
if len(want) > 0 {
|
2019-09-26 11:35:22 +02:00
|
|
|
if issue != "" {
|
|
|
|
issue = "Regression in " + issue
|
|
|
|
}
|
2019-09-27 08:48:53 +02:00
|
|
|
t.Fatalf("query: %s. Result metrics %+v not found in %+v.%s", query, want, got, issue)
|
2019-07-08 20:44:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-27 08:48:53 +02:00
|
|
|
func removeIfFoundMetrics(r Metric, contains []Metric) []Metric {
|
2019-07-08 20:44:41 +02:00
|
|
|
for i, item := range contains {
|
2019-09-08 18:48:38 +02:00
|
|
|
if reflect.DeepEqual(r.Metric, item.Metric) && reflect.DeepEqual(r.Values, item.Values) &&
|
|
|
|
reflect.DeepEqual(r.Timestamps, item.Timestamps) {
|
2019-07-08 20:44:41 +02:00
|
|
|
contains[i] = contains[len(contains)-1]
|
|
|
|
return contains[:len(contains)-1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return contains
|
|
|
|
}
|
|
|
|
|
2019-09-27 08:48:53 +02:00
|
|
|
func checkSeriesResult(t *testing.T, got, want Series, query, issue string) {
|
|
|
|
t.Helper()
|
|
|
|
if got.Status != want.Status {
|
2019-09-30 10:25:54 +02:00
|
|
|
t.Fatalf("query %s. Result Series status mismatch %q - %q. %s", query, want.Status, got.Status, issue)
|
2019-09-27 08:48:53 +02:00
|
|
|
}
|
|
|
|
wantData := append([]map[string]string(nil), want.Data...)
|
|
|
|
for _, r := range got.Data {
|
|
|
|
wantData = removeIfFoundSeries(r, wantData)
|
|
|
|
}
|
|
|
|
if len(wantData) > 0 {
|
|
|
|
if issue != "" {
|
|
|
|
issue = "Regression in " + issue
|
|
|
|
}
|
2019-09-30 10:25:54 +02:00
|
|
|
t.Fatalf("query %s. Result Series %+v not found in %+v.%s", query, wantData, got.Data, issue)
|
2019-09-27 08:48:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func removeIfFoundSeries(r map[string]string, contains []map[string]string) []map[string]string {
|
|
|
|
for i, item := range contains {
|
|
|
|
if reflect.DeepEqual(r, item) {
|
|
|
|
contains[i] = contains[len(contains)-1]
|
|
|
|
return contains[:len(contains)-1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return contains
|
|
|
|
}
|
|
|
|
|
2019-09-30 10:25:54 +02:00
|
|
|
func checkQueryResult(t *testing.T, got, want Query, query, issue string) {
|
|
|
|
t.Helper()
|
|
|
|
if got.Status != want.Status {
|
|
|
|
t.Fatalf("query %s. Result Query status mismatch %q - %q. %s", query, want.Status, got.Status, issue)
|
|
|
|
}
|
|
|
|
if got.Data.ResultType != want.Data.ResultType {
|
|
|
|
t.Fatalf("query %s. Result Query Data ResultType status mismatch %q - %q. %s", query, want.Data.ResultType, got.Data.ResultType, issue)
|
|
|
|
}
|
|
|
|
|
|
|
|
wantData := append([]QueryDataResult(nil), want.Data.Result...)
|
|
|
|
for _, r := range got.Data.Result {
|
|
|
|
wantData = removeIfFoundQueryData(r, wantData)
|
|
|
|
}
|
|
|
|
if len(wantData) > 0 {
|
|
|
|
if issue != "" {
|
|
|
|
issue = "Regression in " + issue
|
|
|
|
}
|
|
|
|
t.Fatalf("query %s. Result query %+v not found in %+v.%s", query, wantData, got.Data.Result, issue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func removeIfFoundQueryData(r QueryDataResult, contains []QueryDataResult) []QueryDataResult {
|
|
|
|
for i, item := range contains {
|
|
|
|
if reflect.DeepEqual(r.Metric, item.Metric) && reflect.DeepEqual(r.Value[0], item.Value[0]) && reflect.DeepEqual(r.Value[1], item.Value[1]) {
|
|
|
|
contains[i] = contains[len(contains)-1]
|
|
|
|
return contains[:len(contains)-1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return contains
|
|
|
|
}
|
|
|
|
|
2019-07-08 20:44:41 +02:00
|
|
|
type suite struct{ t *testing.T }
|
|
|
|
|
|
|
|
func newSuite(t *testing.T) *suite { return &suite{t: t} }
|
|
|
|
|
|
|
|
func (s *suite) noError(err error) {
|
|
|
|
s.t.Helper()
|
|
|
|
if err != nil {
|
|
|
|
s.t.Errorf("unexpected error %v", err)
|
|
|
|
s.t.FailNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *suite) equalInt(a, b int) {
|
|
|
|
s.t.Helper()
|
|
|
|
if a != b {
|
|
|
|
s.t.Errorf("%d not equal %d", a, b)
|
|
|
|
s.t.FailNow()
|
|
|
|
}
|
|
|
|
}
|
2019-09-05 16:55:38 +02:00
|
|
|
|
|
|
|
func (s *suite) greaterThan(a, b int) {
|
|
|
|
s.t.Helper()
|
|
|
|
if a <= b {
|
|
|
|
s.t.Errorf("%d less or equal then %d", a, b)
|
|
|
|
s.t.FailNow()
|
|
|
|
}
|
|
|
|
}
|