-
Notifications
You must be signed in to change notification settings - Fork 49
Description
I'm using github.com/yalp/jsonpath in a project used for testing my apis. It allows me to just look at the subset of the response payload that i'm interested in for the relevant test case. That package returns an interface{} for the value at the specified path instead of a []byte. I have a use-case where I'd like to perform a superset match on a map in the payload.
For example, my api returns something like:
{
"settings": {
"localization": {
"language": "foo"
},
"meta": {
"lastModified": "bar",
"displayName": "baz",
"file": {
"size": "bar",
"type": "baz"
}
}
}
}
In my test I want to verify some of the values under settings.meta. specifically the displayName string and file map. yalp/jsonpath returns me an interface{} which i can then cast to map[string]interface{} for everything under settings.meta. If I then want to jsondiff.Compare it I have to json.Marshal it back to a []byte.
Today, jsondiff.Compare immediately decodes the []byte into interface{} objects. Why not introduce a new public function that just takes the first parameter as an interface{} to avoid needing to re-marshal before the call? Then the assertion could look like:
jsondiff.CompareInterface(metaInterface, []byte(`{"displayName":"baz","file":{"size":"bar","type":"baz"}}`))