diff --git a/cmd/promtool/testdata/no-test-group-interval.yml b/cmd/promtool/testdata/no-test-group-interval.yml new file mode 100644 index 000000000..d1f6935cd --- /dev/null +++ b/cmd/promtool/testdata/no-test-group-interval.yml @@ -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 \ No newline at end of file diff --git a/cmd/promtool/unittest.go b/cmd/promtool/unittest.go index 5bec5c60b..d37e03e52 100644 --- a/cmd/promtool/unittest.go +++ b/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...) diff --git a/cmd/promtool/unittest_test.go b/cmd/promtool/unittest_test.go index 1e0244054..c96883113 100644 --- a/cmd/promtool/unittest_test.go +++ b/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) { diff --git a/docs/configuration/unit_testing_rules.md b/docs/configuration/unit_testing_rules.md index c583ecfda..163fcb91f 100644 --- a/docs/configuration/unit_testing_rules.md +++ b/docs/configuration/unit_testing_rules.md @@ -39,7 +39,7 @@ tests: ``` yaml # Series data -interval: +[ interval: | default = evaluation_interval ] input_series: [ - ]