The workaround is to use PartialEqual for non-zero values, and standard assertions for zero ones.
Does this not just bring you right back where new fields in a struct aren’t being checked? I’m not a Go developer, but this seems more explicit to me:
result := foo.GetResult()
expected := foo.Result{
foo: 2,
bar: nil,
// There is also a CreatedAt and UpdatedAt field, but we ignore them
}
equal_struct(t, result, expected, "CreatedAt", "UpdatedAt")
equal_struct then checks that the fooandbar fields are the same, ignores CreatedAt and UpdatedAt, and then makes sure there are no more fields.
Does this not just bring you right back where new fields in a struct aren’t being checked? I’m not a Go developer, but this seems more explicit to me:
equal_struct
then checks that thefoo
andbar
fields are the same, ignoresCreatedAt
andUpdatedAt
, and then makes sure there are no more fields.I’m curious about the implementation of PartialEqual… but I don’t see a link to the source code? I would love to compare it to gstruct from GoMega https://onsi.github.io/gomega/#codegstructcode-testing-complex-data-types
Author replied to my tweet with a link: https://gist.github.com/brandur/7b459a1ed81bfd041fabf05dc34265e3