matryer / silk

Markdown based document-driven RESTful API testing.
http://silktest.org/
GNU General Public License v2.0
942 stars 69 forks source link

exclusion patterns #21

Open robmurtha opened 8 years ago

robmurtha commented 8 years ago

As a Tester I want to Exclude variable data (timestamps, id fields etc.) So that I can validate things that matter

Proposed feature

Designate a pattern that will be used to "erase" values from both the expected data, and the response.

Possible solutions

Use a special character field / operator to indicate the exclusion, in this example the prefix ! designates a type of expression being provided.

Text Patterns Substitute using sed style replace, mostly for text. !s: s/ABCDE/XXXXX/g

Remove data matching regex, in this case a valid email address. Any value matching the regex would be replaced with nothing.

!r: (?:[a-z0-9!#$%&'+/=?^{|}~-]+(?:.[a-z0-9!#$%&'_+/=?^_{|}~-]+)|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|[\x01-\x09\x0b\x0c\x0e-\x7f])")@(?:(?:a-z0-9?.)+a-z0-9?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|[\x01-\x09\x0b\x0c\x0e-\x7f])+)])

JSON Patterns Replace a field's contents with a dummy value. !_id: 123

Exclude field from json, the field "_id" field and value would be removed prior to compare. !x: _id

matryer commented 8 years ago

This would be great when asserting explicit bodies, but I think that kind of assertion on data isn't very useful anyway. Annoyingly, orders of objects (map) and even arrays aren't always predictable, so perhaps more Testify style "assert contains" ideas would work?

But this idea also addresses potential security issues (if passwords are sent around), although I'm keen to avoid solving things like that in the early stages.

robmurtha commented 8 years ago

Ok, one of the main goals would be to start with a known result that can be pasted into the document and then exclude things like timestamps and ids when running the test to avoid common mismatches. I'll play around with something simple with one syntax using a real example, thanks!

matryer commented 8 years ago

Awesome, yeah I’d love to see an example.

On 19 Feb 2016, at 14:48, Rob Murtha notifications@github.com wrote:

Ok, one of the main goals would be to start with a known result that can be pasted into the document and then exclude things like timestamps and ids when running the test to avoid common mismatches. I'll play around with something simple with one syntax using a real example, thanks!

— Reply to this email directly or view it on GitHub https://github.com/matryer/silk/issues/21#issuecomment-186242514.