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

Tavern GRPC support #438

Merged
merged 86 commits into from
Jan 20, 2024
Merged

Conversation

kiril-me
Copy link
Contributor

@kiril-me kiril-me commented Sep 5, 2019

GRPC client support.

test_name: GRPC message echo
grpc: 
  connect:
    host: localhost
    port: 50051
    tls: false

stages:
  - name: Echo text
    grpc_request:
      service: helloworld.Greeter/SayHello
      body:
        name: "John"
    grpc_response:
      body:
        message: "Hello, John!"

GRPC client connection is described using host, port, tls.

On stage level, grpc_request create a request with the body. service is the full GRPC service name. Besides, there is a possibility to change the host inside request:

- name: Echo text
    grpc_request:
      host: myhost:50052
      service: helloworld.Greeter/SayHello
      body:
        name: "John"

Similar to http response GRPC plugin hasgrpc_response.
To verify error code you can use status and detail:

stages:
  - name: Echo text
    grpc_request:
      service: helloworld.Greeter/SayHello
    grpc_response:
      status: INVALID_ARGUMENT
      details: "Name was not provided"

The main problem with GRPC what client should know the protobuf message to make request and read the response.

GRPC plugin supports several features to discover protobuf message structure:

  1. Provide protos file (https://developers.google.com/protocol-buffers/docs/proto3).
grpc:
  connect:
    ...
  proto:
    source: my-proto-folder

The tavern will automatically compile protos and start using them.
2. In case you already have Python generated classes (protoc output https://developers.google.com/protocol-buffers/docs/pythontutorial). Setup the proto module location.

grpc:
  connect:
    ...
  proto:
    module: proto-folder

Using proto source file actually generate GRPC python file inside the default module (proto) folder. But you can change it update module to custome name.

grpc:
  connect:
    ...
  proto:
    source: my-proto-folder
    module: py-generated-proto
  1. The plugin will try automatically to request protobuf structure from the server using reflections (https://github.com/grpc/grpc/blob/master/doc/server-reflection.md). Just skip proto section.

To send metadata with request GRPC has metadata map.

test_name: GRPC message echo
grpc: 
  connect:
    host: localhost
    port: 50051
    tls: false
  metadata:
    user: John

@kiril-me kiril-me mentioned this pull request Sep 5, 2019
@michaelboulton
Copy link
Member

Sorry for not leaving a comment on this earlier, but as mentioned in #419 (comment) I don't really want to merge something in that I won't be able to maintain. What we could do is put this as a 'tavern-grpc' plugin into a separate repository under the 'taverntesting' github organisation, and add the schema and a 'stub' implementation in Tavern that just raises an error and points to that repository?

@michaelboulton michaelboulton merged commit 5185f53 into taverntesting:master Jan 20, 2024
8 checks passed
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

Successfully merging this pull request may close these issues.

2 participants