How do I find which struct field is different when comparing two structs using reflect.DeepEqual()
. When I print the struct values then I don't see any difference between the 2 struct values but still the reflect.DeepEqual()
method returns false
As pointed our by kostix in his (now deleted) answer https://github.com/go-test/deep is very useful. It helped me find my issues in minutes when comparing large structures based on XML/JSON documents.
diff := deep.Equal(got, want)
if diff != nil {
t.Errorf("compare failed: %v", diff)
}
With the standard reflect package, I had to more or less implement the diff myself, but in this case it works and the diff shows all the field names up to the values which differ. It makes it really easy to find your issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With