google / go-cmp

Package for comparing Go values in tests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IgnoreFields and nested struct

kotyara85 opened this issue · 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!

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

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