fuchsia_pkg_testing/
inspect.rs

1// Copyright 2020 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use diagnostics_hierarchy::DiagnosticsHierarchy;
6use diagnostics_reader::{ArchiveReader, ComponentSelector};
7
8/// Get the Inspect `NodeHierarchy` for the component under test running in the nested environment.
9pub async fn get_inspect_hierarchy(
10    nested_environment_label: &str,
11    component_name: &str,
12) -> DiagnosticsHierarchy {
13    let data = ArchiveReader::inspect()
14        .add_selector(ComponentSelector::new(vec![
15            nested_environment_label.to_string(),
16            component_name.to_string(),
17        ]))
18        .snapshot()
19        .await
20        .expect("read inspect hierarchy")
21        .into_iter()
22        .next()
23        .expect("there's one result");
24    if data.payload.is_none() {
25        log::error!(data:?; "Unexpected empty payload");
26    }
27    data.payload.unwrap()
28}