From 9a3258719aa5848a1a1cc065e3754066c5c802d9 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Fri, 9 Sep 2022 13:57:25 +0200 Subject: [PATCH] common/helpers: remove global side-effect from DiffFormatter option --- common/helpers/tests_diff.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/common/helpers/tests_diff.go b/common/helpers/tests_diff.go index 3213c804..11ff5093 100644 --- a/common/helpers/tests_diff.go +++ b/common/helpers/tests_diff.go @@ -20,12 +20,15 @@ var prettyC = pretty.Config{ PrintStringers: false, SkipZeroFields: true, IncludeUnexported: false, - Formatter: map[reflect.Type]interface{}{ +} + +func defaultPrettyFormatters() map[reflect.Type]interface{} { + return map[reflect.Type]interface{}{ reflect.TypeOf(net.IP{}): fmt.Sprint, reflect.TypeOf(netip.Addr{}): fmt.Sprint, reflect.TypeOf(time.Time{}): fmt.Sprint, reflect.TypeOf(SubnetMap[string]{}): fmt.Sprint, - }, + } } // DiffOption changes the behavior of the Diff function. @@ -40,6 +43,7 @@ type DiffOption struct { // returned. func Diff(a, b interface{}, options ...DiffOption) string { prettyC = prettyC + prettyC.Formatter = defaultPrettyFormatters() for _, option := range options { switch option.kind { case DiffUnexported.kind: