diff --git a/model/rulefmt/rulefmt_test.go b/model/rulefmt/rulefmt_test.go index d79ee94e2..d6499538e 100644 --- a/model/rulefmt/rulefmt_test.go +++ b/model/rulefmt/rulefmt_test.go @@ -73,12 +73,21 @@ func TestParseFileFailure(t *testing.T) { filename: "invalid_label_name.bad.yaml", errMsg: "invalid label name", }, + { + filename: "record_and_for.bad.yaml", + errMsg: "invalid field 'for' in recording rule", + }, + { + filename: "record_and_keep_firing_for.bad.yaml", + errMsg: "invalid field 'keep_firing_for' in recording rule", + }, } for _, c := range table { _, errs := ParseFile(filepath.Join("testdata", c.filename)) require.NotNil(t, errs, "Expected error parsing %s but got none", c.filename) - require.Error(t, errs[0], c.errMsg, "Expected error for %s.", c.filename) + require.Error(t, errs[0]) + require.Containsf(t, errs[0].Error(), c.errMsg, "Expected error for %s.", c.filename) } } diff --git a/model/rulefmt/testdata/record_and_for.bad.yaml b/model/rulefmt/testdata/record_and_for.bad.yaml new file mode 100644 index 000000000..a15d428a0 --- /dev/null +++ b/model/rulefmt/testdata/record_and_for.bad.yaml @@ -0,0 +1,6 @@ +groups: + - name: yolo + rules: + - record: Hello + expr: 1 + for: 1m diff --git a/model/rulefmt/testdata/record_and_keep_firing_for.bad.yaml b/model/rulefmt/testdata/record_and_keep_firing_for.bad.yaml new file mode 100644 index 000000000..eb8192f05 --- /dev/null +++ b/model/rulefmt/testdata/record_and_keep_firing_for.bad.yaml @@ -0,0 +1,6 @@ +groups: + - name: yolo + rules: + - record: Hello + expr: 1 + keep_firing_for: 1m