pub(crate) async fn load_from_program(
    program: fdata::Dictionary,
    pkg_dir: &fidl_fuchsia_io::DirectoryProxy,
) -> Result<Config, anyhow::Error> {
    let fdata::Dictionary { entries, .. } = program;

    // TODO(https://fxbug.dev/92247): read the configuration directly from the `program` section
    // rather than from a packaged config file, once the CML schema supports it.
    let network_config = entries
        .context("`entries` field not set in program")?
        .into_iter()
        .find_map(|fdata::DictionaryEntry { key, value }| {
            (key == NETWORK_CONFIG_PROPERTY_NAME).then(|| value)
        })
        .with_context(|| format!("`{}` missing in program", NETWORK_CONFIG_PROPERTY_NAME))?
        .context("missing value for network configuration property")?;

    // Temporarily allow unreachable patterns while fuchsia.data.DictionaryValue
    // is migrated from `strict` to `flexible`.
    // TODO(https://fxbug.dev/92247): Remove this.
    #[allow(unreachable_patterns)]
    let network_config_path = match *network_config {
        fdata::DictionaryValue::Str(path) => Ok(path),
        fdata::DictionaryValue::StrVec(vec) => Err(anyhow!(
            "`{}` should be a single filepath; got a list: {:?}",
            NETWORK_CONFIG_PROPERTY_NAME,
            vec
        )),
        other => Err(anyhow::anyhow!("encountered unknown DictionaryValue variant: {:?}", other)),
    }?;

    let file = io_util::open_file(
        pkg_dir,
        std::path::Path::new(&network_config_path),
        fidl_fuchsia_io::OPEN_RIGHT_READABLE,
    )
    .with_context(|| format!("opening network config file at {}", network_config_path))?;
    let contents =
        io_util::file::read_to_string(&file).await.context("reading network config file")?;

    contents.parse()
}
/// Loads the virtual network configuration that the test should be run in.
///
/// The configuration should be a JSON file available in the package directory at `pkg_dir`, and the
/// filepath is specified in `program`.
Loads the virtual network configuration that the test should be run in.
The configuration should be a JSON file available in the package directory at `pkg_dir`, and the
filepath is specified in `program`.
Loads the virtual network configuration that the test should be run in . The configuration should be a JSON file available in the package directory at ` pkg_dir ` and the filepath is specified in ` program ` .
pub(crate) async fn load_from_program(
    program: fdata::Dictionary,
    pkg_dir: &fidl_fuchsia_io::DirectoryProxy,
) -> Result<Config, anyhow::Error> {
    let fdata::Dictionary { entries, .. } = program;
    // TODO(https://fxbug.dev/92247): read the configuration directly from the `program` section
    // rather than from a packaged config file, once the CML schema supports it.
    let network_config = entries
        .context("`entries` field not set in program")?
        .into_iter()
        .find_map(|fdata::DictionaryEntry { key, value }| {
            (key == NETWORK_CONFIG_PROPERTY_NAME).then(|| value)
        })
        .with_context(|| format!("`{}` missing in program", NETWORK_CONFIG_PROPERTY_NAME))?
        .context("missing value for network configuration property")?;
    // Temporarily allow unreachable patterns while fuchsia.data.DictionaryValue
    // is migrated from `strict` to `flexible`.
    // TODO(https://fxbug.dev/92247): Remove this.
    #[allow(unreachable_patterns)]
    let network_config_path = match *network_config {
        fdata::DictionaryValue::Str(path) => Ok(path),
        fdata::DictionaryValue::StrVec(vec) => Err(anyhow!(
            "`{}` should be a single filepath; got a list: {:?}",
            NETWORK_CONFIG_PROPERTY_NAME,
            vec
        )),
        other => Err(anyhow::anyhow!("encountered unknown DictionaryValue variant: {:?}", other)),
    }?;
    let file = io_util::open_file(
        pkg_dir,
        std::path::Path::new(&network_config_path),
        fidl_fuchsia_io::OPEN_RIGHT_READABLE,
    )
    .with_context(|| format!("opening network config file at {}", network_config_path))?;
    let contents =
        io_util::file::read_to_string(&file).await.context("reading network config file")?;
    contents.parse()
}
pub ( crate ) async fn load_from_program ( program : fdata :: Dictionary , pkg_dir : & fidl_fuchsia_io :: DirectoryProxy , ) -> Result < Config , anyhow :: Error > { let fdata :: Dictionary { entries , .. } = program ; // TODO(https://fxbug.dev/92247): read the configuration directly from the `program` section // rather than from a packaged config file, once the CML schema supports it. let network_config = entries . context ( " " ) ? . into_iter ( ) . find_map ( | fdata :: DictionaryEntry { key , value } | { ( key == NETWORK_CONFIG_PROPERTY_NAME ) . then ( | | value ) } ) . with_context ( | | format ! ( " " NETWORK_CONFIG_PROPERTY_NAME ) ) ? . context ( " " ) ? ; // Temporarily allow unreachable patterns while fuchsia.data.DictionaryValue // is migrated from `strict` to `flexible`. // TODO(https://fxbug.dev/92247): Remove this. # [ allow ( unreachable_patterns ) ] let network_config_path = match * network_config { fdata :: DictionaryValue :: Str ( path ) => Ok ( path ) , fdata :: DictionaryValue :: StrVec ( vec ) => Err ( anyhow ! ( " " NETWORK_CONFIG_PROPERTY_NAME vec ) ) , other => Err ( anyhow :: anyhow ! ( " " other ) ) , } ? ; let file = io_util :: open_file ( pkg_dir , std :: path :: Path :: new ( & network_config_path ) , fidl_fuchsia_io :: OPEN_RIGHT_READABLE , ) . with_context ( | | format ! ( " " network_config_path ) ) ? ; let contents = io_util :: file :: read_to_string ( & file ) . await . context ( " " ) ? ; contents . parse ( ) }
Loads the virtual network configuration that the test should be run in.
Loads the virtual network configuration that the test should be run in .
program
fdata::Dictionary
pkg_dir
&fidl_fuchsia_io::DirectoryProxy
program
fdata::Dictionary
pkg_dir
&fidl_fuchsia_io::DirectoryProxy