(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestSubQueryStepSizeCheck(t *testing.T) { |
| 13 | t.Parallel() |
| 14 | for _, tc := range []struct { |
| 15 | name string |
| 16 | query string |
| 17 | defaultStep time.Duration |
| 18 | err error |
| 19 | maxStep int64 |
| 20 | }{ |
| 21 | { |
| 22 | name: "invalid query", |
| 23 | query: "sum(up", |
| 24 | }, |
| 25 | { |
| 26 | name: "no subquery", |
| 27 | query: "up", |
| 28 | }, |
| 29 | { |
| 30 | name: "valid subquery and within step limit", |
| 31 | query: "up[60m:1m]", |
| 32 | maxStep: 100, |
| 33 | }, |
| 34 | { |
| 35 | name: "valid subquery, not within step limit", |
| 36 | query: "up[60m:1m]", |
| 37 | maxStep: 10, |
| 38 | err: httpgrpc.Errorf(http.StatusBadRequest, ErrSubQueryStepTooSmall, 10), |
| 39 | }, |
| 40 | { |
| 41 | name: "subquery with no step size defined, use default step and pass", |
| 42 | query: "up[60m:]", |
| 43 | maxStep: 100, |
| 44 | defaultStep: time.Minute, |
| 45 | }, |
| 46 | { |
| 47 | name: "subquery with no step size defined, use default step and fail", |
| 48 | query: "up[60m:]", |
| 49 | maxStep: 100, |
| 50 | defaultStep: time.Second, |
| 51 | err: httpgrpc.Errorf(http.StatusBadRequest, ErrSubQueryStepTooSmall, 100), |
| 52 | }, |
| 53 | { |
| 54 | name: "two subqueries within functions, one exceeds the limit while another is not", |
| 55 | query: "sum_over_time(up[60m:]) + avg_over_time(test[5m:1m])", |
| 56 | maxStep: 10, |
| 57 | defaultStep: time.Second, |
| 58 | err: httpgrpc.Errorf(http.StatusBadRequest, ErrSubQueryStepTooSmall, 10), |
| 59 | }, |
| 60 | { |
| 61 | name: "two subqueries within functions, all within the limit", |
| 62 | query: "sum_over_time(up[60m:]) + avg_over_time(test[5m:1m])", |
| 63 | maxStep: 100, |
| 64 | defaultStep: time.Minute, |
| 65 | }, |
| 66 | } { |
| 67 | t.Run(tc.name, func(t *testing.T) { |
| 68 | err := SubQueryStepSizeCheck(tc.query, tc.defaultStep, tc.maxStep) |
| 69 | require.Equal(t, tc.err, err) |
nothing calls this directly
no test coverage detected