Hi! I have a question about struct matching, and I...
# pact-plugins
b
Hi! I have a question about struct matching, and I'm feeling kind of stumped. I have a proto with a
struct
field, e.g.
Copy code
message Request {
  string name = 1;
  google.protobuf.Struct params = 2;
}
In my test, I am creating a new struct
Copy code
params, err := structpb.NewStruct(map[string]any{"kind": "general", "message": "test" })
and then marshaling it to JSON. The string I am passing to
withContents
looks like this
Copy code
{
  "pact:proto": "whatever.proto",
  "pact:proto-service": "Service/Endpoint",
  "pact:content-type": "application/protobuf",
  "request": {
    "name": "name",
    "params": {
      "kind": "general",
      "message": "test"
    }
  },
  "response": {
    "responses": [
      {
        "success": true,
        "id": "test123"
      }
    ]
  }
}
I run the test once and get this error
Copy code
Received generate templates error rpc error: code = FailedPrecondition desc = Failed to match the request message - BodyMismatches({"$.params": [BodyMismatch { path: "$.params.fields.key", expected: Some(b"\"message\""), actual: Some(b"\"kind\""), mismatch: "Expected 'kind' (String) to be equal to 'message' (String)" }, BodyMismatch { path: "$.params.fields.value.string_value", expected: Some(b"\"test\""), actual: Some(b"\"general\""), mismatch: "Expected 'general' (String) to be equal to 'test' (String)" }]})
and then I run the test again (changing nothing, with exact same contents string) and it passes
My best guess is that it's doing something weird with struct keys and ordering but I'm not sure what or how to fix it
r
Yeah, it looks like it is getting confused, as I think a google.protobuf.Struct is implemented as a union type or an enum. It may need special handling.
b
Does anyone have any suggestions for how to handle this? I did a preliminary dive into the
matching
code but didn't get very far. I also looked into the matching docs to see if there was something I could use there, but it seems like that's geared more towards primitives. We have a bunch of teams using
google.protobuf.Struct
in their proto files, so this is a pretty big blocker for us 😕
r
Sorry, I have been dealing with the provider state issue with the gRPC plugin. I'll investigate this for you, but I probably won't get to it before early next week.
m
Mind raising an issue on https://github.com/pactflow/pact-protobuf-plugin/ Becca for us to investigate please?
b
Oh ya, sometime in the next few weeks is totally fine! Right now I'm able to get away with using a struct with only a single field – no ordering problems there 😂 And happy to raise an issue – thanks both for being so responsive! I'll link it here once I create it
😬 1