cli-anything-wiremock
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOverview
概述
cli-anything-wiremock/__admin/WireMock is commonly used in integration testing environments to replace real HTTP backends with controllable mock responses.
cli-anything-wiremock/__admin/WireMock通常用于集成测试环境,以可控的模拟响应替代真实的HTTP后端。
Command Groups
命令组
stub
— Manage HTTP stub mappings
stubstub
— 管理HTTP存根映射
stub| Command | Description |
|---|---|
| List all registered stubs |
| Get details of a specific stub by UUID |
| Create a stub from a JSON string |
| Quickly create a stub: METHOD URL STATUS_CODE |
| Delete a stub by UUID |
| Reset all stubs to the defaults on disk |
| Persist in-memory stubs to disk |
| Import stubs from a JSON file |
| 命令 | 描述 |
|---|---|
| 列出所有已注册的存根 |
| 通过UUID获取特定存根的详细信息 |
| 通过JSON字符串创建存根 |
| 快速创建存根:METHOD URL STATUS_CODE |
| 通过UUID删除存根 |
| 将所有存根重置为磁盘上的默认值 |
| 将内存中的存根持久化到磁盘 |
| 从JSON文件导入存根 |
request
— Inspect served requests
requestrequest
— 检查已处理的请求
request| Command | Description |
|---|---|
| List recent served requests |
| Find requests matching a JSON pattern |
| Count requests matching a JSON pattern |
| List requests that matched no stub (404s) |
| Clear the request journal |
| 命令 | 描述 |
|---|---|
| 列出最近处理的请求 |
| 查找匹配JSON模式的请求 |
| 统计匹配JSON模式的请求数量 |
| 列出未匹配到任何存根的请求(404请求) |
| 清空请求日志 |
scenario
— Stateful scenario management
scenarioscenario
— 有状态场景管理
scenario| Command | Description |
|---|---|
| List all scenarios and current states |
| Set scenario NAME to STATE |
| Reset all scenarios to their initial state |
| 命令 | 描述 |
|---|---|
| 列出所有场景及其当前状态 |
| 将指定NAME的场景设置为STATE状态 |
| 将所有场景重置为初始状态 |
record
— Record traffic from a real backend
recordrecord
— 录制真实后端的流量
record| Command | Description |
|---|---|
| Start proxying + recording to TARGET_URL |
| Stop recording, return captured stubs |
| Check if currently recording |
| Snapshot in-memory requests as stubs |
| 命令 | 描述 |
|---|---|
| 启动代理并录制流量到TARGET_URL |
| 停止录制,返回捕获的存根 |
| 检查当前是否正在录制 |
| 将内存中的请求快照为存根 |
settings
— Global server settings
settingssettings
— 全局服务器设置
settings| Command | Description |
|---|---|
| Get current global WireMock settings |
| Show WireMock server version |
| 命令 | 描述 |
|---|---|
| 获取当前WireMock全局设置 |
| 显示WireMock服务器版本 |
Top-level commands
顶级命令
| Command | Description |
|---|---|
| Check if WireMock is running |
| Full reset: stubs + requests + scenarios |
| Gracefully shut down the WireMock server |
| 命令 | 描述 |
|---|---|
| 检查WireMock是否正在运行 |
| 完全重置:存根 + 请求 + 场景 |
| 优雅关闭WireMock服务器 |
Key Examples
关键示例
bash
undefinedbash
undefinedCheck connectivity
Check connectivity
cli-anything-wiremock status
cli-anything-wiremock status
Create a stub using quick form
Create a stub using quick form
cli-anything-wiremock stub quick GET /api/users 200 --body '[{"id":1}]'
cli-anything-wiremock stub quick GET /api/users 200 --body '[{"id":1}]'
Create a stub using full JSON
Create a stub using full JSON
cli-anything-wiremock stub create '{
"request": {"method": "POST", "url": "/api/orders"},
"response": {"status": 201, "body": "{"id":99}"}
}'
cli-anything-wiremock stub create '{
"request": {"method": "POST", "url": "/api/orders"},
"response": {"status": 201, "body": "{"id":99}"}
}'
Verify a POST was made exactly once
Verify a POST was made exactly once
cli-anything-wiremock --json request count '{"method":"POST","url":"/api/orders"}'
cli-anything-wiremock --json request count '{"method":"POST","url":"/api/orders"}'
→ {"count": 1}
→ {"count": 1}
Scenario: advance state
Scenario: advance state
cli-anything-wiremock scenario set "cart-flow" "item-added"
cli-anything-wiremock scenario set "cart-flow" "item-added"
Record a real backend
Record a real backend
cli-anything-wiremock record start https://api.example.com
cli-anything-wiremock record start https://api.example.com
... make requests ...
... make requests ...
cli-anything-wiremock record stop
undefinedcli-anything-wiremock record stop
undefinedAgent Guidance
Agent使用指南
Always use --json
in agent contexts
--json在Agent环境中始终使用--json
参数
--jsonUse for all invocations in scripts or agent tool calls. JSON output varies by command type (these are distinct response types, not an envelope wrapping all responses):
--jsonbash
undefined在脚本或Agent工具调用中执行所有命令时,请使用参数。JSON输出会根据命令类型有所不同(这些是不同的响应类型,并非包裹所有响应的信封格式):
--jsonbash
undefinedData commands return raw WireMock API JSON directly:
数据类命令直接返回原始WireMock API JSON:
cli-anything-wiremock --json stub quick GET /api/hello 200 --body '{"hello":"world"}'
cli-anything-wiremock --json stub quick GET /api/hello 200 --body '{"hello":"world"}'
→ {"id": "abc-123", "request": {...}, "response": {...}, ...}
→ {"id": "abc-123", "request": {...}, "response": {...}, ...}
cli-anything-wiremock --json stub list
cli-anything-wiremock --json stub list
→ {"mappings": [...], "total": N}
→ {"mappings": [...], "total": N}
Void commands (delete, reset, save) return:
无返回值命令(delete、reset、save)返回:
→ {"status": "ok"}
→ {"status": "ok"}
Errors return:
错误时返回:
→ {"status": "error", "message": "Connection refused"}
→ {"status": "error", "message": "Connection refused"}
undefinedundefinedConnection via environment
通过环境变量配置连接
Set connection params via environment variables before calling any command:
bash
export WIREMOCK_HOST=localhost
export WIREMOCK_PORT=8080在调用任何命令之前,通过环境变量设置连接参数:
bash
export WIREMOCK_HOST=localhost
export WIREMOCK_PORT=8080Workflow pattern for test verification
测试验证的工作流模式
- Set up stubs before running the system under test:
bash
cli-anything-wiremock --json stub quick POST /api/payment 200 --body '{"success":true}' - Run the system under test.
- Verify interactions:
bash
cli-anything-wiremock --json request count '{"method":"POST","url":"/api/payment"}' - Clean up:
bash
cli-anything-wiremock reset
- 在运行被测系统之前设置存根:
bash
cli-anything-wiremock --json stub quick POST /api/payment 200 --body '{"success":true}' - 运行被测系统。
- 验证交互:
bash
cli-anything-wiremock --json request count '{"method":"POST","url":"/api/payment"}' - 清理环境:
bash
cli-anything-wiremock reset
Error handling
错误处理
Non-zero exit code on all errors. In mode, errors return . Success returns the raw WireMock API response.
--json{"status": "error", "message": "..."}所有错误都会返回非零退出码。在模式下,错误会返回。成功时则返回原始WireMock API响应。
--json{"status": "error", "message": "..."}