Conversation
|
Starting to think that may be a I'm thinking it could work something like this: jsonassert.Assertf(payload, `{
"nested": {
"<<PARTIAL>>": "Value doesn't matter, but let's establish a boolean convention",
"thisNestedObject": "can have additional keys in the payload and still pass the test"
},
"anotherNested": {
"thisOtherNestedObject": "is checked for unexpected keys"
},
"thisOuterObject": "is also checked for unexpected keys"
}`)and for arrays it would work like: jsonassert.Assertf(payload, `{
"someArr": [
"<<PARTIAL>>",
"the above directive must be the first in the array",
"and if present the existence of the following values",
"irrespective of order",
"is all that's checked."
"i.e. <<PARTIAL>> can be used for both...",
"- checking for that *one element* out of 100",
"- and checking for unordered arrays"
]
}`)as I'm writing this I'm convincing myself that I should probably implement some sort of ordering check independently of this feature first, as the above solution would pass even if there were unexpected elements in an unordered array. |
|
I love the idea of
Some of the APIs i'm testing against don't have deterministic ordering, so i've had to hack around this with unmarshal/sort/marshal/compare logic. |
|
Thank you for the excellent library and all the hard work! Another way which we could approach this problem is to allow interfaces to be passed. This could allow golang tags to be used for extra metadata to apply during a match. For example type MatcherOutput struct {
FieldA []string `json:"field_a" jsonassert:"unordered"`
...
} |
|
@blaskovicz This PR is probably not going to land soon (chances are I'll rewrite it), but if you want you can check if |
Closes #20
ContainsfAPI"<<UNORDERED>>"feature to ignore ordering in arrays.TODO: