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 (#57)
  • Loading branch information
coryhh authored Apr 25, 2024
1 parent 92237e2 commit 7678bc3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion arex-compare-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>arex-compare-parent</artifactId>
<groupId>com.arextest</groupId>
<version>0.2.12</version>
<version>0.2.13</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
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());
}


}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.arextest</groupId>
<artifactId>arex-compare-parent</artifactId>
<packaging>pom</packaging>
<version>0.2.12</version>
<version>0.2.13</version>
<modules>
<module>arex-compare-extension</module>
<module>arex-compare-core</module>
Expand Down

0 comments on commit 7678bc3

Please sign in to comment.