Skip to content

Commit

Permalink
fix(format): sort config map items before output
Browse files Browse the repository at this point in the history
  • Loading branch information
piksel committed Feb 17, 2021
1 parent 3ace8d2 commit 6f2e6b0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/format/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ var _ = Describe("the format package", func() {
testSetAndFormat(tv, fieldMap["SubPropPtrSlice"], "@diet,@glue", "[ @diet, @glue ]")
})
It("should format prop struct slices identical to input", func() {
testSetAndFormat(tv, fieldMap["StrMap"], "a:1,c:3,b:2", "{ a: 1, b: 2, c: 3 }")
testSetAndFormat(tv, fieldMap["StrMap"], "a:1,b:2,c:3", "{ a: 1, b: 2, c: 3 }")
})
})
})
Expand Down
3 changes: 2 additions & 1 deletion pkg/format/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,10 @@ func GetConfigFieldString(config reflect.Value, field FieldInfo) (value string,
kvPairs := []string{}
for _, key := range configField.MapKeys() {
value := configField.MapIndex(key).Interface()

kvPairs = append(kvPairs, fmt.Sprintf("%s:%s", key, value))
}
// Map key/value-pairs are sorted after concat as it should be identical to sorting the keys before
sort.Strings(kvPairs)
return strings.Join(kvPairs, ","), nil
} else if fieldKind == reflect.Slice || fieldKind == reflect.Array {
sliceLen := configField.Len()
Expand Down

0 comments on commit 6f2e6b0

Please sign in to comment.