From f489ca98b531b537fbda64f911ddcf58883b2ca6 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Fri, 24 Nov 2023 16:27:38 +0200 Subject: [PATCH] Reproducible output from expression matching Fix flakyness of unit tests by adding back the sorting of matched feature elements that was unadvisedly removed in 63c22551df210143c8297f96c65afbafbea8f049. This might help debugging some corner cases in real-life scenarios (when using templating), too. --- pkg/apis/nfd/v1alpha1/expression.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/apis/nfd/v1alpha1/expression.go b/pkg/apis/nfd/v1alpha1/expression.go index 1d997efc0..ed16dc816 100644 --- a/pkg/apis/nfd/v1alpha1/expression.go +++ b/pkg/apis/nfd/v1alpha1/expression.go @@ -308,6 +308,8 @@ func (m *MatchExpressionSet) MatchGetKeys(keys map[string]Nil) (bool, []MatchedE } ret = append(ret, MatchedElement{"Name": n}) } + // Sort for reproducible output + sort.Slice(ret, func(i, j int) bool { return ret[i]["Name"] < ret[j]["Name"] }) return true, ret, nil } @@ -333,6 +335,8 @@ func (m *MatchExpressionSet) MatchGetValues(values map[string]string) (bool, []M } ret = append(ret, MatchedElement{"Name": n, "Value": values[n]}) } + // Sort for reproducible output + sort.Slice(ret, func(i, j int) bool { return ret[i]["Name"] < ret[j]["Name"] }) return true, ret, nil }