Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow usage of AllowUnexported() and IgnoreFields() #196

Closed
gauntface opened this issue May 6, 2020 · 1 comment · Fixed by #203
Closed

Allow usage of AllowUnexported() and IgnoreFields() #196

gauntface opened this issue May 6, 2020 · 1 comment · Fixed by #203

Comments

@gauntface
Copy link

I have hit a few scenarios where I want to compare some unexported fields but not all and I can't use AllowUnexported and IgnoreFields together.

opts := []cmp.Option{
	cmp.AllowUnexported(Client{}),
	cmpopts.IgnoreFields(Client{}, "httpNewRequest"),
}
if diff := cmp.Diff(got, tt.want, opts...); diff != "" {
	t.Fatalf("Unexpected result; diff %v", diff)
}

Results in a panic: name must be exported

@dsnet
Copy link
Collaborator

dsnet commented May 6, 2020

It's been on my radar to have cmpopts.IgnoreFields work with unexported fields. If you want to try and enable this, feel free to send a PR.

dsnet added a commit that referenced this issue May 20, 2020
Modify IgnoreFields to permit the specification of unexported fields.
To avoid a bug with reflect.Type.FieldByName, we disallow forwarding
on unexported fields. See https://golang.org/issue/4876 for details.

Fixes #196
dsnet added a commit that referenced this issue May 20, 2020
Modify IgnoreFields to permit the specification of unexported fields.
To avoid a bug with reflect.Type.FieldByName, we disallow forwarding
on unexported fields. See https://golang.org/issue/4876 for details.

Fixes #196
@dsnet dsnet removed the help wanted label Jun 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants