-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Compare structs with unsorted slices #806
Comments
It would also be amazing if we we could compare 2 json-strings this way - almost like Example usage: expectedEvent := `{
"participants": ["Joe", "Rick"],
"event": "Birthday party"
}`
actualEvent := `{
"event": "Birthday party",
"participants": ["Rick", "Joe"]
}`
assert.JsonContentsMatch(t, expectedEvent, actualEvent) |
Is it in the raodmap? |
We can certainly add it. I'm going to spruce up the milestones this morning, I'll slot this in. |
Hey @glesica just checking if this got added to the milestones? It would be an incredibly useful feature |
I just ran into this with a slice nested down inside some structs. I'm using |
i have the same problem。 |
This use case seems to be addressed by the https://pkg.go.dev/github.com/stretchr/testify/assert?utm_source=godoc#ElementsMatch |
@mchlp Yes and no... It does solve it in the case the OP presented. Now imagine you have assert.Equal(t, expectedResponse, receivedResponse) But you have write: assert.Equal(t, expectedResponse.field1, receivedResponse.field1)
assert.Equal(t, expectedResponse.field2, receivedResponse.field2)
...
assert.ElementsMatch(t, expectedResponse.field20, receivedResponse.field20) And this is only the simple case without any nesting.... If I have to write this all out by hand, why am I even using an assertion library? |
Potentially could be addressed by: #843 (comment) |
Hi!
Are here any assert func to compare two struct contains same slices with the same elements but in differs order?
For example:
I need some func that can compare that two structs ignoring slice elems order in it.
The text was updated successfully, but these errors were encountered: