diff --git a/assert/assertions.go b/assert/assertions.go index 1320317..638bb04 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -18,6 +18,10 @@ import ( "github.com/pmezard/go-difflib/difflib" ) +func init() { + spew.Config.SortKeys = true +} + // TestingT is an interface wrapper around *testing.T type TestingT interface { Errorf(format string, args ...interface{}) @@ -1001,7 +1005,6 @@ func diff(expected interface{}, actual interface{}) string { return "" } - spew.Config.SortKeys = true e := spew.Sdump(expected) a := spew.Sdump(actual) diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 12d8151..df17f89 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -1125,6 +1125,40 @@ func TestDiffEmptyCases(t *testing.T) { Equal(t, "", diff([]int{1}, []bool{true})) } +// Ensure there are no data races +func TestDiffRace(t *testing.T) { + t.Parallel() + + expected := map[string]string{ + "a": "A", + "b": "B", + "c": "C", + } + + actual := map[string]string{ + "d": "D", + "e": "E", + "f": "F", + } + + // run diffs in parallel simulating tests with t.Parallel() + numRoutines := 10 + rChans := make([]chan string, numRoutines) + for idx := range rChans { + rChans[idx] = make(chan string) + go func(ch chan string) { + defer close(ch) + ch <- diff(expected, actual) + }(rChans[idx]) + } + + for _, ch := range rChans { + for msg := range ch { + NotZero(t, msg) // dummy assert + } + } +} + type mockTestingT struct { }