google/go-cmp

IgnoreFields and nested struct

kotyara85 opened this issue · 2 comments

Hey there,
So I have this struct

type File struct {
Sources []*Source `json:"sources"`
}


type Source struct {
 UID string `json:"uid"
}

I need to ignore UID as it's dynamically generated

cmp.Equal(c.response, response, cmpopts.IgnoreFields(File{}, "UID"))

Is not doing anything. Is there a way to achieve this with this package?

Thanks!

dsnet commented

Don't you mean cmpopts.IgnoreFields(Source, "UID)? as the "UID" field is declared on the Source type rather than the File type?

dsnet commented

Closing as there is nothing actionable here. Feel free to comment with an update and we can reopen.