dpgui8229808 2018-03-14 16:33
浏览 42
已采纳

提供者未注册交互

I'm using the Pact Go implementation to try out contract testing. I've made a provider test that isn't working because I need to mock out my service's request to Twilio.

I've made one Pact object for the contract between my consumer and this provider, and then another one called twilioPact for the contract between my provider and Twilio. I've added an interaction for the POST to the Twilio endpoint, but in the pact.log I'm not seeing it get registered. My test is making the request correctly, but there's no interaction registered for it so I get the 500 error from the mock server.

Does anyone have any experience using Pact with a 'provider' that is also a 'consumer'?

EDIT: After talking with Matt Fellows I was informed that I was using Pact incorrectly, and shouldn't be trying to run a mock service while running a provider verification. I had suspected as much, but none of the examples I had seen were for a provider that had a dependency. I was able to get my provider verification to work by writing a consumer test and passing the generated pact file to the pact-stub-service to act as the mock to Twilio.

  • 写回答

1条回答 默认 最新

  • dongshi9489 2018-03-15 10:39
    关注

    Here's a few things to consider:

    1. It's better to have two separate contract tests between your client <-> Twilio Adapter, and Twilio Adapter <-> Twilio. It's possible to do what you're doing, but it will make the tests more complicated and probably harder to read/comprehend. Testing them in isolation gives you much more control.
    2. When doing the former contract test, rather then daisy chain another pact mock service for your Twilio Adapter's (Provider) dependency (Twilio), you're best using standard mock/stub tooling for this job - either code based mocks/doubles, service doubles (e.g. Mountebank) or the stub server shipped with Pact [1]. Don't forget you will get to validate these assumptions with the other contract test, so you're safe to do this.
    3. It's possible that because you have two mock servers running (one to mock the Twilio Adapter and another to mock Twilio) that your requests are being sent to the same mock service, and getting all tangled up

    [1] Here is are the list of binaries etc. that are shipped with pact-go:

        tree -L 3 /path/to/pact-go
    
        .
        ├── pact
        │   ├── README.md
        │   ├── bin
        │   │   ├── pact-broker
        │   │   ├── pact-mock-service
        │   │   ├── pact-provider-verifier
        │   │   ├── pact-publish
        │   │   └── pact-stub-service
        │   └── lib
        │       ├── app
        │       ├── ruby
        │       └── vendor
        └── pact-go
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算