Fix bug in export_graph. Don't query the value for the root key.

This commit is contained in:
James Pace 2026-07-26 06:59:31 -04:00
parent 5f5e9c3b8a
commit 0616f9f946
1 changed files with 30 additions and 0 deletions

View File

@ -269,6 +269,11 @@ impl DiagnosticGraph {
let mut statuses = Vec::<DiagnosticStatus>::new(); let mut statuses = Vec::<DiagnosticStatus>::new();
for key in keys_in_order.iter() { for key in keys_in_order.iter() {
if *key == self.root() {
// The root key will always be the first one through this
// loop.
continue;
}
let status_at_key = self.value_of(&key)?; let status_at_key = self.value_of(&key)?;
statuses.push(status_at_key.copy_with_new_name(self.full_name_from_key(&key)?)); statuses.push(status_at_key.copy_with_new_name(self.full_name_from_key(&key)?));
} }
@ -428,4 +433,29 @@ mod tests {
Ok(()) Ok(())
} }
#[test]
fn export_graph() -> Result<()> {
let statuses = vec![
make_a_status_with_name_and_level("/a", DiagnosticLevel::UNSET),
make_a_status_with_name_and_level("/a/b/c", DiagnosticLevel::OK),
make_a_status_with_name_and_level("/a/b", DiagnosticLevel::UNSET),
make_a_status_with_name_and_level("/a/d", DiagnosticLevel::UNSET),
];
let mut graph = DiagnosticGraph::new();
graph.add_status_vec(&statuses)?;
let exported = graph.export_graph()?;
assert!(exported.len() == 4);
// Searching doen the b tree first would also be
// technically correct, but this is the order the implementation
// is currently going with.
assert!(exported[0].name() == "/a");
assert!(exported[1].name() == "/a/d");
assert!(exported[2].name() == "/a/b");
assert!(exported[3].name() == "/a/b/c");
Ok(())
}
} }