Add rulefmt tests

Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>
pull/11827/head
Julien Pivotto 2 years ago
parent 5ad74e6e71
commit 8e500dbd39

@ -73,12 +73,21 @@ func TestParseFileFailure(t *testing.T) {
filename: "invalid_label_name.bad.yaml", filename: "invalid_label_name.bad.yaml",
errMsg: "invalid label name", 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 { for _, c := range table {
_, errs := ParseFile(filepath.Join("testdata", c.filename)) _, errs := ParseFile(filepath.Join("testdata", c.filename))
require.NotNil(t, errs, "Expected error parsing %s but got none", 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)
} }
} }

@ -0,0 +1,6 @@
groups:
- name: yolo
rules:
- record: Hello
expr: 1
for: 1m

@ -0,0 +1,6 @@
groups:
- name: yolo
rules:
- record: Hello
expr: 1
keep_firing_for: 1m
Loading…
Cancel
Save