From fb8bbe91d7fd3a3036ae1e09db47ea2291fff30a Mon Sep 17 00:00:00 2001 From: Archit Bansal Date: Thu, 18 Feb 2021 17:45:53 -0800 Subject: [PATCH] Fix for flaky unit test in health checker The unit test was dependent on the order of map iteration. Changed to using sorted keys while iterating. --- pkg/healthchecker/types/types.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/healthchecker/types/types.go b/pkg/healthchecker/types/types.go index 5666c758..fac9913c 100644 --- a/pkg/healthchecker/types/types.go +++ b/pkg/healthchecker/types/types.go @@ -18,6 +18,7 @@ package types import ( "fmt" + "sort" "strconv" "strings" "time" @@ -54,13 +55,19 @@ type LogPatternFlag struct { } // String implements the String function for flag.Value interface +// Returns a space separated sorted by keys string of map values. func (lpf *LogPatternFlag) String() string { result := "" - for k, v := range lpf.logPatternCountMap { + var keys []string + for k := range lpf.logPatternCountMap { + keys = append(keys, k) + } + sort.Strings(keys) + for _, k := range keys { if result != "" { result += " " } - result += fmt.Sprintf("%v:%v", k, v) + result += fmt.Sprintf("%v:%v", k, lpf.logPatternCountMap[k]) } return result }