Browse Source

Make TestUpdate() do some work (#4306)

Previously it would set no preconditions and check no postconditions,
as the `groups` member was empty.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
pull/4195/head^2
Bryan Boreham 7 years ago committed by Brian Brazil
parent
commit
2bd510a63e
  1. 5
      rules/fixtures/rules.yaml
  2. 6
      rules/manager_test.go

5
rules/fixtures/rules.yaml

@ -0,0 +1,5 @@
groups:
- name: test
rules:
- record: job:http_requests:rate5m
expr: sum by (job)(rate(http_requests_total[5m]))

6
rules/manager_test.go

@ -287,6 +287,7 @@ func TestCopyState(t *testing.T) {
} }
func TestUpdate(t *testing.T) { func TestUpdate(t *testing.T) {
files := []string{"fixtures/rules.yaml"}
expected := map[string]labels.Labels{ expected := map[string]labels.Labels{
"test": labels.FromStrings("name", "value"), "test": labels.FromStrings("name", "value"),
} }
@ -296,15 +297,16 @@ func TestUpdate(t *testing.T) {
}) })
ruleManager.Run() ruleManager.Run()
err := ruleManager.Update(0, nil) err := ruleManager.Update(10*time.Second, files)
testutil.Ok(t, err) testutil.Ok(t, err)
testutil.Assert(t, len(ruleManager.groups) > 0, "expected non-empty rule groups")
for _, g := range ruleManager.groups { for _, g := range ruleManager.groups {
g.seriesInPreviousEval = []map[string]labels.Labels{ g.seriesInPreviousEval = []map[string]labels.Labels{
expected, expected,
} }
} }
err = ruleManager.Update(0, nil) err = ruleManager.Update(10*time.Second, files)
testutil.Ok(t, err) testutil.Ok(t, err)
for _, g := range ruleManager.groups { for _, g := range ruleManager.groups {
for _, actual := range g.seriesInPreviousEval { for _, actual := range g.seriesInPreviousEval {

Loading…
Cancel
Save