Dsl 空手道比赛的最佳方式是使用==&引用;及;包括「;使用通用脚本

Dsl 空手道比赛的最佳方式是使用==&引用;及;包括「;使用通用脚本,dsl,karate,Dsl,Karate,这个问题是由一个 假设我们实现的服务器v1和v2响应如下所示 * def v1Response = { id: "1", name: "awesome" } * def v2Response = { id: "2", name: "awesome", value: "karate" } * def v1Schema = { id: "#string", name: "#string } * def v2Schema = { id: "#string", name: "#string, valu

这个问题是由一个

假设我们实现的服务器v1和v2响应如下所示

* def v1Response = { id: "1", name: "awesome" }
* def v2Response = { id: "2", name: "awesome", value: "karate" }
* def v1Schema = { id: "#string", name: "#string }
* def v2Schema = { id: "#string", name: "#string, value: "#string" }
* match response ==/contains schema <--- should be able to test all above three cases above and they must pass. 
类似地,我们定义v1和v2的客户机模式如下

* def v1Response = { id: "1", name: "awesome" }
* def v2Response = { id: "2", name: "awesome", value: "karate" }
* def v1Schema = { id: "#string", name: "#string }
* def v2Schema = { id: "#string", name: "#string, value: "#string" }
* match response ==/contains schema <--- should be able to test all above three cases above and they must pass. 
根据以上给定的数据,我只想在一个通用行中测试以下三种情况,它们必须通过测试

1. * match v1Response == v1Schema
2. * match v2Response == v2Schema 
3. * match v2Response contains v1Schema
使用一个通用行,如下所示

* def v1Response = { id: "1", name: "awesome" }
* def v2Response = { id: "2", name: "awesome", value: "karate" }
* def v1Schema = { id: "#string", name: "#string }
* def v2Schema = { id: "#string", name: "#string, value: "#string" }
* match response ==/contains schema <--- should be able to test all above three cases above and they must pass. 
*匹配响应==/contains架构看起来您好像忘记了
contains
:p

* def schemas =
"""
{
  v1: { id: "#string", name: "#string" },
  v2: { id: "#string", name: "#string", value: "#string" }
}
"""

* def env = 'v1'
* def response = { id: "1", name: "awesome" }
* match response contains karate.filterKeys(schemas[env], response)

* def response = { id: "2", name: "awesome", value: "karate" }
* match response contains karate.filterKeys(schemas[env], response)

* def env = 'v2'
* def response = { id: "1", name: "awesome" }
* match response contains karate.filterKeys(schemas[env], response)

* def response = { id: "2", name: "awesome", value: "karate" }
* match response contains karate.filterKeys(schemas[env], response)

注:第一个和第二个案例使用“==”not“contains”进行匹配,因此您建议的解决方案并不正确(我可以使用contains来通过所有三个案例,但这不是我想要的)。如果我们不能做到这一点,那么我将不得不维护两个单独的分支,它们之间的唯一区别是“==”vs“contains”。使用“==”进行匹配的概念是在开发过程中找到早期的bug/额外的键,然后在转移到生产环境时,我们可以使用contains进行匹配。也许空手道的简单性在这里给了人们很大的希望:)要说服你接受我提出的解决方案是不是要求太多了?如果你想要“向后兼容”,没有更好的方法了,请尝试使用上面的示例,并展示如何使语法工作<代码>维护两个独立的分支机构
-强烈反对。关于如何处理不同的环境,我已经提供了足够的选项。在两年半的时间里,你是唯一一个提出这个要求的人,最后-空手道是开源的,所以如果你对它有强烈的感觉,请提供修复:)不确定其他人一直以来是如何做的,但我觉得这可能是有用的功能。然而,我想不出任何更好的解决办法。从语法上讲,这可能是一个挑战
*def equalsOrContains=((client==server)?'response==schema':'response contains schema')
*匹配equalsOrContains
第二个解决方案。只要我们在MatchType的enum中添加'eqOrCont',然后根据字符串val解析出来,这似乎是可能的?
*def eqOrCont='contains'或'='
*匹配响应eqOrCont架构很抱歉,如果由于知识有限,建议无效。@Dixie我承认我无法理解以上所有内容。我将建议一个技巧,我已经看到一个团队使用。您有两个功能文件,一个像
*match lhs==rhs
,另一个像
*match lhs包含rhs
,您可以在运行时使用条件逻辑调用其中一个。这将100%解决你一直要求的问题。祝你一切顺利!