-
Notifications
You must be signed in to change notification settings - Fork 18k
reflect: DeepEqual fails with matching key/value pairs in maps #44154
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
Comments
If you change your code to either
or |
Closing because this is working as expected. Please comment if you disagree. |
Sorry, I extracted some of the logic into a playground and mistyped. Wasn't going to share the entire project. In the actual project, I'm not comparing a struct to a map. This is actually failing in a unit test using the ginkgo/gomega frameworks. According to their docs, gomega uses For the following test case: It("sets the number of nodes missing from each pool", func() {
actualReturn = CheckMissingPods(test, allRunningPods)
Expect(actualReturn.NodeCountByPool).To(Equal(
map[string]int{
DefaultClientPool: 0,
DefaultDriverPool: 0,
DefaultServerPool: 0,
},
))
}) This is the failed expectation we are seeing:
I will need to dive in to see if this is some sort of issue with gomega, since it did not replicate in the playground. I'll comment here if I cannot see a way gomega could cause this failure, and I'll update what I find regarding the framework in onsi/gomega#412. |
In the failure message one of the maps has the key |
@ianlancetaylor Thank you. I don't see how I missed that. I haven't felt well the last two days, and I knew I'm feeling crazy tired… guess I just thought I was still functional. Sorry to waste your time. |
No worries. |
What version of go are you using?
I noticed the issue when running code commit c8bd801, but I can confirm this problem exists on Go Playgrounds as well (see link in next section).
What did you do?
I created two maps with equal keys and values. Then, I compared them using
reflect.DeepEqual
.https://play.golang.org/p/OjDV7PWt1SY
What did you expect to see?
The maps are structurally different, but they have equal keys/values and length. I would expect them to be equal.
What did you see instead?
The maps are not structurally identical, so
reflect.DeepEqual
returns false.The text was updated successfully, but these errors were encountered: