fix(接口测试): 修复资源池执行带附件的场景时附件找不到的问题

--bug=1010949 --user=宋天阳 【接口测试】github#11246,文件上传类接口,选择资源池执行时会显示找不到文件
https://www.tapd.cn/55049933/s/1115580
This commit is contained in:
song-tianyang 2022-03-09 11:53:52 +08:00 committed by CountryBuilder
parent 6ef5e9607f
commit 7f881317a8
1 changed files with 8 additions and 2 deletions

View File

@ -189,7 +189,7 @@ public class ApiJmeterFileService {
if (file != null && file.exists()) { if (file != null && file.exists()) {
byte[] fileByte = FileUtils.fileToByte(file); byte[] fileByte = FileUtils.fileToByte(file);
if (fileByte != null) { if (fileByte != null) {
multipartFiles.put(file.getName(), fileByte); multipartFiles.put(file.getAbsolutePath(), fileByte);
} }
} }
} }
@ -198,6 +198,7 @@ public class ApiJmeterFileService {
} }
private byte[] zipFilesToByteArray(String testId, HashTree hashTree) { private byte[] zipFilesToByteArray(String testId, HashTree hashTree) {
String bodyFilePath = FileUtils.BODY_FILE_DIR;
String fileName = testId + ".jmx"; String fileName = testId + ".jmx";
String jmx = new MsTestPlan().getJmx(hashTree); String jmx = new MsTestPlan().getJmx(hashTree);
Map<String, byte[]> files = new HashMap<>(); Map<String, byte[]> files = new HashMap<>();
@ -208,9 +209,14 @@ public class ApiJmeterFileService {
if (multipartFiles != null && !multipartFiles.isEmpty()) { if (multipartFiles != null && !multipartFiles.isEmpty()) {
for (String k : multipartFiles.keySet()) { for (String k : multipartFiles.keySet()) {
byte[] v = multipartFiles.get(k); byte[] v = multipartFiles.get(k);
if(k.startsWith(bodyFilePath)){
files.put(StringUtils.substringAfter(k,bodyFilePath), v);
}else {
LogUtil.error("WARNING:Attachment path is not in body_file_path: " + k);
files.put(k, v); files.put(k, v);
} }
} }
}
return listBytesToZip(files); return listBytesToZip(files);
} }