Skip to content

Commit fb8bbe9

Browse files
committed
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.
1 parent 100f2bf commit fb8bbe9

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pkg/healthchecker/types/types.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package types
1818

1919
import (
2020
"fmt"
21+
"sort"
2122
"strconv"
2223
"strings"
2324
"time"
@@ -54,13 +55,19 @@ type LogPatternFlag struct {
5455
}
5556

5657
// String implements the String function for flag.Value interface
58+
// Returns a space separated sorted by keys string of map values.
5759
func (lpf *LogPatternFlag) String() string {
5860
result := ""
59-
for k, v := range lpf.logPatternCountMap {
61+
var keys []string
62+
for k := range lpf.logPatternCountMap {
63+
keys = append(keys, k)
64+
}
65+
sort.Strings(keys)
66+
for _, k := range keys {
6067
if result != "" {
6168
result += " "
6269
}
63-
result += fmt.Sprintf("%v:%v", k, v)
70+
result += fmt.Sprintf("%v:%v", k, lpf.logPatternCountMap[k])
6471
}
6572
return result
6673
}

0 commit comments

Comments
 (0)