grpc-wiremock

0
3 года назад
4 года назад
4 года назад
4 года назад
4 года назад
6 лет назад
4 года назад
5 лет назад
4 года назад
4 года назад
4 года назад
4 года назад
README.md

Stability: Maintenance Docker Cloud Build Status Docker Image Version (tag latest semver)

Overview

grpc-wiremock is a mock server for GRPC services implemented as a wrapper around the WireMock http server.

How It Works

grpc-wiremock starts a gRPC server generated based on provided proto files which will convert a proto grpc request to JSON and redirects it as a POST request to the WireMock then converts a http response back to grpc proto format.

  1. GRPC server works on
    tcp://localhost:50000
  2. WireMock server works on
    http://localhost:8888

Quick Usage

  1. Run
  1. Stub
  1. Check

Should get response:

Stubbing

Stubbing should be done via WireMock JSON API

Error mapping

Default error (not

200 OK
) mapping is based on https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto :

HTTP Status CodeGRPC Status
400 Bad RequestINVALID_ARGUMENT
401 UnauthorizedUNAUTHENTICATED
403 ForbiddenPERMISSION_DENIED
404 Not FoundNOT_FOUND
409 ConflictALREADY_EXISTS
429 Too Many RequestsRESOURCE_EXHAUSTED
499 Client Closed RequestCANCELLED
500 Internal Server ErrorINTERNAL
501 Not ImplementedUNIMPLEMENTED
503 Service UnavailableUNAVAILABLE
504 Gateway TimeoutDEADLINE_EXCEEDED

And could be overridden or augmented by overriding or augmenting the following properties:

For example:

How To:

1. Configure gRPC server

Currently, following grpc server properties are supported:

Could be used like this:

2. Configure WireMock server

WireMock server may be configured by passing command line options prefixed by

wiremock_
:

3. Mock server-side streaming:

Given the service:

Then the following stub may be provided, where

response.headers.streamSize
specifies how many responses should be returned during the stream (
1
- if absent).

The current response iteration number is available in

request.headers.streamCursor
:

4. Speed up container start

In case you don't need to change proto files, you can build your own image with precompiled protos.
See an example

5. Use with snappy compresser/decompresser

Snappy support can be enabled using

EXTERNAL_CODECS
env variable as follows:

Also in docker-compose:

*gzip compression supported by default

6. Use in load testing

To increase performance some Wiremock related options may be tuned either directly or by enabling the "load" profile. Next two commands are identical:

7. Preserving proto field names in stubs

By default, stub mappings must have proto fields references in lowerCamlCase, e.g. proto field

user_id
must be referenced as:

To preserve proto field names the following env variable could be used: