labels: test Compare without knowing the exact result

Only the sign of the result is important

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2022-06-26 18:11:40 +01:00 committed by Julien Pivotto
parent a6c6155092
commit fb2d883f1e
1 changed files with 11 additions and 1 deletions

View File

@ -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)
}
}