Go Struct Diff

I just moved to a Go based project from working on a Python-Django and previously a Nodejs one. What immediately struck me was that the unit tests in the project were implemented with use of standard library only. This by itself I should have expected - classic Go approach, since with its rich STD lib you go really far. Also quite some of examples and tutorials about testing in Go were starting off with just what language provided out of the box. There was however one task that I could not accomplish to my satisfaction with Go std lib only, having been used to how Jest and Pytest work.

Diffing structs

When comparing objects in Jest or Dicts with Pytest you get a pretty printed diff with highlighted field which fails the comparison. No to so much in the canonical Go test setup which looks like this:

if reflect.DeepEquals(struct1, struct2) {
    t.Failf("Struct1 not the same as expected %v %v", struct1, struct2)

while the setup is simple and does not have any dependencies, you immediately see that when the testing condition fails what you get is a dump of the entire structure and it is up to you to wade through it to find the differences. Additional problem being that you have to write the log message yourself.

Go CMP and go-test/deep

Fortunately there are some packages you can readily go get to acquire Jest/Pytest diffing qualities. The libs I found for that are Deep and go-cmp. I was surprised that they weren’t more popular though. Don’t more people miss the convenience that such diffs offer?