在忽略数组顺序的同时匹配响应
match response while ignoring array order
给出以下响应:
* def resp = {"a":[{"c": 2},{"c": 1}, {"c":3}], "b":[6,5,4]}
不管数组的顺序我都想匹配
我知道我可以用 contains
指令来做到这一点,但我认为这需要我做多个匹配模式,例如:
* match resp.a.[*].c contains [3,2,1]
* match resp.b contains [5,4,6]
是否有类似全局配置的东西可以一起忽略数组顺序,或者我必须使用包含滚动?
以下作品。例如,如果需要,您还可以指定数组的大小。
* def response = {"a":[2,1,3], "b":[6,5,4]}
* match response.a contains [3,2,1]
* match response.b contains [5,4,6]
* match response == {"a": "#[] #? _ <4, _ >0", "b": "#[] #? _ <7, _ >3"}
编辑以匹配您更详细的案例:
* def resp = {"a":[{"c": 2},{"c": 1}, {"c":3}], "b":[6,5,4]}
* def inside = {"c" : "#number"}
* def schema = { "a": "#[] #(inside)", "b": "#[] #number" }
* match resp == schema
给出以下响应:
* def resp = {"a":[{"c": 2},{"c": 1}, {"c":3}], "b":[6,5,4]}
不管数组的顺序我都想匹配
我知道我可以用 contains
指令来做到这一点,但我认为这需要我做多个匹配模式,例如:
* match resp.a.[*].c contains [3,2,1]
* match resp.b contains [5,4,6]
是否有类似全局配置的东西可以一起忽略数组顺序,或者我必须使用包含滚动?
以下作品。例如,如果需要,您还可以指定数组的大小。
* def response = {"a":[2,1,3], "b":[6,5,4]}
* match response.a contains [3,2,1]
* match response.b contains [5,4,6]
* match response == {"a": "#[] #? _ <4, _ >0", "b": "#[] #? _ <7, _ >3"}
编辑以匹配您更详细的案例:
* def resp = {"a":[{"c": 2},{"c": 1}, {"c":3}], "b":[6,5,4]}
* def inside = {"c" : "#number"}
* def schema = { "a": "#[] #(inside)", "b": "#[] #number" }
* match resp == schema