refactor(接口测试): 优化mock匹配请求头

This commit is contained in:
wxg0103 2024-05-17 16:28:11 +08:00 committed by Craftsman
parent 6d9f017a90
commit 17f41bffcc
2 changed files with 6 additions and 6 deletions

View File

@ -37,7 +37,7 @@ public class MockMatchRule implements Serializable {
if (matchRule == null) {
return true;
}
return matchRule.match(matchParam);
return matchRule.match(matchParam, StringUtils.equals("header", matchType));
}
public boolean requestParamMatch(HttpRequestParam httpRequestParam) {
@ -74,11 +74,11 @@ public class MockMatchRule implements Serializable {
formDataBodyRule.getMatchRules().add(keyValueInfo);
});
}
return formDataBodyRule.match(httpRequestParam.getBodyParamsObj());
return formDataBodyRule.match(httpRequestParam.getBodyParamsObj(), false);
case RAW:
return StringUtils.contains(body.getRawBody().getValue(), httpRequestParam.getRaw());
case WWW_FORM:
return body.getWwwFormBody().match(httpRequestParam.getBodyParamsObj());
return body.getWwwFormBody().match(httpRequestParam.getBodyParamsObj(), false);
default:
return true;
}

View File

@ -15,9 +15,9 @@ public class keyValueMatchRule {
@Schema(description = "匹配规则")
private List<KeyValueInfo> matchRules;
public boolean match(Map<String, String> matchParam) {
if ((MapUtils.isEmpty(matchParam) && CollectionUtils.isNotEmpty(matchRules)) ||
(CollectionUtils.isEmpty(matchRules) && MapUtils.isNotEmpty(matchParam))) {
public boolean match(Map<String, String> matchParam, boolean isHeader) {
if (!isHeader && ((MapUtils.isEmpty(matchParam) && CollectionUtils.isNotEmpty(matchRules)) ||
(CollectionUtils.isEmpty(matchRules) && MapUtils.isNotEmpty(matchParam)))) {
return false;
}
if (isMatchAll) {