You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
It would nice to have built-in matcher that compares slices and returns true if slices have same elements in arbitrary order.
Why the feature is needed
Sometimes code we are testing produces slices with non-determined elements order. For example, when converting map to slice we may end up with many possible orders of elements.
s := make([]interface{}, 0, len(m))
for k, v := range m {
s = append(s, v)
}
Some testing frameworks like testify include special assert function checking if two slices have same elements.
If we have a mock depending on arguments with non-determined elements order such as s then setting up expected calls for such mock can be quite inconvenient. We either have to use Any() matcher and skip validating this argument at all or implement custom matcher.
Proposed solution
Include built-in matcher like InAnyOrder(s []interface{}) or WithSameElements(s []interface{} implementing checks similar to assert.ElementsMatch
P.S.
I will be happy to implement the matcher if we agree on this feature being useful.
The text was updated successfully, but these errors were encountered:
Hey, thanks for the feature request. I will let this issue sit for a little bit to see what others in the community think of the idea. I could see how a matcher like this could be useful.
Requested feature
It would nice to have built-in matcher that compares slices and returns
true
if slices have same elements in arbitrary order.Why the feature is needed
Sometimes code we are testing produces slices with non-determined elements order. For example, when converting map to slice we may end up with many possible orders of elements.
Some testing frameworks like testify include special assert function checking if two slices have same elements.
If we have a mock depending on arguments with non-determined elements order such as
s
then setting up expected calls for such mock can be quite inconvenient. We either have to useAny()
matcher and skip validating this argument at all or implement custom matcher.Proposed solution
Include built-in matcher like
InAnyOrder(s []interface{})
orWithSameElements(s []interface{}
implementing checks similar to assert.ElementsMatchP.S.
I will be happy to implement the matcher if we agree on this feature being useful.
The text was updated successfully, but these errors were encountered: