契约测试
示例:
详情

实践过程
安装依赖
sudo yum install gcc python3-devel
pip3 install pytest pact-python flask json5
pip3 install --upgrade httpcore requests
运行程序
[root@VM-0-4-centos ~]# cd /home/klc/pact_study/broker/
[root@VM-0-4-centos broker]# docker-compose up -d
...
Creating broker_postgres_1 ... done
Creating broker_broker_app_1 ... done
Creating broker_nginx_1 ... done
登录Pact-Broker网站
pactbroker/pactbroker
具体操作过程
启动Pact-Broker,支持网站访问
[root@VM-0-4-centos pact_study]# ./pact.sh start_broker
Starting Pact Broker
Creating network "broker_default" with the default driver
启动Provider提供接口访问
[root@VM-0-4-centos pact_study]# ./pact.sh start_provider
Starting Provider App
* Serving Flask app 'user-app' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:5001/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 962-565-275
运行消费者契约测试,生成契约文件
备注:
vi /etc/profile #添加export PYTHONPATH=$PYTHONPATH:/home/klc/pact_study
source /etc/profile
[root@VM-0-4-centos pact_study]# ./pact.sh run_consumer_test
Runing Consumer Test
=============================================== test session starts ================================================
platform linux -- Python 3.6.8, pytest-7.0.1, pluggy-1.0.0
rootdir: /home/klc/pact_study/tests
plugins: anyio-3.6.2
collected 1 item
运行生产者契约测试,验证契约文件
[root@VM-0-4-centos pact_study]# ./verify_pact.sh v1 http://localhost:5001 http://localhost:5002 http://127.0.0.1:5300
