Skip to content

Commit 4c3a1f9

Browse files
committed
test: update tests for custom rule_group interval
This updates tests include `interval`'s and also includes a test to make sure the rules render correctly when interval is not included.
1 parent 3bba809 commit 4c3a1f9

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

internal/prometheus/storage_test.go

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestIOWriterGroupedRulesYAMLRepoStore(t *testing.T) {
3333
"Having a single SLI recording rule should render correctly.": {
3434
slos: []prometheus.StorageSLO{
3535
{
36-
SLO: prometheus.SLO{ID: "test1"},
36+
SLO: prometheus.SLO{ID: "test1", RuleGroupInterval: "2m"},
3737
Rules: prometheus.SLORules{
3838
SLIErrorRecRules: []rulefmt.Rule{
3939
{
@@ -52,6 +52,7 @@ func TestIOWriterGroupedRulesYAMLRepoStore(t *testing.T) {
5252
5353
groups:
5454
- name: sloth-slo-sli-recordings-test1
55+
interval: 2m
5556
rules:
5657
- record: test:record
5758
expr: test-expr
@@ -91,7 +92,7 @@ groups:
9192
"Having a single SLO alert rule should render correctly.": {
9293
slos: []prometheus.StorageSLO{
9394
{
94-
SLO: prometheus.SLO{ID: "test1"},
95+
SLO: prometheus.SLO{ID: "test1", RuleGroupInterval: "2m"},
9596
Rules: prometheus.SLORules{
9697
AlertRules: []rulefmt.Rule{
9798
{
@@ -111,6 +112,7 @@ groups:
111112
112113
groups:
113114
- name: sloth-slo-alerts-test1
115+
interval: 2m
114116
rules:
115117
- alert: testAlert
116118
expr: test-expr
@@ -120,11 +122,40 @@ groups:
120122
test-annot: one
121123
`,
122124
},
125+
"Having a single a blank or empty rule_group interval render correctly.": {
126+
slos: []prometheus.StorageSLO{
127+
{
128+
SLO: prometheus.SLO{ID: "test1", RuleGroupInterval: ""},
129+
Rules: prometheus.SLORules{
130+
SLIErrorRecRules: []rulefmt.Rule{
131+
{
132+
Record: "test:record",
133+
Expr: "test-expr",
134+
Labels: map[string]string{"test-label": "one"},
135+
},
136+
},
137+
},
138+
},
139+
},
140+
expYAML: `
141+
---
142+
# Code generated by Sloth (dev): https://github.com/slok/sloth.
143+
# DO NOT EDIT.
144+
145+
groups:
146+
- name: sloth-slo-sli-recordings-test1
147+
rules:
148+
- record: test:record
149+
expr: test-expr
150+
labels:
151+
test-label: one
152+
`,
153+
},
123154

124155
"Having a multiple SLO alert and recording rules should render correctly.": {
125156
slos: []prometheus.StorageSLO{
126157
{
127-
SLO: prometheus.SLO{ID: "testa"},
158+
SLO: prometheus.SLO{ID: "testa", RuleGroupInterval: "3m"},
128159
Rules: prometheus.SLORules{
129160
SLIErrorRecRules: []rulefmt.Rule{
130161
{
@@ -167,7 +198,7 @@ groups:
167198
},
168199
},
169200
{
170-
SLO: prometheus.SLO{ID: "testb"},
201+
SLO: prometheus.SLO{ID: "testb", RuleGroupInterval: "1h"},
171202
Rules: prometheus.SLORules{
172203
SLIErrorRecRules: []rulefmt.Rule{
173204
{
@@ -201,6 +232,7 @@ groups:
201232
202233
groups:
203234
- name: sloth-slo-sli-recordings-testa
235+
interval: 3m
204236
rules:
205237
- record: test:record-a1
206238
expr: test-expr-a1
@@ -211,6 +243,7 @@ groups:
211243
labels:
212244
test-label: a-2
213245
- name: sloth-slo-meta-recordings-testa
246+
interval: 3m
214247
rules:
215248
- record: test:record-a3
216249
expr: test-expr-a3
@@ -221,6 +254,7 @@ groups:
221254
labels:
222255
test-label: a-4
223256
- name: sloth-slo-alerts-testa
257+
interval: 3m
224258
rules:
225259
- alert: testAlertA1
226260
expr: test-expr-a1
@@ -235,18 +269,21 @@ groups:
235269
annotations:
236270
test-annot: a-2
237271
- name: sloth-slo-sli-recordings-testb
272+
interval: 1h
238273
rules:
239274
- record: test:record-b1
240275
expr: test-expr-b1
241276
labels:
242277
test-label: b-1
243278
- name: sloth-slo-meta-recordings-testb
279+
interval: 1h
244280
rules:
245281
- record: test:record-b2
246282
expr: test-expr-b2
247283
labels:
248284
test-label: b-2
249285
- name: sloth-slo-alerts-testb
286+
interval: 1h
250287
rules:
251288
- alert: testAlertB1
252289
expr: test-expr-b1

0 commit comments

Comments
 (0)