在 Postman 中验证 'Could not resolve host' 个用例

Validate 'Could not resolve host' use case in Postman

我需要删除一个租户并确保该租户不再可访问。有没有办法在 Postman 中验证 'Could not resolve host' 即 'Error: getaddrinfo',因为此错误是预期的行为?

在终端中执行以下curl命令时

curl https://invaliddomain1281738012732.com -v

显示正确的错误消息

curl: (6) Could not resolve host: invaliddomain1281738012732.com

但是在邮递员中,有没有办法添加一个测试来验证这种行为?

您无法通过直接调用 URL 并对结果编写测试来测试 URL 的有效性,来自 Postman's Learning Center:

Tests will execute after the response is received, so when you click Send, Postman will run your test script when the response data returns from the API.

一个解决方法是直接从“测试”选项卡查询 URL 并在那里断言响应,例如:

pm.test("address doesn't exist", function(){
    pm.sendRequest('https://invaliddomain1281738012732.com', (error, response) => {
        pm.expect(error.errno).to.eql("ENOTFOUND");
    });
})