匹配失败时,Wiremock禁用响应

问题描述 投票:0回答:1

我正在使用Wiremock Standalone 2.21并在请求时使用匹配的查询参数。我希望Wiremock在匹配失败时不响应(或者如果可能的话,可以自定义响应)。这可能吗?谢谢!

response wiremock disable
1个回答
0
投票

这可以使用WireMock中的Stub Priority来实现。

在下面的示例中,有两个规则。一个特定和一个通用捕获所有。这两个规则都将匹配您的输入,但通过设置正确的优先级,您可以确保应用程序遵循所需的匹配顺序。在这种情况下,如果URL是/api/specific-resource,那么第一个规则将映射。如果网址是/api/some-other,那么第二条规则将适用。

具体规则:

{
    "priority": 1,
    "request": {
        "method": "GET",
        "url": "/api/specific-resource"
    },
    "response": {
        "status": 200
    }
}

通用规则:

{
    "priority": 10,
    "request": {
        "method": "GET",
        "urlPattern": "/api/*"
    },
    "response": {
        "status": 200
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.