Skip to content

Commit f2dc921

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 fa43ac0 commit f2dc921

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
@@ -2003,4 +2003,52 @@ mod tests {
20032003
);
20042004
assert!(diff.has_breaking_changes()); // Tightening is breaking
20052005
}
2006+
2007+
#[test]
2008+
fn test_top_level_and_nested_change_filters() {
2009+
// Test that top_level_changes and nested_changes correctly filter by path depth.
2010+
// This test manually constructs a SchemaDiff to exercise the filtering logic.
2011+
2012+
let top_level_field = create_field_with_id("name", DataType::STRING, false, 1);
2013+
let nested_field = create_field_with_id("street", DataType::STRING, false, 2);
2014+
let deeply_nested_field = create_field_with_id("city", DataType::STRING, false, 3);
2015+
2016+
// Create a diff with mixed top-level and nested changes
2017+
let diff = SchemaDiff {
2018+
added_fields: vec![
2019+
FieldChange {
2020+
field: top_level_field.clone(),
2021+
path: ColumnName::new(["name"]), // Top-level (depth 1)
2022+
},
2023+
FieldChange {
2024+
field: nested_field.clone(),
2025+
path: ColumnName::new(["address", "street"]), // Nested (depth 2)
2026+
},
2027+
],
2028+
removed_fields: vec![FieldChange {
2029+
field: deeply_nested_field.clone(),
2030+
path: ColumnName::new(["user", "address", "city"]), // Deeply nested (depth 3)
2031+
}],
2032+
updated_fields: vec![],
2033+
has_breaking_changes: false,
2034+
};
2035+
2036+
// Test top_level_changes - should only return depth 1 fields
2037+
let (top_added, top_removed, top_updated) = diff.top_level_changes();
2038+
assert_eq!(top_added.len(), 1);
2039+
assert_eq!(top_added[0].path, ColumnName::new(["name"]));
2040+
assert_eq!(top_removed.len(), 0);
2041+
assert_eq!(top_updated.len(), 0);
2042+
2043+
// Test nested_changes - should only return depth > 1 fields
2044+
let (nested_added, nested_removed, nested_updated) = diff.nested_changes();
2045+
assert_eq!(nested_added.len(), 1);
2046+
assert_eq!(nested_added[0].path, ColumnName::new(["address", "street"]));
2047+
assert_eq!(nested_removed.len(), 1);
2048+
assert_eq!(
2049+
nested_removed[0].path,
2050+
ColumnName::new(["user", "address", "city"])
2051+
);
2052+
assert_eq!(nested_updated.len(), 0);
2053+
}
20062054
}

0 commit comments

Comments
 (0)