1use crate::PackagePath;
6use fuchsia_url::test::{random_package_name, random_package_variant};
7use proptest::prelude::*;
8
9#[cfg(test)]
10use {
11 crate::{MetaPackage, PackageBuildManifest},
12 fuchsia_url::test::random_resource_path,
13};
14
15#[cfg(test)]
16prop_compose! {
17 fn random_host_path_char()(c in "[a-z0-9]") -> String {
26 c
27 }
28}
29
30#[cfg(test)]
31prop_compose! {
32 fn random_host_path_component
33 (min: usize, max: usize)
34 (s in prop::collection::vec(random_host_path_char(), min..max)) -> String {
35 s.join("")
36 }
37}
38
39#[cfg(test)]
40prop_compose! {
41 fn random_host_path
42 (min: usize, max: usize)
43 (s in prop::collection::vec(random_host_path_component(1, 4), min..max))
44 -> String
45 {
46 s.join("/")
47 }
48}
49
50#[cfg(test)]
51prop_compose! {
52 pub(crate) fn random_external_resource_path()
53 (s in random_resource_path(1, 4)
54 .prop_filter(
55 "External package contents cannot be in the 'meta/' directory",
56 |s| !s.starts_with("meta/"))
57 ) -> String
58 {
59 s
60 }
61}
62
63#[cfg(test)]
64prop_compose! {
65 pub(crate) fn random_far_resource_path()
66 (s in random_resource_path(1, 4)) -> String
67 {
68 format!("meta/{s}")
69 }
70}
71
72#[cfg(test)]
73prop_compose! {
74 pub(crate) fn random_hash()(s: [u8; 32]) -> fuchsia_merkle::Hash {
75 s.into()
76 }
77}
78
79#[cfg(test)]
80prop_compose! {
81 pub(crate) fn random_merkle_hex()(s in "[[:xdigit:]]{64}") -> String {
82 s
83 }
84}
85
86#[cfg(test)]
87prop_compose! {
88 fn random_creation_manifest_result()
89 (external_content in prop::collection::btree_map(
90 random_external_resource_path(), random_host_path(1, 2), 1..4),
91 mut far_content in prop::collection::btree_map(
92 random_far_resource_path(), random_host_path(1, 2), 1..4),)
93 -> Result<PackageBuildManifest, crate::errors::PackageBuildManifestError>
94 {
95 far_content.insert("meta/package".to_string(), "meta/package".to_string());
96 PackageBuildManifest::from_external_and_far_contents(
97 external_content, far_content)
98 }
99}
100
101#[cfg(test)]
102prop_compose! {
103 pub(crate) fn random_creation_manifest()
104 (manifest_result in random_creation_manifest_result().prop_filter(
105 "path combinations cannot have file/directory collisions, like ['foo', 'foo/bar']",
106 |r| r.is_ok()
107 ))
108 -> PackageBuildManifest
109 {
110 manifest_result.unwrap()
111 }
112}
113
114#[cfg(test)]
115prop_compose! {
116 pub(crate) fn random_meta_package()(name in random_package_name()) -> MetaPackage {
117 MetaPackage::from_name_and_variant_zero(name)
118 }
119}
120
121prop_compose! {
122 pub fn random_package_path()(
123 name in random_package_name(),
124 variant in random_package_variant()
125 ) -> PackagePath {
126 PackagePath::from_name_and_variant(name, variant)
127 }
128}