silk icon indicating copy to clipboard operation
silk copied to clipboard

exclusion patterns

Open robmurtha opened this issue 9 years ago • 3 comments

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

robmurtha avatar Feb 18 '16 22:02 robmurtha

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.

matryer avatar Feb 19 '16 14:02 matryer

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!

robmurtha avatar Feb 19 '16 14:02 robmurtha

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

On 19 Feb 2016, at 14:48, Rob Murtha [email protected] 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.

matryer avatar Feb 19 '16 14:02 matryer