英文:
Allow multiple provider states with parameters ( Golang )
问题
我们的团队(包括我自己和其他两名开发人员)在过去的一周左右对PACT进行了探索,其中一个关注的领域是没有能力将参数与提供者状态关联起来。由于缺乏这个关键功能(计划在版本3发布中),我们可能无法得到各自服务子团队的支持。
@MattFellows - 你对版本3何时可用于Go有什么预测?有没有可能提前获得这个功能?
允许使用参数的多个提供者状态
在之前的版本中,提供者状态被定义为一个描述性字符串。没有办法推断出状态所需的数据,除非将值编码到描述中。
{
"providerState": "存在一个名为Mary的鳄鱼,并且用户Fred已登录"
}
更改后的形式为:
{
"providerStates": [
{
"name": "存在一个名为的鳄鱼",
"params": {"name" : "Mary"}
}, {
"name": "用户已登录",
"params" : { "username" : "Fred"}
}
]
}
英文:
As our team ( namely myself and two other developers ) spiked on PACT past week or so, one of the areas of concern is not having the ability associate parameters to provider states. The absence of this key feature ( which is slated for version 3 release ), we likely will not get buy in from each of our respective service sub-teams.
@MattFellows - Any projections on when version 3 might be available for Go? Any chance we can get this feature earlier?
Allow multiple provider states with parameters
In previous versions, provider states are defined as a descriptive string. There is no way to infer the data required for the state without encoding the values into the description.
{
"providerState": "an alligator with the given name Mary exists and the user Fred is logged in"
}
The change would be:
{
"providerStates": [
{
"name": "an alligator with the given name exists",
"params": {"name" : "Mary"}
}, {
"name": "the user is logged in",
"params" : { "username" : "Fred"}
}
]
}
答案1
得分: 2
你是正确的,直到版本3才会提供这个功能。
然而,你仍然可以实现你想要的效果。状态本身只是一个指向提供者上某个数据集的消费者的句柄,这可以是一对一或一对多的映射,完全由你决定。
通常,在验证期间,提供者会被通知状态,然后设置一个测试数据夹具(通常是填充数据库),根据该参考设置整个系统的“状态”,以便运行消费者测试。
虽然传递参数和多个状态的能力很好,但它是一个相对高级的功能,我非常怀疑这会是团队遇到的第一个问题。我自己从未需要使用过它们。
关于这个问题,你可以看一下项目中的gin代码,这是一个简单但有效的示例。
英文:
You are correct in that it won't be available until version 3.
You can still achieve what you are after, however. The state itself is just a handle for the Consumer to some set of data on the Provider - that can be a one-to-one or one-to-many mapping - it's completely up to you.
Typically the Provider is notified of the state during verification, it will then setup a test data fixture (often seeding a database) that sets up the 'state' of the entire system based on that reference, which allows the Consumer test to run.
Whilst the ability to pass through parameters and multiple states is nice, it's somewhat an advanced feature and I very much doubt this will be the first problem you run into as a team. I've never needed to use them myself.
For a crude but effective example of this, take a look at the gin code in the examples folder of the project.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论