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

Stub server should support generator MockServerURL #55

Open
tienvx opened this issue May 2, 2023 · 2 comments
Open

Stub server should support generator MockServerURL #55

tienvx opened this issue May 2, 2023 · 2 comments

Comments

@tienvx
Copy link

tienvx commented May 2, 2023

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"
}
}
@rholshausen
Copy link
Contributor

@tienvx
Copy link
Author

tienvx commented May 31, 2023

I follow these steps:

  • Clone this project (pact-stub-server)
  • Update pact_models in Cargo.toml to ~1.1.3
  • Run cargo build
  • Follow those steps in https://github.com/tienvx/test-mock-server-url-generator
  • Instead of starting stub server using yarn, run this command instead: target/debug/pact-stub-server -p 8001 -d ../test-mock-server-url-generator/pacts --cors

But it doesn't fix the issue. The connection refused error is still there.

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

2 participants