Browse Source

Set test group interval default to evaluation interval (#13011)

Signed-off-by: Rens Groothuijsen <l.groothuijsen@alumni.maastrichtuniversity.nl>
pull/13014/head
Rens Groothuijsen 1 year ago committed by GitHub
parent
commit
122f9506e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      cmd/promtool/testdata/no-test-group-interval.yml
  2. 3
      cmd/promtool/unittest.go
  3. 10
      cmd/promtool/unittest_test.go
  4. 2
      docs/configuration/unit_testing_rules.md

15
cmd/promtool/testdata/no-test-group-interval.yml vendored

@ -0,0 +1,15 @@
tests:
- input_series:
- series: test
values: 0 1
promql_expr_test:
- expr: test
eval_time: 59s
exp_samples:
- value: 0
labels: test
- expr: test
eval_time: 1m
exp_samples:
- value: 1
labels: test

3
cmd/promtool/unittest.go

@ -96,6 +96,9 @@ func ruleUnitTest(filename string, queryOpts promql.LazyLoaderOpts) []error {
// Testing.
var errs []error
for _, t := range unitTestInp.Tests {
if t.Interval == 0 {
t.Interval = unitTestInp.EvaluationInterval
}
ers := t.test(evalInterval, groupOrderMap, queryOpts, unitTestInp.RuleFiles...)
if ers != nil {
errs = append(errs, ers...)

10
cmd/promtool/unittest_test.go

@ -112,6 +112,16 @@ func TestRulesUnitTest(t *testing.T) {
},
want: 0,
},
{
name: "No test group interval",
args: args{
files: []string{"./testdata/no-test-group-interval.yml"},
},
queryOpts: promql.LazyLoaderOpts{
EnableNegativeOffset: true,
},
want: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

2
docs/configuration/unit_testing_rules.md

@ -39,7 +39,7 @@ tests:
``` yaml
# Series data
interval: <duration>
[ interval: <duration> | default = evaluation_interval ]
input_series:
[ - <series> ]

Loading…
Cancel
Save