为您的 JSON API 提供简单、专注且自动化的消费者驱动合约测试
copy+paste one of the following commands in your terminal.
Linux x64
curl -Lo rumpel https://github.com/hellgrenj/Rumpel/releases/download/v0.4.2/rumpel-linux-x64 && \
sudo install rumpel /usr/local/bin/macOS arm64
curl -Lo rumpel https://github.com/hellgrenj/Rumpel/releases/download/v0.4.2/rumpel-macos-arm64 && \
sudo install rumpel /usr/local/bin/win x64
download the latest exe, rename it rumpel.exe and put it in your PATH.
Docker:
https://hub.docker.com/r/hellgrenj/rumpel.
Helm (Experimental!):
https://github.com/hellgrenj/charts/tree/main/rumpel-mock#install-and-test
(only for mocking services right now..)
Record a consumer-driven contract against a known and reproducible state of the API and system under test (SUT). Use the created contract to verify that the API still works for this specific consumer when making changes to the API. Make sure you verify against the same SUT-state as you recorded against.
You can also use the contract on the consumer side to mock the provider in local development. In this mode Rumpel will validate the consumer requests, making sure that the consumer upholds its end of the contract.
rumpel --record-contract --target-api=http://localhost:8080 --contract-name=msA-msBrumpel --verify-contract --contract-path=./contracts/msA-msB.rumpel.contract.jsonrumpel --mock-provider --contract-path=./contracts/msA-msB.rumpel.contract.json
Demo application: artlab
a demo of Docker, Kubernetes and Skaffold where Rumpel is used to record a contract and mock a dependency.
rumpel --record-contract --target-api=http://localhost:8080 --contract-name=msA-msBRumpel listens on port 8181 or the number set in the environment variable RUMPEL_PORT
screenshot
rumpel --verify-contract --contract-path=./contracts/msA-msB.rumpel.contract.jsonContract verification supports bearer tokens and you can skip certain assertions with ignore-flags.
Run the --help command for more information.
This should be a part of the Providers CI/CD pipeline, see ./tests/integration for an example on how to do this with docker-compose.
screenshots
Customizations
You can customize the verification per transaction by manually adding Customizations in the contract. In the example below a Customization is added that instructs Rumpel to ignore the object property name. A Customization has 3 properties: The name of the target Object Property, The name of the Action and at what Depth in the JSON the property is found. (is it a first level property or a property in a nested object..)
Available Customizations
rumpel --mock-provider --contract-path=./contracts/msA-msB.rumpel.contract.jsonThis can be used in local dev environments to mock dependencies, see ./tests/integration for an example of how to do this with docker-compose or the repository artlab for an example of how to do this with Skaffold. You can also mock services in different k8s-clusters with this (experimental) helm chart: https://github.com/hellgrenj/charts/tree/main/rumpel-mock#install-and-test
Rumpel listens on port 8181 or the number set in the environment variable RUMPEL_PORT.
In this mode Rumpel validates the requests sent by the consumer.
screenshot
Simulated conditions
You can simulate conditions per transaction when mocking a provider by manually adding SimulatedConditions in the contract. Every simulated condition has a Type and a Value, see the screenshot below for an example. You can add one or several simulated conditions, in the example below we are adding 3 different conditions.
Available Types of Simulated conditions and the expected Values
--record-contract or the shorthand -r--verify-contract or the shorthand -v--mock-provider or the shorthand -m--help or the shorthand -h--version
You need the following installed on your dev machine:
There are both unit tests and integration tests. Check the ./tests folder.
Run unit tests in ./tests/unit with dotnet test
Run integration tests in ./tests/integration with deno run -A tests.ts
Run ALL tests in ./tests with deno run -A run_all_tests.ts
暂无开放 Issues,或尚未同步最近议题。