fix(接口测试): 场景使用mock环境执行,url有误
--bug=1045933 --user=陈建星 [接口测试】接口场景中使用MOCK环境执行,请求URL 地址错误 https://www.tapd.cn/55049933/s/1584279
This commit is contained in:
parent
67b86d4487
commit
589dc65212
|
@ -584,7 +584,7 @@
|
||||||
order by `pos` desc limit 1;
|
order by `pos` desc limit 1;
|
||||||
</select>
|
</select>
|
||||||
<select id="getApiDefinitionExecuteInfo" resultType="io.metersphere.api.dto.ApiDefinitionExecuteInfo">
|
<select id="getApiDefinitionExecuteInfo" resultType="io.metersphere.api.dto.ApiDefinitionExecuteInfo">
|
||||||
select id as resource_id, module_id, path, method
|
select id as resource_id, module_id, path, method, num
|
||||||
from api_definition
|
from api_definition
|
||||||
where protocol = 'HTTP'
|
where protocol = 'HTTP'
|
||||||
and id in
|
and id in
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
|
||||||
|
|
||||||
sampler.setMethod(msHTTPElement.getMethod());
|
sampler.setMethod(msHTTPElement.getMethod());
|
||||||
// path 设置完整的url
|
// path 设置完整的url
|
||||||
sampler.setPath(getPath(msHTTPElement, httpConfig));
|
sampler.setPath(getPath(msHTTPElement, httpConfig, envConfig));
|
||||||
|
|
||||||
setHttpOtherConfig(msHTTPElement.getOtherConfig(), sampler);
|
setHttpOtherConfig(msHTTPElement.getOtherConfig(), sampler);
|
||||||
|
|
||||||
|
@ -182,16 +182,20 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
|
||||||
return authManager;
|
return authManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPath(MsHTTPElement msHTTPElement, HttpConfig httpConfig) {
|
private String getPath(MsHTTPElement msHTTPElement, HttpConfig httpConfig, EnvironmentInfoDTO envConfig) {
|
||||||
String url = msHTTPElement.getPath();
|
String url = msHTTPElement.getPath();
|
||||||
if (httpConfig != null) {
|
if (httpConfig != null) {
|
||||||
// 接口调试没有环境,不取环境的配置
|
// 接口调试没有环境,不取环境的配置
|
||||||
String protocol = httpConfig.getProtocol().toLowerCase();
|
String protocol = httpConfig.getProtocol().toLowerCase();
|
||||||
String hostName = httpConfig.getHostname();
|
String hostName = httpConfig.getHostname();
|
||||||
if (hostName.lastIndexOf("/") == hostName.length() - 1) {
|
if (StringUtils.endsWith(hostName, "/")) {
|
||||||
hostName = hostName.substring(0, hostName.length() - 1);
|
hostName = hostName.substring(0, hostName.length() - 1);
|
||||||
}
|
}
|
||||||
if (url.indexOf("/") == 0) {
|
// 如果是 mock 返回的url格式是 /mock-server/projectNum/apiNum
|
||||||
|
if (BooleanUtils.isTrue(envConfig.getMock()) && msHTTPElement.getNum() != null) {
|
||||||
|
hostName = StringUtils.join(hostName, "/", msHTTPElement.getNum());
|
||||||
|
}
|
||||||
|
if (StringUtils.startsWith(url, "/")) {
|
||||||
url = url.substring(1);
|
url = url.substring(1);
|
||||||
}
|
}
|
||||||
url = protocol + "://" + (hostName + "/" + url);
|
url = protocol + "://" + (hostName + "/" + url);
|
||||||
|
@ -360,10 +364,6 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
|
||||||
match = true;
|
match = true;
|
||||||
}
|
}
|
||||||
if (match) {
|
if (match) {
|
||||||
// 如果是mock 返回的url格式是 /mock-server/projectNum/apiNum
|
|
||||||
if (BooleanUtils.isTrue(envConfig.getMock())) {
|
|
||||||
httpConfig.setHostname(StringUtils.join(httpConfig.getHostname(), "/", msHTTPElement.getNum()));
|
|
||||||
}
|
|
||||||
return httpConfig;
|
return httpConfig;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue