mirror of https://github.com/stretchr/testify.git
Sort map keys before diffing maps
parent
e7a1d8890c
commit
67106a5111
|
@ -961,6 +961,7 @@ func diff(expected interface{}, actual interface{}) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spew.Config.SortKeys = true
|
||||||
e := spew.Sdump(expected)
|
e := spew.Sdump(expected)
|
||||||
a := spew.Sdump(actual)
|
a := spew.Sdump(actual)
|
||||||
|
|
||||||
|
|
|
@ -1055,12 +1055,28 @@ Diff:
|
||||||
)
|
)
|
||||||
Equal(t, expected, actual)
|
Equal(t, expected, actual)
|
||||||
|
|
||||||
// output for maps cannot be equally tested since order is random
|
expected = `
|
||||||
|
|
||||||
|
Diff:
|
||||||
|
--- Expected
|
||||||
|
+++ Actual
|
||||||
|
@@ -1,6 +1,6 @@
|
||||||
|
(map[string]int) (len=4) {
|
||||||
|
- (string) (len=4) "four": (int) 4,
|
||||||
|
+ (string) (len=4) "five": (int) 5,
|
||||||
|
(string) (len=3) "one": (int) 1,
|
||||||
|
- (string) (len=5) "three": (int) 3,
|
||||||
|
- (string) (len=3) "two": (int) 2
|
||||||
|
+ (string) (len=5) "seven": (int) 7,
|
||||||
|
+ (string) (len=5) "three": (int) 3
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
actual = diff(
|
actual = diff(
|
||||||
map[string]int{"one": 1, "two": 2, "three": 3, "four": 4},
|
map[string]int{"one": 1, "two": 2, "three": 3, "four": 4},
|
||||||
map[string]int{"one": 1, "three": 3, "five": 5, "seven": 7},
|
map[string]int{"one": 1, "three": 3, "five": 5, "seven": 7},
|
||||||
)
|
)
|
||||||
NotZero(t, len(actual))
|
Equal(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDiffEmptyCases(t *testing.T) {
|
func TestDiffEmptyCases(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue