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

Provider test fails for gRPC when proto file has java_package instead of package #78

Open
svillegasz opened this issue Oct 28, 2024 · 0 comments

Comments

@svillegasz
Copy link

svillegasz commented Oct 28, 2024

The gRPC provider test does not work correctly when the proto file used to generate the pact includes an option java_package but lacks a package definition. The proto file is valid, and both the gRPC server and consumer test work as expected. However, the provider test fails with a "Method not found" error. It appears that the gRPC requests add a . (dot) before the service name specified in the proto file and in the pact, likely due to the missing package name.

Steps to Reproduce:

  1. In the pact-plugins repository, update the proto/area_calculator.proto file (link to proto file), replacing package area_calculator; with option java_package = "area_calculator";.
syntax = "proto3";

option java_package = "area_calculator";

option go_package = "io.pact/area_calculator";

service Calculator {
  rpc calculateOne (ShapeMessage) returns (AreaResponse) {}
  rpc calculateMulti (AreaRequest) returns (AreaResponse) {}
}

message ShapeMessage {
  oneof shape {
    Square square = 1;
    Rectangle rectangle = 2;
    Circle circle = 3;
    Triangle triangle = 4;
    Parallelogram parallelogram = 5;
  }
}

message Square {
  float edge_length = 1;
}

message Rectangle {
  float length = 1;
  float width = 2;
}

message Circle {
  float radius = 1;
}

message Triangle {
  float edge_a = 1;
  float edge_b = 2;
  float edge_c = 3;
}

message Parallelogram {
  float base_length = 1;
  float height = 2;
}

message AreaRequest {
  repeated ShapeMessage shapes = 1;
}

message AreaResponse {
  repeated float value = 1;
}
  1. Run the consumer test (link to consumer test) to generate the pact.
{
  "consumer": {
    "name": "grpc-consumer-jvm"
  },
  "interactions": [
    {
      "comments": {
        "testname": "io.pact.example.grpc.maven.PactConsumerTest.calculateRectangleArea(MockServer, SynchronousMessages)"
      },
      "description": "calculate rectangle area request",
      "interactionMarkup": {
        "markup": "```protobuf\nmessage ShapeMessage {\n    message .Rectangle rectangle = 2;\n}\n```\n\n```protobuf\nmessage AreaResponse {\n    repeated float value = 1;\n}\n```\n",
        "markupType": "COMMON_MARK"
      },
      "key": "c7fbe3ee",
      "pending": false,
      "pluginConfiguration": {
        "protobuf": {
          "descriptorKey": "4dd232df817d20316d8f28a658e82add",
          "service": "Calculator/calculateOne"
        }
      },
      "request": {
        "contents": {
          "content": "EgoNAABAQBUAAIBA",
          "contentType": "application/protobuf; message=ShapeMessage",
          "contentTypeHint": "BINARY",
          "encoded": "base64"
        },
        "matchingRules": {
          "body": {
            "$.rectangle.length": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "number"
                }
              ]
            },
            "$.rectangle.width": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "number"
                }
              ]
            }
          }
        },
        "metadata": {
          "contentType": "application/protobuf;message=ShapeMessage"
        }
      },
      "response": [
        {
          "contents": {
            "content": "CgQAAEBB",
            "contentType": "application/protobuf; message=AreaResponse",
            "contentTypeHint": "BINARY",
            "encoded": "base64"
          },
          "matchingRules": {
            "body": {
              "$.value.*": {
                "combine": "AND",
                "matchers": [
                  {
                    "match": "number"
                  }
                ]
              }
            }
          },
          "metadata": {
            "contentType": "application/protobuf;message=AreaResponse"
          }
        }
      ],
      "transport": "grpc",
      "type": "Synchronous/Messages"
    }
  ],
  "metadata": {
    "pact-jvm": {
      "version": "4.6.11"
    },
    "pactSpecification": {
      "version": "4.0"
    },
    "plugins": [
      {
        "configuration": {
          "4dd232df817d20316d8f28a658e82add": {
            "protoDescriptors": "CqYGChVhcmVhX2NhbGN1bGF0b3IucHJvdG8i6gEKDFNoYXBlTWVzc2FnZRIhCgZzcXVhcmUYASABKAsyBy5TcXVhcmVIAFIGc3F1YXJlEioKCXJlY3RhbmdsZRgCIAEoCzIKLlJlY3RhbmdsZUgAUglyZWN0YW5nbGUSIQoGY2lyY2xlGAMgASgLMgcuQ2lyY2xlSABSBmNpcmNsZRInCgh0cmlhbmdsZRgEIAEoCzIJLlRyaWFuZ2xlSABSCHRyaWFuZ2xlEjYKDXBhcmFsbGVsb2dyYW0YBSABKAsyDi5QYXJhbGxlbG9ncmFtSABSDXBhcmFsbGVsb2dyYW1CBwoFc2hhcGUiKQoGU3F1YXJlEh8KC2VkZ2VfbGVuZ3RoGAEgASgCUgplZGdlTGVuZ3RoIjkKCVJlY3RhbmdsZRIWCgZsZW5ndGgYASABKAJSBmxlbmd0aBIUCgV3aWR0aBgCIAEoAlIFd2lkdGgiIAoGQ2lyY2xlEhYKBnJhZGl1cxgBIAEoAlIGcmFkaXVzIk8KCFRyaWFuZ2xlEhUKBmVkZ2VfYRgBIAEoAlIFZWRnZUESFQoGZWRnZV9iGAIgASgCUgVlZGdlQhIVCgZlZGdlX2MYAyABKAJSBWVkZ2VDIkgKDVBhcmFsbGVsb2dyYW0SHwoLYmFzZV9sZW5ndGgYASABKAJSCmJhc2VMZW5ndGgSFgoGaGVpZ2h0GAIgASgCUgZoZWlnaHQiNAoLQXJlYVJlcXVlc3QSJQoGc2hhcGVzGAEgAygLMg0uU2hhcGVNZXNzYWdlUgZzaGFwZXMiJAoMQXJlYVJlc3BvbnNlEhQKBXZhbHVlGAEgAygCUgV2YWx1ZTJtCgpDYWxjdWxhdG9yEi4KDGNhbGN1bGF0ZU9uZRINLlNoYXBlTWVzc2FnZRoNLkFyZWFSZXNwb25zZSIAEi8KDmNhbGN1bGF0ZU11bHRpEgwuQXJlYVJlcXVlc3QaDS5BcmVhUmVzcG9uc2UiAEIqCg9hcmVhX2NhbGN1bGF0b3JaF2lvLnBhY3QvYXJlYV9jYWxjdWxhdG9yYgZwcm90bzM=",
            "protoFile": "syntax = \"proto3\";\n\noption java_package = \"area_calculator\";\n\noption go_package = \"io.pact/area_calculator\";\n\nservice Calculator {\n  rpc calculateOne (ShapeMessage) returns (AreaResponse) {}\n  rpc calculateMulti (AreaRequest) returns (AreaResponse) {}\n}\n\nmessage ShapeMessage {\n  oneof shape {\n    Square square = 1;\n    Rectangle rectangle = 2;\n    Circle circle = 3;\n    Triangle triangle = 4;\n    Parallelogram parallelogram = 5;\n  }\n}\n\nmessage Square {\n  float edge_length = 1;\n}\n\nmessage Rectangle {\n  float length = 1;\n  float width = 2;\n}\n\nmessage Circle {\n  float radius = 1;\n}\n\nmessage Triangle {\n  float edge_a = 1;\n  float edge_b = 2;\n  float edge_c = 3;\n}\n\nmessage Parallelogram {\n  float base_length = 1;\n  float height = 2;\n}\n\nmessage AreaRequest {\n  repeated ShapeMessage shapes = 1;\n}\n\nmessage AreaResponse {\n  repeated float value = 1;\n}\n"
          }
        },
        "name": "protobuf",
        "version": "0.4.0"
      }
    ]
  },
  "provider": {
    "name": "area-calculator-provider"
  }
}
  1. Using the generated pact, run the provider test (link to provider test).

Expected Behavior: The provider test should pass without requiring a package definition in the proto file, as the gRPC server and consumer test work as expected.

Actual Behavior: The provider test fails with the following error:
1) Verification Failed - gRPC error: status Operation is not implemented or not supported, message 'Method not found: .Calculator/calculateOne'

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

1 participant