Skip to content

Commit 9df62ad

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 f266aa7 commit 9df62ad

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
@@ -257,4 +257,52 @@ mod tests {
257257
// In PR 2, this will correctly be 3 (1 removed, 1 added, 1 updated)
258258
assert_eq!(diff.change_count(), 0); // TEMPORARY: Will be 3 in PR 2
259259
}
260+
261+
#[test]
262+
fn test_top_level_and_nested_change_filters() {
263+
// Test that top_level_changes and nested_changes correctly filter by path depth.
264+
// This test manually constructs a SchemaDiff to exercise the filtering logic.
265+
266+
let top_level_field = create_field_with_id("name", DataType::STRING, false, 1);
267+
let nested_field = create_field_with_id("street", DataType::STRING, false, 2);
268+
let deeply_nested_field = create_field_with_id("city", DataType::STRING, false, 3);
269+
270+
// Create a diff with mixed top-level and nested changes
271+
let diff = SchemaDiff {
272+
added_fields: vec![
273+
FieldChange {
274+
field: top_level_field.clone(),
275+
path: ColumnName::new(["name"]), // Top-level (depth 1)
276+
},
277+
FieldChange {
278+
field: nested_field.clone(),
279+
path: ColumnName::new(["address", "street"]), // Nested (depth 2)
280+
},
281+
],
282+
removed_fields: vec![FieldChange {
283+
field: deeply_nested_field.clone(),
284+
path: ColumnName::new(["user", "address", "city"]), // Deeply nested (depth 3)
285+
}],
286+
updated_fields: vec![],
287+
has_breaking_changes: false,
288+
};
289+
290+
// Test top_level_changes - should only return depth 1 fields
291+
let (top_added, top_removed, top_updated) = diff.top_level_changes();
292+
assert_eq!(top_added.len(), 1);
293+
assert_eq!(top_added[0].path, ColumnName::new(["name"]));
294+
assert_eq!(top_removed.len(), 0);
295+
assert_eq!(top_updated.len(), 0);
296+
297+
// Test nested_changes - should only return depth > 1 fields
298+
let (nested_added, nested_removed, nested_updated) = diff.nested_changes();
299+
assert_eq!(nested_added.len(), 1);
300+
assert_eq!(nested_added[0].path, ColumnName::new(["address", "street"]));
301+
assert_eq!(nested_removed.len(), 1);
302+
assert_eq!(
303+
nested_removed[0].path,
304+
ColumnName::new(["user", "address", "city"])
305+
);
306+
assert_eq!(nested_updated.len(), 0);
307+
}
260308
}

0 commit comments

Comments
 (0)