From fb2d883f1ee17041b1d903da496affc93f29684a Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 26 Jun 2022 18:11:40 +0100 Subject: [PATCH] labels: test Compare without knowing the exact result Only the sign of the result is important Signed-off-by: Bryan Boreham --- model/labels/labels_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/model/labels/labels_test.go b/model/labels/labels_test.go index 5d5fdd475..0b1f07c22 100644 --- a/model/labels/labels_test.go +++ b/model/labels/labels_test.go @@ -503,9 +503,19 @@ func TestLabels_Compare(t *testing.T) { }, } + sign := func(a int) int { + switch { + case a < 0: + return -1 + case a > 0: + return 1 + } + return 0 + } + for i, test := range tests { got := Compare(labels, test.compared) - require.Equal(t, test.expected, got, "unexpected comparison result for test case %d", i) + require.Equal(t, sign(test.expected), sign(got), "unexpected comparison result for test case %d", i) } }