From 7d30ccd0eb84addd1ea64e4bc9829b251bd57c0b Mon Sep 17 00:00:00 2001 From: Ganesh Vernekar Date: Mon, 31 Dec 2018 16:25:49 +0530 Subject: [PATCH] Sort samples before comparing - PromQL unit test (#5052) Signed-off-by: Ganesh Vernekar --- cmd/promtool/unittest.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/promtool/unittest.go b/cmd/promtool/unittest.go index 5796c5f5a..4b49922aa 100644 --- a/cmd/promtool/unittest.go +++ b/cmd/promtool/unittest.go @@ -311,6 +311,12 @@ Outer: }) } + sort.Slice(expSamples, func(i, j int) bool { + return labels.Compare(expSamples[i].Labels, expSamples[j].Labels) <= 0 + }) + sort.Slice(gotSamples, func(i, j int) bool { + return labels.Compare(gotSamples[i].Labels, gotSamples[j].Labels) <= 0 + }) if !reflect.DeepEqual(expSamples, gotSamples) { errs = append(errs, fmt.Errorf(" expr:'%s', time:%s, \n exp:%#v, \n got:%#v", testCase.Expr, testCase.EvalTime.String(), parsedSamplesString(expSamples), parsedSamplesString(gotSamples)))