Skip to content

Commit 6687346

Browse files
committed
test: Add coverage for top_level_changes and nested_changes methods
Adds a comprehensive unit test that exercises the filtering logic by manually constructing a SchemaDiff with both top-level and nested field changes. This test verifies that the methods correctly filter fields by path depth (length 1 vs length > 1). The test improves code coverage for these methods from 0% to full coverage of the filtering logic, addressing CI coverage requirements.
1 parent f18cf41 commit 6687346

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

kernel/src/schema/diff.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,4 +1665,52 @@ mod tests {
16651665
assert!(updated_paths.contains(&ColumnName::new(["identifier"])));
16661666
assert!(updated_paths.contains(&ColumnName::new(["user", "full_name"])));
16671667
}
1668+
1669+
#[test]
1670+
fn test_top_level_and_nested_change_filters() {
1671+
// Test that top_level_changes and nested_changes correctly filter by path depth.
1672+
// This test manually constructs a SchemaDiff to exercise the filtering logic.
1673+
1674+
let top_level_field = create_field_with_id("name", DataType::STRING, false, 1);
1675+
let nested_field = create_field_with_id("street", DataType::STRING, false, 2);
1676+
let deeply_nested_field = create_field_with_id("city", DataType::STRING, false, 3);
1677+
1678+
// Create a diff with mixed top-level and nested changes
1679+
let diff = SchemaDiff {
1680+
added_fields: vec![
1681+
FieldChange {
1682+
field: top_level_field.clone(),
1683+
path: ColumnName::new(["name"]), // Top-level (depth 1)
1684+
},
1685+
FieldChange {
1686+
field: nested_field.clone(),
1687+
path: ColumnName::new(["address", "street"]), // Nested (depth 2)
1688+
},
1689+
],
1690+
removed_fields: vec![FieldChange {
1691+
field: deeply_nested_field.clone(),
1692+
path: ColumnName::new(["user", "address", "city"]), // Deeply nested (depth 3)
1693+
}],
1694+
updated_fields: vec![],
1695+
has_breaking_changes: false,
1696+
};
1697+
1698+
// Test top_level_changes - should only return depth 1 fields
1699+
let (top_added, top_removed, top_updated) = diff.top_level_changes();
1700+
assert_eq!(top_added.len(), 1);
1701+
assert_eq!(top_added[0].path, ColumnName::new(["name"]));
1702+
assert_eq!(top_removed.len(), 0);
1703+
assert_eq!(top_updated.len(), 0);
1704+
1705+
// Test nested_changes - should only return depth > 1 fields
1706+
let (nested_added, nested_removed, nested_updated) = diff.nested_changes();
1707+
assert_eq!(nested_added.len(), 1);
1708+
assert_eq!(nested_added[0].path, ColumnName::new(["address", "street"]));
1709+
assert_eq!(nested_removed.len(), 1);
1710+
assert_eq!(
1711+
nested_removed[0].path,
1712+
ColumnName::new(["user", "address", "city"])
1713+
);
1714+
assert_eq!(nested_updated.len(), 0);
1715+
}
16681716
}

0 commit comments

Comments
 (0)