use crate::PackagePath;
use fuchsia_url::test::{random_package_name, random_package_variant};
use proptest::prelude::*;
#[cfg(test)]
use {
crate::{MetaPackage, PackageBuildManifest},
fuchsia_url::test::random_resource_path,
};
#[cfg(test)]
prop_compose! {
fn random_host_path_char()(c in "[a-z0-9]") -> String {
c
}
}
#[cfg(test)]
prop_compose! {
fn random_host_path_component
(min: usize, max: usize)
(s in prop::collection::vec(random_host_path_char(), min..max)) -> String {
s.join("")
}
}
#[cfg(test)]
prop_compose! {
fn random_host_path
(min: usize, max: usize)
(s in prop::collection::vec(random_host_path_component(1, 4), min..max))
-> String
{
s.join("/")
}
}
#[cfg(test)]
prop_compose! {
pub(crate) fn random_external_resource_path()
(s in random_resource_path(1, 4)
.prop_filter(
"External package contents cannot be in the 'meta/' directory",
|s| !s.starts_with("meta/"))
) -> String
{
s
}
}
#[cfg(test)]
prop_compose! {
pub(crate) fn random_far_resource_path()
(s in random_resource_path(1, 4)) -> String
{
format!("meta/{s}")
}
}
#[cfg(test)]
prop_compose! {
pub(crate) fn random_hash()(s: [u8; 32]) -> fuchsia_merkle::Hash {
s.into()
}
}
#[cfg(test)]
prop_compose! {
pub(crate) fn random_merkle_hex()(s in "[[:xdigit:]]{64}") -> String {
s
}
}
#[cfg(test)]
prop_compose! {
fn random_creation_manifest_result()
(external_content in prop::collection::btree_map(
random_external_resource_path(), random_host_path(1, 2), 1..4),
mut far_content in prop::collection::btree_map(
random_far_resource_path(), random_host_path(1, 2), 1..4),)
-> Result<PackageBuildManifest, crate::errors::PackageBuildManifestError>
{
far_content.insert("meta/package".to_string(), "meta/package".to_string());
PackageBuildManifest::from_external_and_far_contents(
external_content, far_content)
}
}
#[cfg(test)]
prop_compose! {
pub(crate) fn random_creation_manifest()
(manifest_result in random_creation_manifest_result().prop_filter(
"path combinations cannot have file/directory collisions, like ['foo', 'foo/bar']",
|r| r.is_ok()
))
-> PackageBuildManifest
{
manifest_result.unwrap()
}
}
#[cfg(test)]
prop_compose! {
pub(crate) fn random_meta_package()(name in random_package_name()) -> MetaPackage {
MetaPackage::from_name_and_variant_zero(name)
}
}
prop_compose! {
pub fn random_package_path()(
name in random_package_name(),
variant in random_package_variant()
) -> PackagePath {
PackagePath::from_name_and_variant(name, variant)
}
}