Skip to content

Commit

Permalink
fix: for comparing only fields with the same name, only nesting one l…
Browse files Browse the repository at this point in the history
…evel down is ignored
  • Loading branch information
rchen9 committed Apr 25, 2024
1 parent 92237e2 commit 5fb86d7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ private boolean isIgnorePath(List<String> fuzzyPath) {
int fuzzyPathSize = fuzzyPath.size();
int ignorePathSize = ignoreNodePath.size();

if (ignorePathSize < fuzzyPathSize) {
// such as parameters/parammap vs parameters
if (fuzzyPathSize - ignorePathSize == 1) {
boolean flag = true;
for (int i = 0; i < ignorePathSize; i++) {
if (!Objects.equals(ignoreNodePath.get(i), fuzzyPath.get(i))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ public void testExpressionNodeIgnore() {
+ " },\n"
+ " {\n"
+ " \"info\": {\n"
+ " \"name\": \"apple\"\n"
+ " \"name\": \"tiktok\"\n"
+ " },\n"
+ " \"age\": 20\n"
+ " }\n"
Expand Down Expand Up @@ -773,5 +773,41 @@ public void testTransFormConfigTest() {
Assertions.assertEquals(1, result.getLogs().size());
}

@Test
public void testParmeter() {
CompareSDK sdk = new CompareSDK();
sdk.getGlobalOptions().putOnlyCompareCoincidentColumn(true);

String str1 = "{\n"
+ " \"parameters\": {\n"
+ " \"parammap\": \"{\\\"link_type\\\":1,\\\"token\\\":\\\"1\\\"}\",\n"
+ " \"tablename\": \"table\"\n"
+ " },\n"
+ " \"body\": \"insert into log (table_name, param_map) values (?, ?)\",\n"
+ " \"dbname\": \"\"\n"
+ " }\n"
+ " ]\n"
+ "}";

String str2 = "{\n"
+ " \"parameters\": {\n"
+ " \"parammap\": \"{\\\"link_type\\\":1}\",\n"
+ " \"tablename\": \"table\"\n"
+ " },\n"
+ " \"body\": \"insert into log (table_name, param_map) values (?, ?)\",\n"
+ " \"dbname\": \"\"\n"
+ " }\n"
+ " ]\n"
+ "}";

CompareOptions compareOptions = CompareOptions.options();
compareOptions.putExclusions(Arrays.asList("body"));
compareOptions.putCategoryType(CategoryType.DATABASE);
compareOptions.putOnlyCompareCoincidentColumn(true);

CompareResult result = sdk.compare(str1, str2, compareOptions);
Assertions.assertEquals(1, result.getLogs().size());
}


}

0 comments on commit 5fb86d7

Please sign in to comment.