Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: Verifier > Show warning 'Empty list/map is risky' #417

Open
tienvx opened this issue May 12, 2024 · 0 comments
Open

Idea: Verifier > Show warning 'Empty list/map is risky' #417

tienvx opened this issue May 12, 2024 · 0 comments

Comments

@tienvx
Copy link
Contributor

tienvx commented May 12, 2024

This idea is related to Optional Attributes

  • Single element: Pact doesn't support it to be optional. This is nothing new. If we really want to test optional behavior, on consumer, we need to write 2 tests:
    • Element is null
    • Element match something
  • Array of elements/A map: The FAQ said it's not supported, but we can achieve it in many ways:
    • atLeast, atMost, constrainedArrayLike
      • Validate min on consumer, then force setting min >= 1
        • Pact-GO does this
        • But Pact-JS or Pact-PHP doesn't do this (I'm not sure about other languages)
      • There are absolutely nothing stop user from bypassing this validation. User just learn how Json Integration works, then write the syntax by themself (which has min=0, like this Validate min = 0 #304).
      • Validate min=0 in FFI Validate min = 0 #304: @rholshausen doesn't agree with it, and I also don't agree
    • eachKey, eachValue
      • There are nothing we can do to stop provider to return empty list/map
    • matchAll
      • If consumer doesn't add atLeast(), or just add atLeast(0), there are nothing we can do to stop provider to return empty list/map
    • values
      • This matcher is weird (and deprecated in Pact-PHP), so I prefer don't talk about it.

So, it's hard to handle empty list/map on consumer side. How about we do this while verifying provider:

When verifying, if provider return empty list/map, and somehow it match all the rules (describe above), we display a warning like this Empty list/map is very risky. It's suggested to return non-empty list/map to verify its structure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant