go-test / deep

Golang deep variable equality test that returns human-readable differences
MIT License
751 stars 54 forks source link

bytesBuffer comparison is not executed at all #35

Closed LucaPaterlini closed 5 years ago

LucaPaterlini commented 5 years ago

https://play.golang.org/p/KFbA0PmNoxO

as you can see the two buffer do not have the same content but deep consider it all fine.

daniel-nichter commented 5 years ago

Set deep.CompareUnexportedFields = true and it works. Problem is https://golang.org/pkg/bytes/#Buffer has no exported fields and no Equal method. Unlike reflect.DeepEqual, go-test/deep does not check unexported fields by default because it tends to result in more false-positives. In fact, this is the first time I've seen a true need for CompareUnexportedFields.

It's common for objects to have many unexported/internal/private fields, and there's no way to know which affect identity and which don't. https://golang.org/pkg/time/#Time.Equal is a good example: time equality is tricky, so we let the object tell us what's equal or not.