gpt4 book ai didi

apache - 使 groovy 请求接受 404 -- 错误 : hudson. AbortException:失败:返回的代码 404 不在接受范围内:[[100‥399]]

转载 作者:行者123 更新时间:2023-12-01 09:14:27 24 4
gpt4 key购买 nike

我正在为我的 api 编写一些集成测试。
现在,我想测试一个返回 404 的请求。
这就是我想要的,但是 groovy/hudson 在我尝试时总是将我的构建标记为失败。
这当然是因为 404 不在可接受的范围内。

我明白这个错误。问题是我不知道如何解决这个问题。

我的 Groovy 文件的一部分:

def testID = "fakeID"
response = httpRequest acceptType: "APPLICATION_JSON",
contentType: "APPLICATION_JSON",
customHeaders: [[name: 'Authorization', value: token]],
url: server+port+"/exams"+testID

有谁知道如何让 groovy 接受这个 404?
提前感谢所有帮助!

最佳答案

您可以使用 validResponseCodes 参数来指定有效响应代码的范围

response = httpRequest acceptType: "APPLICATION_JSON", 
contentType: "APPLICATION_JSON",
customHeaders: [[name: 'Authorization', value: token]],
url: server+port+"/exams"+testID,
validResponseCodes: '200:404'

httpRequest documentation

关于apache - 使 groovy 请求接受 404 -- 错误 : hudson. AbortException:失败:返回的代码 404 不在接受范围内:[[100‥399]],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48250195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com