This commit is contained in:
@@ -16,7 +16,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
class ReportBuilderTest {
|
||||
|
||||
@Test
|
||||
void wecomMarkdownShowsSkeletonWithoutSeverityAndLocation() {
|
||||
void onlyAddedFieldsHighlightedInNewSkeletonNotWholeJson() {
|
||||
CheckReport report = new CheckReport();
|
||||
report.setRepository("jnpf-java-cloud");
|
||||
report.setBranch("code/redis_change_detection_v1.0");
|
||||
@@ -40,12 +40,14 @@ class ReportBuilderTest {
|
||||
report.getChanges().add(addedMsg);
|
||||
report.getChanges().add(addedErr);
|
||||
|
||||
String oldJson = "{\"taskId\":\"\",\"status\":\"\",\"progress\":{\"totalTenants\":0}}";
|
||||
String newJson = "{\"taskId\":\"\",\"status\":\"\",\"progress\":{\"totalTenants\":0},"
|
||||
+ "\"message\":\"\",\"lastError\":\"\"}";
|
||||
|
||||
KeyStructureChange key = new KeyStructureChange();
|
||||
key.setKeyPattern("saas:period-config:migration:current");
|
||||
key.setOldSkeletonJson(
|
||||
"{\"taskId\":\"\",\"status\":\"\",\"progress\":{\"totalTenants\":0}}");
|
||||
key.setNewSkeletonJson(
|
||||
"{\"taskId\":\"\",\"status\":\"\",\"progress\":{\"totalTenants\":0},\"message\":\"\",\"lastError\":\"\"}");
|
||||
key.setOldSkeletonJson(oldJson);
|
||||
key.setNewSkeletonJson(newJson);
|
||||
key.setSeverity(Severity.P1);
|
||||
key.getFieldDetails().add(addedMsg);
|
||||
key.getFieldDetails().add(addedErr);
|
||||
@@ -53,20 +55,27 @@ class ReportBuilderTest {
|
||||
|
||||
String md = new ReportBuilder("[缓存结构变更]").toMarkdown(report);
|
||||
|
||||
assertTrue(md.startsWith("## [缓存结构变更] jnpf-java-cloud"));
|
||||
assertTrue(md.contains("- Key --> <font color=\"warning\">saas:period-config:migration:current\u200b</font>"));
|
||||
assertTrue(md.contains("value 值从"));
|
||||
assertTrue(md.contains("变更为"));
|
||||
// 新增字段仅在新骨架中 warning 标注
|
||||
assertTrue(md.contains("<font color=\"warning\">`\"message\":\"\"`</font>"));
|
||||
assertTrue(md.contains("<font color=\"warning\">`\"lastError\":\"\"`</font>"));
|
||||
// 旧骨架不应出现这两个字段的 warning
|
||||
assertTrue(md.contains(
|
||||
"- Key --> <font color=\"warning\">**`saas:period-config:migration:current`**</font>"));
|
||||
|
||||
int oldSection = md.indexOf("value 值从");
|
||||
int newSection = md.indexOf("变更为");
|
||||
String oldPart = md.substring(oldSection, newSection);
|
||||
assertFalse(oldPart.contains("<font color=\"warning\">`\"message\":\"\"`</font>"));
|
||||
String newPart = md.substring(newSection);
|
||||
|
||||
// 旧骨架:无 warning,且不能整段被反引号包裹
|
||||
assertFalse(oldPart.contains("<font color=\"warning\">"));
|
||||
assertFalse(oldPart.contains("`" + oldJson + "`"));
|
||||
assertTrue(oldPart.contains(oldJson));
|
||||
|
||||
// 新骨架:仅新增字段带 warning,其余明文
|
||||
assertTrue(newPart.contains("<font color=\"warning\">\"message\":\"\"</font>"));
|
||||
assertTrue(newPart.contains("<font color=\"warning\">\"lastError\":\"\"</font>"));
|
||||
assertTrue(newPart.contains("\"taskId\":\"\""));
|
||||
assertFalse(newPart.contains("<font color=\"warning\">\"taskId\":\"\"</font>"));
|
||||
// 禁止整段代码块
|
||||
assertFalse(newPart.contains("`" + newJson));
|
||||
assertFalse(md.contains("### P0"));
|
||||
assertFalse(md.contains("位置"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,11 +92,12 @@ class ReportBuilderTest {
|
||||
assertEquals(Collections.singleton("lastError"), oldPaths);
|
||||
assertTrue(newPaths.isEmpty());
|
||||
|
||||
String oldMd = SkeletonAnnotator.annotateAsCodeBlock(oldJson, oldPaths);
|
||||
String newMd = SkeletonAnnotator.annotateAsCodeBlock(newJson, newPaths);
|
||||
assertTrue(oldMd.contains("<font color=\"warning\">`\"lastError\":\"\"`</font>"));
|
||||
assertFalse(newMd.contains("lastError"));
|
||||
assertTrue(newMd.startsWith("`"));
|
||||
String oldMd = SkeletonAnnotator.annotateForWecom(oldJson, oldPaths);
|
||||
String newMd = SkeletonAnnotator.annotateForWecom(newJson, newPaths);
|
||||
assertTrue(oldMd.contains("<font color=\"warning\">\"lastError\":\"\"</font>"));
|
||||
assertFalse(oldMd.contains("<font color=\"warning\">\"taskId\":\"\"</font>"));
|
||||
assertEquals(newJson, newMd);
|
||||
assertFalse(newMd.startsWith("`"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,11 +124,9 @@ class ReportBuilderTest {
|
||||
|
||||
String console = new ReportBuilder("[缓存结构变更]").toConsole(report);
|
||||
assertTrue(console.contains("======== 字段明细 ========"));
|
||||
assertTrue(console.contains("**位置**: Foo#bar:1"));
|
||||
assertTrue(console.contains("**删除字段**: x"));
|
||||
assertTrue(console.contains("======== 企微 Markdown ========"));
|
||||
assertTrue(console.contains("value 值从"));
|
||||
assertTrue(console.contains("<font color=\"warning\">`\"x\":\"\"`</font>"));
|
||||
assertTrue(console.contains("<font color=\"warning\">\"x\":\"\"</font>"));
|
||||
assertFalse(console.contains("`{\"x\":\"\"}`"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user