test(phase-4): similarasin 建单入口黄金快照——补上 Phase 3 点名的「抄管线」缺口
现有 SimilarAsinSnapshotTest 自建 parser、再抄一份归一/分组,parseAndCreateTask 一次没进、一行库没碰,对 Phase 4 要动的类似 ASIN 与 common 归位零保护。 本笔打真入口:单文件/双文件聚合两条 case,钉住建单校验、scope key、 解析载荷与指针落盘、头行+结果行+scope 三处落库形状与返回 VO 预览。 时钟、雪花 id 不进快照(id 桩固定,taskNo 只渲染前缀)。
This commit is contained in:
+403
@@ -0,0 +1,403 @@
|
||||
package com.nanri.aiimage.modules.similarasin.service.support;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.nanri.aiimage.config.InstanceMetadata;
|
||||
import com.nanri.aiimage.config.SimilarAsinProperties;
|
||||
import com.nanri.aiimage.modules.file.service.LocalFileStorageService;
|
||||
import com.nanri.aiimage.modules.file.service.oss.OssStorageService;
|
||||
import com.nanri.aiimage.modules.similarasin.mapper.SimilarAsinFilterConditionMapper;
|
||||
import com.nanri.aiimage.modules.similarasin.model.dto.SimilarAsinParseRequest;
|
||||
import com.nanri.aiimage.modules.similarasin.model.dto.SimilarAsinSourceFileDto;
|
||||
import com.nanri.aiimage.modules.similarasin.model.vo.SimilarAsinParseVo;
|
||||
import com.nanri.aiimage.modules.similarasin.model.vo.SimilarAsinParsedRowVo;
|
||||
import com.nanri.aiimage.modules.similarasin.service.SimilarAsinImagePrefetchService;
|
||||
import com.nanri.aiimage.modules.similarasin.service.SimilarAsinLlmService;
|
||||
import com.nanri.aiimage.modules.similarasin.service.SimilarAsinTaskCacheService;
|
||||
import com.nanri.aiimage.modules.similarasin.service.SimilarAsinTaskService;
|
||||
import com.nanri.aiimage.modules.similarasin.util.SimilarAsinImageEmbedder;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileResultMapper;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileTaskMapper;
|
||||
import com.nanri.aiimage.modules.task.mapper.TaskChunkMapper;
|
||||
import com.nanri.aiimage.modules.task.mapper.TaskScopeStateMapper;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileResultEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.TaskScopeStateEntity;
|
||||
import com.nanri.aiimage.modules.task.service.TaskDistributedLockService;
|
||||
import com.nanri.aiimage.modules.task.service.TaskFileJobService;
|
||||
import com.nanri.aiimage.modules.task.service.TaskHeartbeatPositionService;
|
||||
import com.nanri.aiimage.modules.task.service.TaskProgressSnapshotService;
|
||||
import com.nanri.aiimage.modules.task.service.TransientPayloadStorageService;
|
||||
import com.nanri.aiimage.modules.usersecret.service.UserApiSecretService;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
|
||||
/**
|
||||
* 相似 ASIN 建单段的现网行为快照(重构蓝图 Phase 4 开工前置)。
|
||||
*
|
||||
* <p>为什么必须补这一支:蓝图 Phase 3 收口时逐支验过「有 golden 是否等于有保护」,
|
||||
* 结论是 {@code SimilarAsinSnapshotTest} **抄管线**——它自建 parser、再抄一份归一/分组,
|
||||
* {@link SimilarAsinTaskService#parseAndCreateTask} 一次没进、一行库没碰,对服务侧改动零保护。
|
||||
* Phase 4 要按业务域搬动 similarasin 的 util 与 common 的 util,动它之前必须有一支
|
||||
* 吃真入口的护栏,否则「搬迁前后对撞相等」这句话没有可对撞的对象。
|
||||
*
|
||||
* <p>快照打的是真 {@code parseAndCreateTask}:建单校验、多文件聚合 scope key、
|
||||
* 解析载荷与载荷指针落盘、头行/结果行/scope 三处落库形状,以及返回 VO 的预览字段。
|
||||
* 时钟、雪花 taskNo、任务 ID 都不进快照(ID 由桩固定,taskNo 只渲染前缀)。
|
||||
*
|
||||
* <p>重新生成:{@code SHUFU_SNAPSHOT_WRITE=true mvn -o test -Dtest=SimilarAsinCreateTaskSnapshotTest}
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SimilarAsinCreateTaskSnapshotTest {
|
||||
|
||||
private static final File GOLDEN_CREATE =
|
||||
new File("src/test/resources/similarasin/golden/create-task-snapshot.txt");
|
||||
|
||||
/** 桩固定任务 ID:雪花号随时间和机器漂移,这里换成定值。 */
|
||||
private static final long FIXED_TASK_ID = 90001L;
|
||||
private static final String FIXED_POINTER = "rustfs:task-parsed/similar-asin/90001/payload.json";
|
||||
private static final String[] HEADERS = {"id", "asin", "国家", "sku", "价格", "url", "标题"};
|
||||
|
||||
@Mock private LocalFileStorageService localFileStorageService;
|
||||
@Mock private OssStorageService ossStorageService;
|
||||
@Mock private com.nanri.aiimage.config.StorageProperties storageProperties;
|
||||
@Mock private FileTaskMapper fileTaskMapper;
|
||||
@Mock private FileResultMapper fileResultMapper;
|
||||
@Mock private TaskScopeStateMapper taskScopeStateMapper;
|
||||
@Mock private TaskChunkMapper taskChunkMapper;
|
||||
@Mock private SimilarAsinFilterConditionMapper filterConditionMapper;
|
||||
@Spy private ObjectMapper objectMapper = new ObjectMapper();
|
||||
@Mock private SimilarAsinLlmService similarAsinLlmService;
|
||||
@Mock private SimilarAsinTaskCacheService taskCacheService;
|
||||
@Mock private SimilarAsinProperties properties;
|
||||
@Mock private TaskFileJobService taskFileJobService;
|
||||
@Mock private TaskDistributedLockService taskDistributedLockService;
|
||||
@Mock private TaskProgressSnapshotService taskProgressSnapshotService;
|
||||
@Mock private TaskHeartbeatPositionService taskHeartbeatPositionService;
|
||||
@Mock private TransientPayloadStorageService transientPayloadStorageService;
|
||||
@Mock private PlatformTransactionManager transactionManager;
|
||||
@Mock private com.nanri.aiimage.common.service.DistributedJobLockService distributedJobLockService;
|
||||
@Mock private InstanceMetadata instanceMetadata;
|
||||
@Mock private SimilarAsinImageEmbedder imageEmbedder;
|
||||
@Mock private SimilarAsinImagePrefetchService imagePrefetchService;
|
||||
@Mock private UserApiSecretService userApiSecretService;
|
||||
|
||||
@InjectMocks private SimilarAsinTaskService service;
|
||||
|
||||
@BeforeAll
|
||||
static void initializeMybatisMetadata() {
|
||||
MapperBuilderAssistant assistant = new MapperBuilderAssistant(new MybatisConfiguration(), "");
|
||||
TableInfoHelper.initTableInfo(assistant, FileTaskEntity.class);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
lenient().when(properties.isBoundedResultAssemblyEnabled()).thenReturn(true);
|
||||
lenient().when(properties.getImageCacheMaxBytes()).thenReturn(256L * 1024L * 1024L);
|
||||
lenient().when(properties.getResultFileTimeoutMinutes()).thenReturn(90);
|
||||
lenient().when(properties.getParseResponsePreviewLimit()).thenReturn(100);
|
||||
lenient().when(properties.getMaxSourceFileBytes()).thenReturn(50L * 1024L * 1024L);
|
||||
lenient().when(properties.getMaxParseRows()).thenReturn(50000);
|
||||
lenient().when(properties.getMaxFieldLength()).thenReturn(2000);
|
||||
lenient().when(transientPayloadStorageService.storeParsedPayloadFast(
|
||||
eq(SimilarAsinTaskService.MODULE_TYPE), anyLong(), anyString(), anyString(), anyBoolean()))
|
||||
.thenReturn(FIXED_POINTER);
|
||||
lenient().doAnswer(invocation -> {
|
||||
FileTaskEntity task = invocation.getArgument(0);
|
||||
task.setId(FIXED_TASK_ID);
|
||||
return 1;
|
||||
}).when(fileTaskMapper).insert(any(FileTaskEntity.class));
|
||||
lenient().when(fileTaskMapper.updateById(any(FileTaskEntity.class))).thenReturn(1);
|
||||
lenient().when(fileResultMapper.insert(any(FileResultEntity.class))).thenReturn(1);
|
||||
lenient().when(taskScopeStateMapper.insert(any(TaskScopeStateEntity.class))).thenReturn(1);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void shutdown() {
|
||||
service.shutdownAssembleExecutor();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// 落库捕获
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
private static final class Captured {
|
||||
private final List<String> events = new ArrayList<>();
|
||||
private String storedPayload;
|
||||
private String storedScopeHash;
|
||||
}
|
||||
|
||||
private Captured capturePersistedEvents() {
|
||||
Captured captured = new Captured();
|
||||
doAnswer(invocation -> {
|
||||
FileTaskEntity task = invocation.getArgument(0);
|
||||
task.setId(FIXED_TASK_ID);
|
||||
captured.events.add("task.insert: " + renderTaskInsert(task));
|
||||
return 1;
|
||||
}).when(fileTaskMapper).insert(any(FileTaskEntity.class));
|
||||
doAnswer(invocation -> {
|
||||
captured.events.add("task.update: " + renderTaskUpdate(invocation.getArgument(0)));
|
||||
return 1;
|
||||
}).when(fileTaskMapper).updateById(any(FileTaskEntity.class));
|
||||
doAnswer(invocation -> {
|
||||
captured.events.add("result.insert: " + renderResultInsert(invocation.getArgument(0)));
|
||||
return 1;
|
||||
}).when(fileResultMapper).insert(any(FileResultEntity.class));
|
||||
doAnswer(invocation -> {
|
||||
captured.events.add("scope.insert: " + renderScopeInsert(invocation.getArgument(0)));
|
||||
return 1;
|
||||
}).when(taskScopeStateMapper).insert(any(TaskScopeStateEntity.class));
|
||||
doAnswer(invocation -> {
|
||||
captured.storedScopeHash = invocation.getArgument(2, String.class);
|
||||
captured.storedPayload = invocation.getArgument(3, String.class);
|
||||
captured.events.add("payload.store: moduleType=" + invocation.getArgument(0, String.class)
|
||||
+ " taskId=" + invocation.getArgument(1, Long.class)
|
||||
+ " scopeHash=" + captured.storedScopeHash
|
||||
+ " payload=" + captured.storedPayload);
|
||||
return FIXED_POINTER;
|
||||
}).when(transientPayloadStorageService).storeParsedPayloadFast(
|
||||
anyString(), anyLong(), anyString(), anyString(), anyBoolean());
|
||||
return captured;
|
||||
}
|
||||
|
||||
private static String renderTaskInsert(FileTaskEntity task) {
|
||||
return "id=" + task.getId()
|
||||
+ " taskNoPrefix=" + taskNoPrefix(task.getTaskNo())
|
||||
+ " moduleType=" + dash(task.getModuleType())
|
||||
+ " taskMode=" + dash(task.getTaskMode())
|
||||
+ " status=" + dash(task.getStatus())
|
||||
+ " sourceFileCount=" + task.getSourceFileCount()
|
||||
+ " ok=" + task.getSuccessFileCount()
|
||||
+ " fail=" + task.getFailedFileCount()
|
||||
+ " userId=" + dash(task.getUserId())
|
||||
+ " createdBy=" + dash(task.getCreatedBy())
|
||||
+ " deviceId=" + dash(task.getDeviceId())
|
||||
+ " requestJsonPresent=" + (task.getRequestJson() != null)
|
||||
+ " resultJson=" + dash(task.getResultJson());
|
||||
}
|
||||
|
||||
private static String renderTaskUpdate(FileTaskEntity task) {
|
||||
return "id=" + task.getId()
|
||||
+ " moduleType=" + dash(task.getModuleType())
|
||||
+ " status=" + dash(task.getStatus())
|
||||
+ " resultJson=" + dash(task.getResultJson());
|
||||
}
|
||||
|
||||
private static String renderResultInsert(FileResultEntity row) {
|
||||
return "taskId=" + dash(row.getTaskId())
|
||||
+ " moduleType=" + dash(row.getModuleType())
|
||||
+ " sourceFilename=" + dash(row.getSourceFilename())
|
||||
+ " sourceFileUrl=" + dash(row.getSourceFileUrl())
|
||||
+ " rowCount=" + dash(row.getRowCount())
|
||||
+ " userId=" + dash(row.getUserId())
|
||||
+ " success=" + dash(row.getSuccess());
|
||||
}
|
||||
|
||||
private static String renderScopeInsert(TaskScopeStateEntity scope) {
|
||||
return "taskId=" + dash(scope.getTaskId())
|
||||
+ " moduleType=" + dash(scope.getModuleType())
|
||||
+ " scopeKey=" + dash(scope.getScopeKey())
|
||||
+ " scopeHash=" + dash(scope.getScopeHash())
|
||||
+ " parsedPayloadJson=" + dash(scope.getParsedPayloadJson())
|
||||
+ " stateJson=" + dash(scope.getStateJson())
|
||||
+ " chunkTotal=" + dash(scope.getChunkTotal())
|
||||
+ " receivedChunkCount=" + dash(scope.getReceivedChunkCount())
|
||||
+ " completed=" + dash(scope.getCompleted());
|
||||
}
|
||||
|
||||
private static String renderVo(SimilarAsinParseVo vo) {
|
||||
List<String> asins = new ArrayList<>();
|
||||
for (SimilarAsinParsedRowVo item : vo.getItems()) {
|
||||
asins.add(item.getAsin());
|
||||
}
|
||||
List<String> groupKeys = new ArrayList<>();
|
||||
vo.getGroups().forEach(group -> groupKeys.add(group.getGroupKey() + "#" + group.getItemCount()));
|
||||
return "taskId=" + vo.getTaskId()
|
||||
+ " sourceFilename=" + dash(vo.getSourceFilename())
|
||||
+ " sourceFileCount=" + vo.getSourceFileCount()
|
||||
+ " totalRows=" + vo.getTotalRows()
|
||||
+ " acceptedRows=" + vo.getAcceptedRows()
|
||||
+ " droppedRows=" + vo.getDroppedRows()
|
||||
+ " groupCount=" + vo.getGroupCount()
|
||||
+ " aiPrompt=" + dash(vo.getAiPrompt())
|
||||
+ " imgSwitch=" + vo.getImgSwitch()
|
||||
+ " categorySwitch=" + vo.getCategorySwitch()
|
||||
+ " itemAsins=" + asins
|
||||
+ " groups=" + groupKeys;
|
||||
}
|
||||
|
||||
private static String taskNoPrefix(String taskNo) {
|
||||
if (taskNo == null) {
|
||||
return "-";
|
||||
}
|
||||
int index = taskNo.lastIndexOf('-');
|
||||
return index < 0 ? taskNo : taskNo.substring(0, index);
|
||||
}
|
||||
|
||||
private static String dash(Object value) {
|
||||
String text = value == null ? "" : String.valueOf(value);
|
||||
return text.isBlank() ? "-" : text;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// 夹具
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
private static File workbook(List<String[]> rows) throws Exception {
|
||||
File file = Files.createTempFile("similar-asin-create-snapshot-", ".xlsx").toFile();
|
||||
try (XSSFWorkbook wb = new XSSFWorkbook(); FileOutputStream out = new FileOutputStream(file)) {
|
||||
var sheet = wb.createSheet("Sheet1");
|
||||
Row header = sheet.createRow(0);
|
||||
for (int i = 0; i < HEADERS.length; i++) {
|
||||
header.createCell(i).setCellValue(HEADERS[i]);
|
||||
}
|
||||
for (int r = 0; r < rows.size(); r++) {
|
||||
Row row = sheet.createRow(r + 1);
|
||||
String[] data = rows.get(r);
|
||||
for (int c = 0; c < data.length; c++) {
|
||||
row.createCell(c).setCellValue(data[c]);
|
||||
}
|
||||
}
|
||||
wb.write(out);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
private static SimilarAsinSourceFileDto source(String fileKey, String filename) {
|
||||
SimilarAsinSourceFileDto dto = new SimilarAsinSourceFileDto();
|
||||
dto.setFileKey(fileKey);
|
||||
dto.setOriginalFilename(filename);
|
||||
return dto;
|
||||
}
|
||||
|
||||
private static SimilarAsinParseRequest request(List<SimilarAsinSourceFileDto> files) {
|
||||
SimilarAsinParseRequest request = new SimilarAsinParseRequest();
|
||||
request.setUserId(9L);
|
||||
request.setFiles(files);
|
||||
request.setAiPrompt(" ");
|
||||
request.setApiKey("unit-test-key");
|
||||
request.setImgSwitch(Boolean.FALSE);
|
||||
request.setCategorySwitch(Boolean.FALSE);
|
||||
return request;
|
||||
}
|
||||
|
||||
private String runSingleFile() throws Exception {
|
||||
Captured captured = capturePersistedEvents();
|
||||
File file = workbook(List.of(
|
||||
new String[]{"2_1", "B01A", "US", "SKU-1", "19.90", "http://img/a.jpg", "title a"},
|
||||
new String[]{"2_2", "B01B", "DE", "SKU-2", "29.90", "http://img/b.jpg", "title b"},
|
||||
new String[]{"2_3", "B01C", "FR", "SKU-3", "39.90", "http://img/c.jpg", "title c"},
|
||||
new String[]{"3", "B01-ABC", "GB", "SKU-4", "9.90", "http://img/d.jpg", "title d"},
|
||||
new String[]{"4", "B01E", "IT", "SKU-5", "49.90", "http://img/e.jpg", "title e"}));
|
||||
lenient().when(localFileStorageService.findLocalSourceFile("uploads/20261023/one.xlsx")).thenReturn(file);
|
||||
SimilarAsinParseVo vo = service.parseAndCreateTask(
|
||||
request(List.of(source("uploads/20261023/one.xlsx", "one.xlsx"))), "snapshot-device");
|
||||
return renderCase("single-file", captured, vo);
|
||||
}
|
||||
|
||||
private String runTwoFiles() throws Exception {
|
||||
Captured captured = capturePersistedEvents();
|
||||
File first = workbook(List.<String[]>of(
|
||||
new String[]{"1", "B02A", "US", "SKU-A", "11.00", "http://img/x.jpg", "title x"}));
|
||||
File second = workbook(List.<String[]>of(
|
||||
new String[]{"2", "B02B", "DE", "SKU-B", "12.00", "http://img/y.jpg", "title y"}));
|
||||
lenient().when(localFileStorageService.findLocalSourceFile("uploads/20261023/a.xlsx")).thenReturn(first);
|
||||
lenient().when(localFileStorageService.findLocalSourceFile("uploads/20261023/b.xlsx")).thenReturn(second);
|
||||
SimilarAsinParseVo vo = service.parseAndCreateTask(request(List.of(
|
||||
source("uploads/20261023/a.xlsx", "a.xlsx"),
|
||||
source("uploads/20261023/b.xlsx", "b.xlsx"))), "snapshot-device");
|
||||
return renderCase("two-files", captured, vo);
|
||||
}
|
||||
|
||||
private static String renderCase(String name, Captured captured, SimilarAsinParseVo vo) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("== case: ").append(name).append('\n');
|
||||
for (String event : captured.events) {
|
||||
sb.append(event).append('\n');
|
||||
}
|
||||
sb.append("vo: ").append(renderVo(vo)).append('\n');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String runAll() throws Exception {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(runSingleFile()).append('\n');
|
||||
sb.append(runTwoFiles());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String read(File file) throws Exception {
|
||||
return Files.readString(file.toPath(), StandardCharsets.UTF_8).replace("\r\n", "\n");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// 用例
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
void create_task_snapshot_matches_golden() throws Exception {
|
||||
assertEquals(read(GOLDEN_CREATE), runAll(), "建单落库流水与 golden 一致");
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_task_snapshot_is_reproducible() throws Exception {
|
||||
assertEquals(runAll(), runAll(), "同一夹具跑两次流水一致(时钟与雪花 id 不得进快照)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_task_snapshot_golden_is_committed() {
|
||||
assertTrue(GOLDEN_CREATE.isFile(), "golden 文件必须存在并入库: " + GOLDEN_CREATE.getAbsolutePath());
|
||||
assertTrue(GOLDEN_CREATE.length() > 0, "golden 文件非空");
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_task_snapshot_tamper_is_detected() throws Exception {
|
||||
String original = read(GOLDEN_CREATE);
|
||||
assertTrue(original.contains("status=PENDING"), "golden 必须钉住建单初始状态");
|
||||
try {
|
||||
Files.writeString(GOLDEN_CREATE.toPath(), original + "\n# tampered", StandardCharsets.UTF_8);
|
||||
assertTrue(!read(GOLDEN_CREATE).equals(runAll()), "篡改 golden 后断言应失败");
|
||||
} finally {
|
||||
Files.writeString(GOLDEN_CREATE.toPath(), original, StandardCharsets.UTF_8);
|
||||
}
|
||||
assertEquals(original, read(GOLDEN_CREATE), "恢复原始 golden");
|
||||
}
|
||||
|
||||
/** 只在显式点名时写 golden:默认跑测试永远不许改是非源。 */
|
||||
@Test
|
||||
@EnabledIfEnvironmentVariable(named = "SHUFU_SNAPSHOT_WRITE", matches = "true")
|
||||
void write_golden_on_demand() throws Exception {
|
||||
Files.createDirectories(GOLDEN_CREATE.getParentFile().toPath());
|
||||
Files.writeString(GOLDEN_CREATE.toPath(), runAll(), StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user