@@ -127,10 +127,63 @@ func TestRuler_rules_special_characters(t *testing.T) {
127
127
},
128
128
},
129
129
})
130
-
131
130
require .Equal (t , string (expectedResponse ), string (body ))
132
131
}
133
132
133
+ func TestRuler_rules_limit (t * testing.T ) {
134
+ store := newMockRuleStore (mockRulesLimit )
135
+ cfg := defaultRulerConfig (t )
136
+
137
+ r := newTestRuler (t , cfg , store , nil )
138
+ defer services .StopAndAwaitTerminated (context .Background (), r ) //nolint:errcheck
139
+
140
+ a := NewAPI (r , r .store , log .NewNopLogger ())
141
+
142
+ req := requestFor (t , http .MethodGet , "https://localhost:8080/api/prom/api/v1/rules" , nil , "user1" )
143
+ w := httptest .NewRecorder ()
144
+ a .PrometheusRules (w , req )
145
+
146
+ resp := w .Result ()
147
+ body , _ := io .ReadAll (resp .Body )
148
+ // Check status code and status response
149
+ responseJSON := response {}
150
+ err := json .Unmarshal (body , & responseJSON )
151
+ require .NoError (t , err )
152
+ require .Equal (t , http .StatusOK , resp .StatusCode )
153
+ require .Equal (t , responseJSON .Status , "success" )
154
+
155
+ // Testing the running rules for user1 in the mock store
156
+ expectedResponse , _ := json .Marshal (response {
157
+ Status : "success" ,
158
+ Data : & RuleDiscovery {
159
+ RuleGroups : []* RuleGroup {
160
+ {
161
+ Name : "group1" ,
162
+ File : "namespace1" ,
163
+ Limit : 5 ,
164
+ Rules : []rule {
165
+ & recordingRule {
166
+ Name : "UP_RULE" ,
167
+ Query : "up" ,
168
+ Health : "unknown" ,
169
+ Type : "recording" ,
170
+ },
171
+ & alertingRule {
172
+ Name : "UP_ALERT" ,
173
+ Query : "up < 1" ,
174
+ State : "inactive" ,
175
+ Health : "unknown" ,
176
+ Type : "alerting" ,
177
+ Alerts : []* Alert {},
178
+ },
179
+ },
180
+ Interval : 60 ,
181
+ },
182
+ },
183
+ },
184
+ })
185
+ require .Equal (t , string (expectedResponse ), string (body ))
186
+ }
134
187
func TestRuler_alerts (t * testing.T ) {
135
188
store := newMockRuleStore (mockRules )
136
189
cfg := defaultRulerConfig (t )
0 commit comments