Skip to content

Stub server should support generator MockServerURL #55

@tienvx

Description

@tienvx

Generator MockServerURL is used like this:

{
      'pact:matcher:type': 'regex',
      'pact:generator:type': 'MockServerURL',
      regex: '.*(\\/example/path)$',
      value: 'http://localhost:8080/example/path',
      example: 'http://localhost:8080/example/path',
    }

Mock Server support this generator (obviously from its name), so Consumer's contract test passed.
But Stub Server doesn't support this generator, so Consumer's integration test failed.

I think:

  • This is a bug, and Stub Server should support this generator (because it support other generators, at least I tested with RandomInt)
  • Should we rename MockServerURL to something else that say that Stub Server support it too? I don't have suggestion, naming is hard.

Here are some additional information:

Pact file from the above demo project

In case you don't want to run the demo project to see the contract file

{
"consumer": {
  "name": "MyConsumer"
},
"interactions": [
  {
    "description": "a request for all urls",
    "key": "285dde1d2816ddad",
    "pending": false,
    "providerStates": [
      {
        "name": "I have a list of urls"
      }
    ],
    "request": {
      "headers": {
        "Accept": [
          "application/json"
        ]
      },
      "method": "GET",
      "path": "/urls"
    },
    "response": {
      "body": {
        "content": {
          "urls": [
            {
              "url": "http://localhost:8080/example/path"
            }
          ]
        },
        "contentType": "application/json",
        "encoded": false
      },
      "generators": {
        "body": {
          "$.urls[*].url": {
            "example": "http://localhost:8080/example/path",
            "regex": ".*(\\/example/path)$",
            "type": "MockServerURL"
          }
        }
      },
      "headers": {
        "Content-Type": [
          "application/json"
        ]
      },
      "matchingRules": {
        "body": {
          "$.urls": {
            "combine": "AND",
            "matchers": [
              {
                "match": "type",
                "min": 1
              }
            ]
          },
          "$.urls[*].url": {
            "combine": "AND",
            "matchers": [
              {
                "match": "regex",
                "regex": ".*(\\/example/path)$"
              }
            ]
          }
        },
        "header": {}
      },
      "status": 200
    },
    "type": "Synchronous/HTTP"
  },
  {
    "description": "a request the url http://provider.com/example/path",
    "key": "7824381c6cca0583",
    "pending": false,
    "providerStates": [
      {
        "name": "I have a url http://provider.com/example/path"
      }
    ],
    "request": {
      "headers": {
        "Accept": [
          "application/json"
        ]
      },
      "method": "GET",
      "path": "/example/path"
    },
    "response": {
      "body": {
        "content": {
          "key": "value"
        },
        "contentType": "application/json",
        "encoded": false
      },
      "headers": {
        "Content-Type": [
          "application/json"
        ]
      },
      "matchingRules": {
        "body": {
          "$.key": {
            "combine": "AND",
            "matchers": [
              {
                "match": "type"
              }
            ]
          }
        },
        "header": {}
      },
      "status": 200
    },
    "type": "Synchronous/HTTP"
  }
],
"metadata": {
  "pact-js": {
    "version": "11.0.2"
  },
  "pactRust": {
    "ffi": "0.4.0",
    "models": "1.0.4"
  },
  "pactSpecification": {
    "version": "4.0"
  }
},
"provider": {
  "name": "MyProvider"
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions