mockserver&&模拟测试工具
安装
官方帮助:https://www.mock-server.com/
version: "3"
services:
mockserver:
image: mockserver/mockserver:mockserver-5.14.0
container_name: mockserver
restart: always
privileged: true
ports:
- "1080:1080"
environment:
- TZ=Asia/Shanghai
- MOCKSERVER_INITIALIZATION_JSON_PATH=/config/expectations.json # 系统启动时从配置文件加载期望
- MOCKSERVER_PERSISTED_EXPECTATIONS_PATH=/config/expectations.json # 持久化期望到配置文件
- MOCKSERVER_PERSIST_EXPECTATIONS=true # 开启期望配置持久化,默认情况是存放在内存的
volumes:
- ./config:/config
创建一个期望
curl --request PUT \
--url https://smart-ops-mock.saas.vppark.cn/mockserver/expectation \
--header 'Accept: */*' \
--header 'Accept-Encoding: gzip, deflate, br' \
--header 'Cache-Control: no-cache' \
--header 'Connection: keep-alive' \
--header 'Content-Length: 511' \
--header 'Content-Type: application/json' \
--header 'Host: smart-ops-mock.saas.vppark.cn' \
--header 'User-Agent: PostmanRuntime-ApipostRuntime/1.1.0' \
--data '{
"id":"/hello",
"httpRequest": {
"method": "GET",
"path": "/hello"
},
"httpResponse": {
"headers": {
"Content-Type": [
"application/json"
]
},
"statusCode": 200,
"body": {
"code": 200,
"message": "ok",
"data": {
"list": {
"a": "b",
"c": "d"
}
}
}
}
}'
处罚一个期望
curl --request GET \
--url https://smart-ops-mock.saas.vppark.cn/hello \
--header 'Accept: */*' \
--header 'Accept-Encoding: gzip, deflate, br' \
--header 'Cache-Control: no-cache' \
--header 'Connection: keep-alive' \
--header 'Host: smart-ops-mock.saas.vppark.cn' \
--header 'User-Agent: PostmanRuntime-ApipostRuntime/1.1.0'
删除一个期望
curl --request PUT \
--url https://smart-ops-mock.saas.vppark.cn/mockserver/clear \
--header 'Accept: */*' \
--header 'Accept-Encoding: gzip, deflate, br' \
--header 'Cache-Control: no-cache' \
--header 'Connection: keep-alive' \
--header 'Content-Length: 26' \
--header 'Content-Type: application/json' \
--header 'Host: smart-ops-mock.saas.vppark.cn' \
--header 'User-Agent: PostmanRuntime-ApipostRuntime/1.1.0' \
--data '{
"path": "/hello"
}'
已经增加的期望列表
curl --request PUT \
--url 'https://smart-ops-mock.saas.vppark.cn/mockserver/retrieve?type=active_expectations' \
--header 'Accept: */*' \
--header 'Accept-Encoding: gzip, deflate, br' \
--header 'Cache-Control: no-cache' \
--header 'Connection: keep-alive' \
--header 'Content-Length: 0' \
--header 'Host: smart-ops-mock.saas.vppark.cn' \
--header 'User-Agent: PostmanRuntime-ApipostRuntime/1.1.0'
系统状态
curl --request PUT \
--url https://smart-ops-mock.saas.vppark.cn/mockserver/status \
--header 'Accept: */*' \
--header 'Accept-Encoding: gzip, deflate, br' \
--header 'Cache-Control: no-cache' \
--header 'Connection: keep-alive' \
--header 'Content-Length: 0' \
--header 'Host: smart-ops-mock.saas.vppark.cn' \
--header 'User-Agent: PostmanRuntime-ApipostRuntime/1.1.0'
重置一切
既整个系统添加的内容全部没有了
curl --request PUT \
--url https://smart-ops-mock.saas.vppark.cn/mockserver/reset \
--header 'Accept: */*' \
--header 'Accept-Encoding: gzip, deflate, br' \
--header 'Cache-Control: no-cache' \
--header 'Connection: keep-alive' \
--header 'Content-Length: 0' \
--header 'Host: smart-ops-mock.saas.vppark.cn' \
--header 'User-Agent: PostmanRuntime-ApipostRuntime/1.1.0'