Skip to content

Commit d00dd1d

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 c7071f8 commit d00dd1d

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
@@ -1097,4 +1097,52 @@ mod tests {
10971097
);
10981098
assert_eq!(nested_updated.len(), 0);
10991099
}
1100+
1101+
#[test]
1102+
fn test_top_level_and_nested_change_filters() {
1103+
// Test that top_level_changes and nested_changes correctly filter by path depth.
1104+
// This test manually constructs a SchemaDiff to exercise the filtering logic.
1105+
1106+
let top_level_field = create_field_with_id("name", DataType::STRING, false, 1);
1107+
let nested_field = create_field_with_id("street", DataType::STRING, false, 2);
1108+
let deeply_nested_field = create_field_with_id("city", DataType::STRING, false, 3);
1109+
1110+
// Create a diff with mixed top-level and nested changes
1111+
let diff = SchemaDiff {
1112+
added_fields: vec![
1113+
FieldChange {
1114+
field: top_level_field.clone(),
1115+
path: ColumnName::new(["name"]), // Top-level (depth 1)
1116+
},
1117+
FieldChange {
1118+
field: nested_field.clone(),
1119+
path: ColumnName::new(["address", "street"]), // Nested (depth 2)
1120+
},
1121+
],
1122+
removed_fields: vec![FieldChange {
1123+
field: deeply_nested_field.clone(),
1124+
path: ColumnName::new(["user", "address", "city"]), // Deeply nested (depth 3)
1125+
}],
1126+
updated_fields: vec![],
1127+
has_breaking_changes: false,
1128+
};
1129+
1130+
// Test top_level_changes - should only return depth 1 fields
1131+
let (top_added, top_removed, top_updated) = diff.top_level_changes();
1132+
assert_eq!(top_added.len(), 1);
1133+
assert_eq!(top_added[0].path, ColumnName::new(["name"]));
1134+
assert_eq!(top_removed.len(), 0);
1135+
assert_eq!(top_updated.len(), 0);
1136+
1137+
// Test nested_changes - should only return depth > 1 fields
1138+
let (nested_added, nested_removed, nested_updated) = diff.nested_changes();
1139+
assert_eq!(nested_added.len(), 1);
1140+
assert_eq!(nested_added[0].path, ColumnName::new(["address", "street"]));
1141+
assert_eq!(nested_removed.len(), 1);
1142+
assert_eq!(
1143+
nested_removed[0].path,
1144+
ColumnName::new(["user", "address", "city"])
1145+
);
1146+
assert_eq!(nested_updated.len(), 0);
1147+
}
11001148
}

0 commit comments

Comments
 (0)