Coder Social home page Coder Social logo

Comments (11)

thetrav avatar thetrav commented on May 30, 2024

Is the large data set fundamentally part of the response? I would look into constructing a test state where less data needed to be transmitted (assuming that scenario still makes sense to the provider)

from pact-specification.

bethesque avatar bethesque commented on May 30, 2024

Pact really works best when you are able to set up data on the provider yourself (provider states). It's not the best tool for using with an API where you don't control the data (as it sound like you aren't). Check out some docs about that here: https://github.com/realestate-com-au/pact/wiki/Why-Pact-may-not-be-the-best-tool-for-testing-public-APIs

Having said that, in version 2 matching, we are looking at adding the ability to specify "an array of > 1 length, where all items match this pattern". I don't imagine that will be available within the next few weeks however.

from pact-specification.

uglyog avatar uglyog commented on May 30, 2024

I think this would be very useful. I find one of the big issues I experience is the coupling of the consumer test data to the provider ones.

An example: I have a User provider that provides lists of users. The contract would be to retrieve a list of users. It is more important that I get a list of at least one user, and that all users I get back conform to my contract.

I find with provider states I have to create fixtures that are shared between the consumer tests and the provider tests which creates a form of coupling. If someone updates the fixture in one project, they have to know to go through every project and do the same update. If the condition was less strict, you could update the fixture in the provider to change the number of entities and all the consumer tests would still work.

from pact-specification.

uglyog avatar uglyog commented on May 30, 2024

Here is my thoughts on the at_least rule:

at_least(3, number) means at least 3 numbers, but all elements must be numbers.
at_least(3, 'red') means at least 3 reds.
at_least(1, { "name": "Bob"}) means 1 or more objects, but they all have to have a name field with value bob.

from pact-specification.

bethesque avatar bethesque commented on May 30, 2024

From comment in example:

I don't like the idea of specifying a type with a name, because then we have to agree across all implementations in all languages what each type means. Specifying by example is the pact way so far, and I'd like to continue with it.

I think at_least([1, 2, 3]) should mean "an array starting with 1, 2, 3".
I think at_least(['red', 'red', 'red']) isn't a scenario that's likely to be useful - why would you ever have three of the same thing in a row?
I think some({"name": "Bob"}) is the most likely scenario, and should mean 'at least one where all the elements match by type.'

Edit: I think some({"name": "Bob"}) is the most likely scenario, and should mean 'at least one item, where all the elements in the list match by type.'

from pact-specification.

uglyog avatar uglyog commented on May 30, 2024

I don't think 'at least one where all the elements match' is the most likely, I think it is 'at least one in the list, and all the items in the list must match'. That is the case that @mortenlj gave.

from pact-specification.

bethesque avatar bethesque commented on May 30, 2024

Sorry, I phrased it badly, that is what I meant.

from pact-specification.

uglyog avatar uglyog commented on May 30, 2024

I think I have worked out a way to implement this. We can add an at_least matcher that takes a minimum number and a single example (or a single definition with matchers). It will add then add the following to the matchers for the given definition:

// example in groovy-like language
example_consumer_body {
    users atLeast(2) {
        name matchString
        age matchNumber
        id identifier
    }
}

Resulting matchers:

{
  "$.body.users": {"at_least": 2},
  "$.body.users.$all.name": {"match": "string"},
  "$.body.users.$all.age": {"match": "number"},
  "$.body.users.$all.id": {"regex": "[0-9]+"},
}

This means we expect a list with at least 2 elements, but all elements must match the given rules. We can have a similar behaviour for at_most.

This will work until somebody has an API with $all as a key. We can also use a * to mean all, but then someone could also use * as a key! :-P

For the case of some, I would prefer the use of any, but it can support both. So we could have: at_least, at_most, any and all.

from pact-specification.

bethesque avatar bethesque commented on May 30, 2024

For the type based matching, I was envisioning something like:

body: something_like(
  name: "Fred",
  age: 9
)

becomes

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

That could be reused in this case:

{
  "$.body.users": {"at_least": 2},
  "$.body.users.*": {"match": type}
}

It has less duplication, and instructs the matcher how to use the example to match to the real thing, rather than specifying what the expected thing should be.

from pact-specification.

uglyog avatar uglyog commented on May 30, 2024

The following test cases have been added for this feature:
testcases/request/body/array size less than required.json
testcases/request/body/array with at least one element matching by example.json
testcases/request/body/array with at least one element not matching example type.json
testcases/request/body/array with nested array that does not match.json
testcases/request/body/array with nested array that matches.json
testcases/request/body/array with regular expression in element.json
testcases/request/body/array with regular expression that does not match in element.json

from pact-specification.

mortenlj avatar mortenlj commented on May 30, 2024

Hi. I'm going over my old issues and PRs on github and "cleaning up". From what I can gather, this was eventually included in the v2 specification, wasn't it?

I moved on to other projects some years ago, so I never got around to actually trying to use the requested feature. I'm closing the issue, feel free to re-open if it should be kept.

from pact-specification.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.