testinggospels / camouflage

Camouflage is a backend mocking tool for HTTP, gRPC, Websockets and Thrift protocols, which helps you carry out your front end prototyping, unit testing, functional/performance testing in silos, in absence of one or more Microservices/APIs.
https://testinggospels.github.io/camouflage/
MIT License
281 stars 26 forks source link

GRPC - cannot simulate gRPC error status, false positive mock response #188

Open szokebarnabas opened 2 years ago

szokebarnabas commented 2 years ago

Describe the bug Hi, apologies in advance if the answer to my question is trivial but I don't have any experience with gRpc and protobufs.

What I would like to achieve is:

To Reproduce Steps to reproduce the behavior:

  1. Mock File Content
    https://github.com/stargate/stargate/tree/master/grpc-proto/proto
  2. File structure:

mocks:

./mocks/stargate/Stargate/ExecuteBatch.mock

protos:

./protos/query.proto
./protos/stargate.proto
  1. Docker-compose:
    
    version: "3.9"
    networks:
    camouflage:
    driver: bridge

volumes: prometheus_data: {} grafana_data: {} camouflage_data: {}

services: camouflage_ui: image: shubhendumadhukar/camouflage-filemanager:latest container_name: camouflage_ui_2 volumes:


4. ExecuteBatch.mock:

{ "warnings": [ "hello" ], "schema_change": { "change_type": "CREATED" }, "result_set": { "columns": [ { "name": "my column", "type": { "basic": "ASCII" } } ], "rows": [ { "values": [ { "string": "hello world" } ] } ] } }


6. Execute the following gRpc request:

grpcurl -v -d '{"queries":[{"cql":"UPDATE bookmarking.bookmarks USING TTL :ttl AND TIMESTAMP :timestamp SET streamPosition = :streamposition, created = :created WHERE pvid = :pvid AND providerterritory = :providerterritory AND provider = :provider AND householdId = :householdid AND timeBucket = :timebucket and personaId = :personaid;"}]}' -proto query.proto -proto stargate.proto -plaintext localhost:4312 stargate.Stargate/ExecuteBatch


Response:

Resolved method descriptor: // Executes a batch of CQL queries. rpc ExecuteBatch ( .stargate.Batch ) returns ( .stargate.Response );

Request metadata to send: (empty)

Response headers received: content-type: application/grpc+proto date: Fri, 02 Sep 2022 07:38:52 GMT grpc-accept-encoding: identity,deflate,gzip

Response contents: { "warnings": [ "hello" ], "schemaChange": { "changeType": "DROPPED" } }

Response trailers received: (empty) Sent 1 request and received 1 response



**Expected behavior**
It's should be possible to define request matchers and return responses accordingly.

Thanks,
Barnabas
shubhendumadhukar commented 2 years ago

Hi @szokebarnabas,

It's should be possible to define request matchers and return responses accordingly.

Could you please elaborate with an example, what kind of request matchers are you referring to?

scvnc commented 2 years ago

I'm unsure if this is a bug or if this isn't documented or supported.

Take HTTP: Camouflage mocks HTTP by having you provide the entire HTTP response in your *.mock file, including status code headers, etc. This would allow me to test scenarios like when the server responds with a HTTP 400, then I can verify my app behaves accordingly.

Similarly in gRPC we have status codes and I may want to do the same thing where I configure camouflage to return GRPC 16 "Unauthorized" so that I can verify my app behaves accordingly when such a thing happens. I don't see it documented.

Since I'm proxying with envoy to camouflage, I also would like to set headers but I know I may be asking for too much there.