mountebank-grpc icon indicating copy to clipboard operation
mountebank-grpc copied to clipboard

Unable to match predicate of path and value for grpc request

Open burigolucas opened this issue 2 years ago • 1 comments

Hi there, first of all thanks a lot for this plugin to bring grpc to mountebank. Hopefully you are still maintaining this project and could help to sort out an issue related to matching precicates for the grpc request. I have posted the original question on stackoverflow. Below is the question replicated for documenting it here in the project:

I am using the grpc plugin to create stubs for grpc requests. It works very well when matching the path only. However, I am facing issues to match both the path and the value. In particular, I am using the jsonpath to select the fields to match. Here is a sample o the request:

{
  "path": "/service.DataProvider/ReadData",
  "value": {
    "identifiers": [
      {
        "unique_id": "unset",
        "data_id": "point1",
        "system_id": "mock"
      }
    ],
    "start_time": {
      "seconds": "1650431509",
      "nanos": 0
    },
    "end_time": {
      "seconds": "1650431569",
      "nanos": 0
    }
  }
}

and the predicates:

        "predicates": [
        {
            "deepEquals": {
              "path": "/service.DataProvider/ReadData"
            }
          },
          {
            "jsonpath": {
              "selector": "$.identifiers[0].data_id"
            },
            "deepEquals": {
              "value": "point1"
            }
          },
          {
            "jsonpath": {
              "selector": "$.identifiers[0].system_id"
            },
            "deepEquals": {
              "value": "mock"
            }
          }
        ]

Any idea of what is wrong on the predicates above? Any comments will be highly appreciated. Thanks!

burigolucas avatar Apr 20 '22 08:04 burigolucas

Hey @burigolucas , I honestly don't maintain this project that much... hope you're getting some use out of it though.

As for your question... it's going to be a bit before I can actually try to test this. However, when using a plugin with mountebank... the plugin sends the entire request to the mountebank server where mountebank has all of the logic for the predicates. Basically mountebank handles matching the stubs and telling the plugin what response to send back.

In your case I think it should use the jsonpath of the request where the selector might match $..identifiers[0].data_id or $.value.identifiers[0].data_id. If it doesn't though, I'll have to create an example and take a look.

Let me know if that helps. Thanks!

cbrz avatar Apr 21 '22 22:04 cbrz