pact-foundation / pact-ruby-standalone

A standalone pact command line executable using the ruby pact implementation and Travelling Ruby
https://pact.io
MIT License
42 stars 33 forks source link

pact-message produces inconsistent pact file #65

Closed tugtugtug closed 3 years ago

tugtugtug commented 3 years ago

Pre issue-raising checklist

I have already (please mark the applicable with an x):

Software versions

Expected behaviour

the pact file produced should look like below with contents and matchingRules populated correctly:

{
  "consumer": {
    "name": "test@consumer"
  },
  "provider": {
    "name": "test@provider"
  },
  "messages": [
    {
      "description": "'some thing changed' event",
      "providerStates": [
        {
          "name": "test",
          "params": null
        }
      ],
      "contents": {
        "changed": {
          "id": "exampleId",
          "anotherId": "anotherId"
        }
      },
      "matchingRules": {
        "body": {
          "$.changed.id": {
            "match": "type"
          },
          "$.changed.anotherId": {
            "match": "type"
          }
        }
      },
      "metaData": {
        "content-type": "application/json"
      }
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "2.0.0"
    }
  }
}

Actual behaviour

The contents is left with the rule markers, and matchingRules empty.

{
  "consumer": {
    "name": "test@consumer"
  },
  "provider": {
    "name": "test@provider"
  },
  "messages": [
    {
      "description": "'some thing changed' event",
      "providerStates": [
        {
          "name": "test",
          "params": null
        }
      ],
      "contents": {
        "changed": {
          "id": {
            "contents": "exampleId",
            "json_class": "Pact::SomethingLike"
          },
          "anotherId": {
            "contents": "anotherId",
            "json_class": "Pact::SomethingLike"
          }
        }
      },
      "matchingRules": {
      },
      "metaData": {
        "content-type": "application/json"
      }
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "2.0.0"
    }
  }
}

Steps to reproduce

./pact-message update --consumer='test@consumer' --pact-dir='/tmp' --provider='test@provider'
{"providerStates":[{"name":"test"}],"description":"'some thing changed' event","contents":{"changed":{"id":{"contents":"exampleId","json_class":"Pact::SomethingLike"},"anotherId":{"contents":"anotherId","json_class":"Pact::SomethingLike"}}},"metadata":{"content-type":"application/json"}}

Relevent log files

NO logging is produced and no --log-level is supported.

Interesting finding

If I run the pact-message again with another message, the previous ones will be updated properly. i.e. after the above step if I run again with:

./pact-message update --consumer='test@consumer' --pact-dir='/tmp' --provider='test@provider'
{"providerStates":[{"name":"test2"}],"description":"'some thing else changed' event","contents":{"changed":{"id":{"contents":"exampleId","json_class":"Pact::SomethingLike"},"anotherId":{"contents":"anotherId","json_class":"Pact::SomethingLike"}}},"metadata":{"content-type":"application/json"}}

then the content of the pact looks like below, where the first message's contents and matching rule now seems correct.

{
  "consumer": {
    "name": "test@consumer"
  },
  "provider": {
    "name": "test@provider"
  },
  "messages": [
    {
      "description": "'some thing changed' event",
      "providerStates": [
        {
          "name": "test",
          "params": null
        }
      ],
      "contents": {
        "changed": {
          "id": "exampleId",
          "anotherId": "anotherId"
        }
      },
      "matchingRules": {
        "body": {
          "$.changed.id": {
            "match": "type"
          },
          "$.changed.anotherId": {
            "match": "type"
          }
        }
      },
      "metaData": {
        "content-type": "application/json"
      }
    },
    {
      "description": "'some thing else changed' event",
      "providerStates": [
        {
          "name": "test2",
          "params": null
        }
      ],
      "contents": {
        "changed": {
          "id": {
            "contents": "exampleId",
            "json_class": "Pact::SomethingLike"
          },
          "anotherId": {
            "contents": "anotherId",
            "json_class": "Pact::SomethingLike"
          }
        }
      },
      "matchingRules": {
      },
      "metaData": {
        "content-type": "application/json"
      }
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "2.0.0"
    }
  }
}
bethesque commented 3 years ago

Thanks, I'll have a look at it.

skaggmannen commented 3 years ago

I've also experienced the same issue, and from some bisecting I have pinpointed the version it was introduced in pact-ruby-standalone to 1.88.29. Hope this helps :)

bethesque commented 3 years ago

Thanks. Sorry, I haven't had my regular OSS day for a while. I have not forgotten about this!

bethesque commented 3 years ago

The latest version of pact-message and the pact-ruby-standalone/pact-cli have been released with the fix.