quick question: I have this pact file with the con...
# general
s
quick question: I have this pact file with the contents. This file is in my local machine path:
/Users/srentala/Desktop/Pact/pacts
Copy code
{
  "consumer": {
    "name": "test-consumer"
  },
  "provider": {
    "name": "test-provider"
  },
  "interactions": [
    {
      "description": "a request to get the machine IP",
      "providerState": "a endpoint to get IP",
      "request": {
        "method": "GET",
        "path": "/product"
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json; charset=utf-8"
        },
        "body": {
          "ip": "81.96.249.131"
        },
        "matchingRules": {
          "$.headers.Content-Type": {
            "match": "regex",
            "regex": "^application\\/json"
          },
          "$.body": {
            "match": "type"
          }
        }
      }
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "2.0.0"
    }
  }
}
I am running the following command to create a mock server using Pact :
pact-mock-service --consumer test-consumer --provider test-provider --port 1234 --pact-dir=/Users/srentala/Desktop/Pact/pacts
but on hitting the endpoint from Postman, it gives following “no interactions found” . What am I missing here?
y
The pact-mock-service is documented here https://github.com/pact-foundation/pact-mock_service#mock-service-usage The option you are specifying is where the pact mock service will write generated pacts.
Copy code
-d, [--pact-dir=PACT_DIR]                                      # Directory to which the pacts will be written
If you are trying to load a pact file, to generate as a stub, you can use https://github.com/pact-foundation/pact-mock_service#stub-service-usage
Here is an example of a usage of the pact-mock-service https://github.com/pact-foundation/pact-mock_service/blob/master/script/example.sh You would need to load your interactions in via HTTP requests
m
yes, you want the stub server
You should probably also use the new recommended one here: https://docs.pact.io/implementation_guides/cli
s
Thanks @Yousaf Nabi (pactflow.io) and @Matt (pactflow.io / pact-js / pact-go)
👍 1
@Yousaf Nabi (pactflow.io) @Matt (pactflow.io / pact-js / pact-go) I have successfully created a mock service as explained in the documentation. However I was wondering if we have a way to just create pacts directly from the interactions’s json(without actual doing registering of pacts, hitting the endpoint etc etc..) ? I have interactions with me … all I want is to generate pacts using a single command? Can we do that?
m
What are you trying to do? Can you just create a pact file in advance and send to a stub server?
s
So If I have an agreed interactions.json file, can I not create pact out of it directly?
y
No, as the Pact framework seeks to assure strong guarantees in the generated pact consumer contract file, that the client actually issued those requests, prior to serialising into a pact file. What is your particular use case?
You could transform your interactions file into a pact file, and validate the output against the v2 schema https://bitbucket.org/atlassian/pact-json-schema/src/master/schemas/v2/schema.json to ensure you are generating a valid pact 2.0.0 specification file