testLimiter sends sequence of alerts to limiter, and checks if limiter updated reacted correctly.
(t *testing.T, limits Limits, ops []callbackOp)
| 287 | |
| 288 | // testLimiter sends sequence of alerts to limiter, and checks if limiter updated reacted correctly. |
| 289 | func testLimiter(t *testing.T, limits Limits, ops []callbackOp) { |
| 290 | reg := prometheus.NewPedanticRegistry() |
| 291 | |
| 292 | limiter := newAlertsLimiter("test", limits, reg) |
| 293 | |
| 294 | for ix, op := range ops { |
| 295 | if op.delete { |
| 296 | limiter.PostDelete(op.alert) |
| 297 | } else { |
| 298 | err := limiter.PreStore(op.alert, op.existing) |
| 299 | require.Equal(t, op.expectedInsertError, err, "op %d", ix) |
| 300 | if err == nil { |
| 301 | limiter.PostStore(op.alert, op.existing) |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | count, totalSize := limiter.currentStats() |
| 306 | |
| 307 | assert.Equal(t, op.expectedCount, count, "wrong count, op %d", ix) |
| 308 | assert.Equal(t, op.expectedTotalSize, totalSize, "wrong total size, op %d", ix) |
| 309 | } |
| 310 | } |
no test coverage detected