From 2bd510a63e48ac6bf4971d62199bdb1045c93f1a Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 22 Jun 2018 15:21:04 +0100 Subject: [PATCH] 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 --- rules/fixtures/rules.yaml | 5 +++++ rules/manager_test.go | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 rules/fixtures/rules.yaml diff --git a/rules/fixtures/rules.yaml b/rules/fixtures/rules.yaml new file mode 100644 index 000000000..bd4cb228a --- /dev/null +++ b/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])) diff --git a/rules/manager_test.go b/rules/manager_test.go index 4ffb5373e..7916ad5ee 100644 --- a/rules/manager_test.go +++ b/rules/manager_test.go @@ -287,6 +287,7 @@ func TestCopyState(t *testing.T) { } func TestUpdate(t *testing.T) { + files := []string{"fixtures/rules.yaml"} expected := map[string]labels.Labels{ "test": labels.FromStrings("name", "value"), } @@ -296,15 +297,16 @@ func TestUpdate(t *testing.T) { }) ruleManager.Run() - err := ruleManager.Update(0, nil) + err := ruleManager.Update(10*time.Second, files) testutil.Ok(t, err) + testutil.Assert(t, len(ruleManager.groups) > 0, "expected non-empty rule groups") for _, g := range ruleManager.groups { g.seriesInPreviousEval = []map[string]labels.Labels{ expected, } } - err = ruleManager.Update(0, nil) + err = ruleManager.Update(10*time.Second, files) testutil.Ok(t, err) for _, g := range ruleManager.groups { for _, actual := range g.seriesInPreviousEval {