pact-foundation / pact-specification

Describes the pact format and verification specifications
MIT License
292 stars 28 forks source link

Assure property exists #58

Open Sinuhe20 opened 6 years ago

Sinuhe20 commented 6 years ago

I'm not very satisfied with the matchers. With current matchers it's possible to say that if a property exists it has to be of a special type or must have a special content, but it's not possible to assure, that the property has to exist at all. For example, how would you assure with matchers that with

body: {
  "abc": "def"
}

property "abc" is a string and must be present in the body?

matching rule

"$.body.*": 
{
"match": "type"
},

would not give an error, if only

{}

is sent.

mefellows commented 6 years ago

With current matchers it's possible to say that if a property exists it has to be of a special type or must have a special content, but it's not possible to assure, that the property has to exist at all

This is incorrect. The problem is, the matcher you've identified is too broad and is not being specific about what it needs. A matcher such as the following would satisfy your request:

"$.body.abc": 
{
"match": "type"
}

How did you arrive at the above matching rule?

Sinuhe20 commented 6 years ago

Is not working for me, if "abc" is missing, test is also ok with this rule.

There is also a problem with arrays, let's say you have the matcher

"$.body.array": 
{
  "min": 1,
  "match": "type"
}

It works perfect, as long as 'array' is present in the body. But if property 'array' is missing, test says also everything is ok.

I think there is the general problem, that if no matcher can be selected, the test will pass.

P.S.

I see if I omit

"$.body.*": 
{
  "match": "type"
}

the matching is more strict, but than I have to define type rules for every attribute. This could work but is very inconvenient.

mefellows commented 6 years ago

Can you please share the code you have that is resulting in this, or even better, a project so we can repro? What you're asking for is absolutely fundamental to how Pact works, so something must be going wrong along the line somewhere.

On Tue, May 22, 2018, 9:40 PM OliverSanftleben notifications@github.com wrote:

Is not working for me, if "abc" is missing, test is also ok with this rule.

There is also a problem with arrays, let's say you have the matcher

"$.body.array": { "min": 1, "match": "type" }

It works perfect, as long as 'array' is present in the body. But if property 'array' is missing, test says also everything is ok.

I think there is the general problem, that if no matcher can be selected, the test will pass.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pact-foundation/pact-specification/issues/58#issuecomment-390959749, or mute the thread https://github.com/notifications/unsubscribe-auth/AADSjCbVGRsfzGqVURqqFXxNFMl94xkuks5t0_kngaJpZM4UIbzz .