|
1 | 1 | // SPDX-License-Identifier: AGPL-3.0-only
|
2 | 2 |
|
3 |
| -package ast |
| 3 | +package ast_test |
4 | 4 |
|
5 | 5 | import (
|
6 | 6 | "context"
|
7 | 7 | "fmt"
|
8 | 8 | "testing"
|
9 | 9 | "time"
|
10 | 10 |
|
| 11 | + "github.com/grafana/mimir/pkg/streamingpromql/optimize" |
| 12 | + "github.com/grafana/mimir/pkg/streamingpromql/optimize/ast" |
| 13 | + "github.com/prometheus/client_golang/prometheus" |
11 | 14 | "github.com/prometheus/prometheus/model/labels"
|
12 | 15 | "github.com/prometheus/prometheus/promql/parser"
|
13 | 16 | "github.com/prometheus/prometheus/promql/parser/posrange"
|
@@ -56,15 +59,15 @@ func TestSortLabelsAndMatchers_AggregateAndBinaryExpressions(t *testing.T) {
|
56 | 59 | "2": "2",
|
57 | 60 | }
|
58 | 61 |
|
59 |
| - sortLabelsAndMatchers := &SortLabelsAndMatchers{} |
| 62 | + ctx := context.Background() |
| 63 | + sortLabelsAndMatchers := &ast.SortLabelsAndMatchers{} |
60 | 64 |
|
61 | 65 | for input, expected := range testCases {
|
62 | 66 | t.Run(input, func(t *testing.T) {
|
63 |
| - expr, err := parser.ParseExpr(input) |
64 |
| - require.NoError(t, err) |
| 67 | + _, _, result := getOutputFromASTOptimizationPassWithQueryPlan(t, ctx, input, func(prometheus.Registerer) optimize.ASTOptimizationPass { |
| 68 | + return sortLabelsAndMatchers |
| 69 | + }) |
65 | 70 |
|
66 |
| - result, err := sortLabelsAndMatchers.Apply(context.Background(), expr) |
67 |
| - require.NoError(t, err) |
68 | 71 | require.Equal(t, expected, result.String())
|
69 | 72 | })
|
70 | 73 | }
|
@@ -154,14 +157,13 @@ func TestSortLabelsAndMatchers_Selectors(t *testing.T) {
|
154 | 157 | },
|
155 | 158 | }
|
156 | 159 |
|
157 |
| - sortLabelsAndMatchers := &SortLabelsAndMatchers{} |
| 160 | + ctx := context.Background() |
| 161 | + sortLabelsAndMatchers := &ast.SortLabelsAndMatchers{} |
158 | 162 |
|
159 | 163 | run := func(t *testing.T, input string, expected parser.Expr) {
|
160 |
| - expr, err := parser.ParseExpr(input) |
161 |
| - require.NoError(t, err) |
162 |
| - |
163 |
| - result, err := sortLabelsAndMatchers.Apply(context.Background(), expr) |
164 |
| - require.NoError(t, err) |
| 164 | + _, _, result := getOutputFromASTOptimizationPassWithQueryPlan(t, ctx, input, func(prometheus.Registerer) optimize.ASTOptimizationPass { |
| 165 | + return sortLabelsAndMatchers |
| 166 | + }) |
165 | 167 |
|
166 | 168 | // Compare the expected and result expressions formatted as strings for clearer diffs.
|
167 | 169 | // Note that we can't use the VectorSelector and MatrixSelector String() methods because these
|
|
0 commit comments