Search: ordering tests (#54432)

* search ordering tests

* lintt
This commit is contained in:
Artur Wierzbicki 2022-08-30 18:58:19 +02:00 committed by GitHub
parent dc2616f833
commit 9284216880
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 316 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"path/filepath"
"testing"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/infra/log"
@ -82,6 +83,33 @@ func checkSearchResponseExtended(t *testing.T, fileName string, index *orgIndex,
experimental.CheckGoldenJSONResponse(t, "testdata", fileName, resp, true)
}
func getFrameWithNames(resp *backend.DataResponse) *data.Frame {
if resp == nil || len(resp.Frames) == 0 {
return nil
}
frame := resp.Frames[0]
nameField, idx := frame.FieldByName(documentFieldName)
if nameField.Len() == 0 || idx == -1 {
return nil
}
scoreField, _ := frame.FieldByName("score")
return data.NewFrame("ordering frame", nameField, scoreField)
}
func checkSearchResponseOrdering(t *testing.T, fileName string, index *orgIndex, filter ResourceFilter, query DashboardQuery) {
t.Helper()
checkSearchResponseOrderingExtended(t, fileName, index, filter, query, &NoopQueryExtender{})
}
func checkSearchResponseOrderingExtended(t *testing.T, fileName string, index *orgIndex, filter ResourceFilter, query DashboardQuery, extender QueryExtender) {
t.Helper()
query.Explain = true
resp := doSearchQuery(context.Background(), testLogger, index, filter, query, extender, "/pfix")
experimental.CheckGoldenJSONFrame(t, "testdata", fileName, getFrameWithNames(resp), true)
}
var testDashboards = []dashboard{
{
id: 1,
@ -582,3 +610,87 @@ func TestDashboardIndex_CamelCaseNgram(t *testing.T) {
)
})
}
func dashboardsWithTitles(names ...string) []dashboard {
out := make([]dashboard, 0)
for i, name := range names {
no := int64(i + 1)
out = append(out, dashboard{
id: no,
uid: fmt.Sprintf("%d", no),
info: &extract.DashboardInfo{
Title: name,
},
})
}
return out
}
func TestDashboardIndex_MultiTermPrefixMatch(t *testing.T) {
var tests = []struct {
dashboards []dashboard
query string
}{
{
dashboards: dashboardsWithTitles(
"Panel Tests - Bar Gauge 2",
"Prometheus 2.0",
"Prometheus 2.0 Stats",
"Prometheus 20.0",
"Prometheus Second Word",
"Prometheus Stats",
"dynamic (2)",
"prometheus histogram",
"prometheus histogram2",
"roci-simple-2",
"x not y",
),
query: "Prometheus 2.",
},
{
dashboards: dashboardsWithTitles(
"From AAA",
"Grafana Dev Overview & Home",
"Home automation",
"Prometheus 2.0",
"Prometheus 2.0 Stats",
"Prometheus 20.0",
"Prometheus Stats",
"Transforms - config from query",
"iot-testing",
"prom style with exemplars",
"prop history",
"simple frame",
"with-hide-from",
"xy broke",
),
query: "Prome",
},
{
dashboards: dashboardsWithTitles(
"Panel Tests - Bar Gauge 2",
"Prometheus 2.0",
"Prometheus 2.0 Stats",
"Prometheus 20.0",
"Prometheus Second Word",
"Prometheus Stats",
"dynamic (2)",
"prometheus histogram",
"prometheus histogram2",
"roci-simple-2",
"x not y",
),
query: "Prometheus stat",
},
}
for i, tt := range tests {
t.Run(fmt.Sprintf("ordering-tests-%d-[%s]", i+1, tt.query), func(t *testing.T) {
index := initTestOrgIndexFromDashes(t, tt.dashboards)
checkSearchResponseOrdering(t, filepath.Base(t.Name()), index, testAllowAllFilter,
DashboardQuery{Query: tt.query},
)
})
}
}

View File

@ -0,0 +1,77 @@
// 🌟 This was machine generated. Do not edit. 🌟
//
// Frame[0]
// Name: ordering frame
// Dimensions: 2 Fields by 10 Rows
// +---------------------------+--------------------+
// | Name: name | Name: score |
// | Labels: | Labels: |
// | Type: []string | Type: []float64 |
// +---------------------------+--------------------+
// | dynamic (2) | 61.26983678470653 |
// | roci-simple-2 | 52.417145624935095 |
// | Prometheus 2.0 | 45.193422538475374 |
// | Prometheus 20.0 | 45.193422538475374 |
// | Prometheus Stats | 45.193422538475374 |
// | prometheus histogram | 45.193422538475374 |
// | prometheus histogram2 | 45.193422538475374 |
// | Panel Tests - Bar Gauge 2 | 40.74215154954845 |
// | Prometheus 2.0 Stats | 38.70210379766075 |
// | Prometheus Second Word | 38.70210379766075 |
// +---------------------------+--------------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
{
"frames": [
{
"schema": {
"name": "ordering frame",
"fields": [
{
"name": "name",
"type": "string",
"typeInfo": {
"frame": "string"
}
},
{
"name": "score",
"type": "number",
"typeInfo": {
"frame": "float64"
}
}
]
},
"data": {
"values": [
[
"dynamic (2)",
"roci-simple-2",
"Prometheus 2.0",
"Prometheus 20.0",
"Prometheus Stats",
"prometheus histogram",
"prometheus histogram2",
"Panel Tests - Bar Gauge 2",
"Prometheus 2.0 Stats",
"Prometheus Second Word"
],
[
61.26983678470653,
52.417145624935095,
45.193422538475374,
45.193422538475374,
45.193422538475374,
45.193422538475374,
45.193422538475374,
40.74215154954845,
38.70210379766075,
38.70210379766075
]
]
}
}
]
}

View File

@ -0,0 +1,59 @@
// 🌟 This was machine generated. Do not edit. 🌟
//
// Frame[0]
// Name: ordering frame
// Dimensions: 2 Fields by 4 Rows
// +----------------------+--------------------+
// | Name: name | Name: score |
// | Labels: | Labels: |
// | Type: []string | Type: []float64 |
// +----------------------+--------------------+
// | Prometheus 2.0 | 2.861163199700355 |
// | Prometheus 20.0 | 2.795309067950216 |
// | Prometheus Stats | 2.6766576425310045 |
// | Prometheus 2.0 Stats | 2.5727172425512226 |
// +----------------------+--------------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
{
"frames": [
{
"schema": {
"name": "ordering frame",
"fields": [
{
"name": "name",
"type": "string",
"typeInfo": {
"frame": "string"
}
},
{
"name": "score",
"type": "number",
"typeInfo": {
"frame": "float64"
}
}
]
},
"data": {
"values": [
[
"Prometheus 2.0",
"Prometheus 20.0",
"Prometheus Stats",
"Prometheus 2.0 Stats"
],
[
2.861163199700355,
2.795309067950216,
2.6766576425310045,
2.5727172425512226
]
]
}
}
]
}

View File

@ -0,0 +1,68 @@
// 🌟 This was machine generated. Do not edit. 🌟
//
// Frame[0]
// Name: ordering frame
// Dimensions: 2 Fields by 7 Rows
// +------------------------+--------------------+
// | Name: name | Name: score |
// | Labels: | Labels: |
// | Type: []string | Type: []float64 |
// +------------------------+--------------------+
// | Prometheus 2.0 | 45.193422538475374 |
// | Prometheus 20.0 | 45.193422538475374 |
// | Prometheus Stats | 45.193422538475374 |
// | prometheus histogram | 45.193422538475374 |
// | prometheus histogram2 | 45.193422538475374 |
// | Prometheus 2.0 Stats | 38.70210379766075 |
// | Prometheus Second Word | 38.70210379766075 |
// +------------------------+--------------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
{
"frames": [
{
"schema": {
"name": "ordering frame",
"fields": [
{
"name": "name",
"type": "string",
"typeInfo": {
"frame": "string"
}
},
{
"name": "score",
"type": "number",
"typeInfo": {
"frame": "float64"
}
}
]
},
"data": {
"values": [
[
"Prometheus 2.0",
"Prometheus 20.0",
"Prometheus Stats",
"prometheus histogram",
"prometheus histogram2",
"Prometheus 2.0 Stats",
"Prometheus Second Word"
],
[
45.193422538475374,
45.193422538475374,
45.193422538475374,
45.193422538475374,
45.193422538475374,
38.70210379766075,
38.70210379766075
]
]
}
}
]
}