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>
This commit is contained in:
Bryan Boreham 2018-06-22 15:21:04 +01:00 committed by Brian Brazil
parent a6dace8829
commit 2bd510a63e
2 changed files with 9 additions and 2 deletions

View File

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

View File

@ -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 {