Hello, I'm a little confused with the Pact behavio...
# pact-go
k
Hello, I'm a little confused with the Pact behaviour regarding non-defined states on provider side. Currently, the request is called even when state is not defined. Is it possible to fail the test if the state is not defined on provider? I would love to have tests like these
pending
more then passing. Thx! Log from my test:
Copy code
023/10/19 13:00:03 [INFO] executing state handler middleware
2023/10/19 13:00:03 [WARN] no state handler found for state: ComponentDetectionQuery progressing
2023-10-19T11:00:03.919419Z  INFO ThreadId(13) pact_verifier: Running provider verification for 'request to return CDQ'
2023-10-19T11:00:03.919461Z  INFO ThreadId(13) pact_verifier::provider_client: Sending request to provider at <http://localhost:43615/>
2023-10-19T11:00:03.919465Z  INFO ThreadId(13) pact_verifier::provider_client: Sending request HTTP Request ( ... )
2023-10-19T11:00:03.921893Z  INFO ThreadId(13) pact_matching: comparing to expected response: HTTP Response ( status: 200, headers: Some({"Content-Type": ["application/json"]}), body: Present(430 bytes) )
2023-10-19T11:00:03.922307Z  INFO ThreadId(13) pact_verifier: Running teardown provider state change handler 'ComponentDetectionQuery progressing' for 'request to return CDQ'
2023/10/19 13:00:03 [INFO] executing state handler middleware
2023/10/19 13:00:03 [WARN] no state handler found for state: ComponentDetectionQuery progressing

...

  request to return CDQ (0s loading, 5ms verification)
     Given ComponentDetectionQuery progressing
    returns a response which
      has status code 200 (OK)
      includes headers
        "Content-Type" with value "application/json" (OK)
      has a matching body (OK)
m
Why would you want it to fail if the tests pass? That tells me you don’t really need to spend time creating a state handler for it
🤔 1
If it stops working, that will only happen if the code changes in the provider anyway, and would get caught other locally before you commit, or in the CI pipeline for that change.
k
Ok, I've not thought about using a tests without state. Is it a good practice? I thought it is better to define a state so it would make tests more stable (maybe I'm wrong, haven't proven that). We wanted to have a rule that every state defined in consumer is implemented in provider. So, when a new consumer comes, they can easily see what states are in place and they can reuse them. It will lower the provider work needed a lot. Btw, I'm still somehow struggling on how to share the "library" of states and their required parameters. I can't do a simple library as consumer is javascript and provider is golang. Do you have any experience with that?