I am currently using the go-cmp
package to compare struct equality. For testing purposes I have the need to compare two different types of structs that should have the same fields with the same values.
As a minimal example I am running into the issue where the cmp.Equal()
function returns false
for different types, even though they have the same fields and values.
type s1 struct {
Name string
}
type s2 struct {
Name string
}
p1 := s1{Name: "John"}
p2 := s2{Name: "John"}
fmt.Println(cmp.Equal(p1, p2)) // false
This is understandable since the two types are different but is there a way to instruct cmp.Equal()
to ignore the types and only look at fields?