From f7cd18abdff888239e1fe321e41e05f3452715ef Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Tue, 5 Aug 2014 20:14:04 +0200 Subject: [PATCH] Add more topk() / bottomk() tests. Test what happens if k > number of input elements. Change-Id: Ie724b850939e297ebf085f0a5a3522e9cfcc6534 --- rules/rules_test.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/rules/rules_test.go b/rules/rules_test.go index aeed1e32e..a6c793c46 100644 --- a/rules/rules_test.go +++ b/rules/rules_test.go @@ -333,6 +333,15 @@ func TestExpressions(t *testing.T) { checkOrder: true, fullRanges: 0, intervalRanges: 8, + }, { + expr: `topk(5, http_requests{group="canary",job="app-server"})`, + output: []string{ + `http_requests{group="canary", instance="1", job="app-server"} => 800 @[%v]`, + `http_requests{group="canary", instance="0", job="app-server"} => 700 @[%v]`, + }, + checkOrder: true, + fullRanges: 0, + intervalRanges: 2, }, { expr: `bottomk(3, http_requests)`, output: []string{ @@ -343,6 +352,15 @@ func TestExpressions(t *testing.T) { checkOrder: true, fullRanges: 0, intervalRanges: 8, + }, { + expr: `bottomk(5, http_requests{group="canary",job="app-server"})`, + output: []string{ + `http_requests{group="canary", instance="0", job="app-server"} => 700 @[%v]`, + `http_requests{group="canary", instance="1", job="app-server"} => 800 @[%v]`, + }, + checkOrder: true, + fullRanges: 0, + intervalRanges: 2, }, { // Single-letter label names and values. expr: `x{y="testvalue"}`, @@ -409,11 +427,11 @@ func TestExpressions(t *testing.T) { fullRanges: 0, intervalRanges: 0, }, { - // Empty expressions shouldn"t parse. + // Empty expressions shouldn't parse. expr: ``, shouldFail: true, }, { - // Interval durations can"t be in quotes. + // Interval durations can't be in quotes. expr: `http_requests["1m"]`, shouldFail: true, }, {