grpc-wiremock is a tool for mocking server API. It provides
- simultaneous work with multiple APIs;
- mocking of grpc (protobuf) API;
- generating mocks by proto and openapi files;
- hot reload on contract changes.
grpc-wiremock is based on Wiremock, so it provides the all its power of matchers.
Also it inherites Wiremock GUI made by holomekc.
Here you can compare the functionality with existing solutions.
Check out our wearable repo with an example service.
There you will find how the service interacts with the mock and a docker-compose file for quick startup.
MOCKS_PATH="$(PWD)/test/wiremock"
CERTS_PATH="$(PWD)/certs"
CONTRACTS_PATH="$(PWD)/deps"
WIREMOCK_GUI_PORT=9000
# grpc-wiremock supports multiple APIs simultaneously.
# This means that the another APIs will go up
# on port 8001, 8002, etc.
YOUR_MOCK_API=8000
docker run \
-p ${WIREMOCK_GUI_PORT}:${WIREMOCK_GUI_PORT} \
-p ${YOUR_MOCK_API}:${YOUR_MOCK_API} \
-v ${MOCKS_PATH}:/home/mock \
-v ${CERTS_PATH}:/etc/ssl/mock/share \
-v ${CONTRACTS_PATH}:/proto \
SberMarket-Tech/grpc-wiremock@latest
To view status and API mocks
- Open Supervisor GUI on http://localhost:9000.
- Open Wiremock GUI on http://localhost:8000/__admin/webapp
In general, grpc-wiremock contains two main components.
You can read more about each of them here:
In the diagram you can see how your requests are distributed within the grpc-wiremock container.
You can also read about performance with multiple mock APIs here.
To develop Dockerfile
run ./dev/watch_build_image.sh
.
It will monitor changes you'are adding to Dockerfile
and rebuild local image
with tag docker.io/sbermarkettech/grpc-wiremock:dev
.
To develop golang code
-
Build
Dockerfile
once - run command:./dev/build_image.sh
-
Start docker container based on the built image:
make -C ./dev/example/ compose-up compose-logs
-
Log into docker container:
make -C ./dev/example/ compose-exec
-
Change
dev/watch_wiremock.sh
for your needs,
i.e. set-build
command to rebuild and install grpc2http:CompileDaemon -color -log-prefix \ -build='make install -C cmd/grpc2http' \ -command='bash ./dev/init_wiremock.sh'
-
Run
./dev/watch_wiremock.sh
inside docker container
When you change code it will restart wiremock to new version of code -
Make a request to wiremock:
grpcurl -H 'TestHeader: check' \ -insecure --authority push-sender \ -d '{"uuid": "1234", "message": "foo"}' \ 127.0.0.1:3009 push_sender.PushSender/Notify
To release new version
- Create new release on github in semver format, i. e.
v1.1.4
. - GitHub actions will build docker image and upload it to DockerHub SberMarket-Tech grpc-wiremock.
grpc-wiremock is under the Apache License, Version 2.0. See the LICENSE file for details.