Skip to content

Commit

Permalink
Use prop_filter to force directory treenode.
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hagemeier <[email protected]>
  • Loading branch information
c-hagem committed Jan 13, 2025
1 parent ab77aaa commit fe1e797
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions mountpoint-s3/tests/reftests/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,21 @@ impl Debug for TreeNode {
/// Leaves are always [TreeNode::File] or an empty [TreeNode::Directory].
/// Parents are always [TreeNode::Directory].
pub fn gen_tree(depth: u32, max_size: u32, max_items: u32, max_width: usize) -> impl Strategy<Value = TreeNode> {
let leaf = any::<FileContent>().prop_map(TreeNode::File);

let strategy = leaf.prop_recursive(
let leaf = prop_oneof![any::<FileContent>().prop_map(TreeNode::File),];
leaf.prop_recursive(
depth, // levels
max_size, // max number of nodes
max_items, // number of items per collection
move |inner| {
// Take the inner strategy and make the recursive cases.
// Since the size of the tree could be zero, this also introduces directories as leaves.
prop::collection::btree_map(any::<Name>(), inner, 0..max_width).prop_map(TreeNode::Directory)
prop_oneof![
// Take the inner strategy and make the recursive cases.
prop::collection::btree_map(any::<Name>(), inner, 0..max_width).prop_map(TreeNode::Directory),
]
},
);

// Ensure the root is always a directory by wrapping the inner strategy
prop::collection::btree_map(any::<Name>(), strategy, 0..max_width).prop_map(TreeNode::Directory)
)
.prop_filter("Root must be a directory", |tree| {
matches!(tree, TreeNode::Directory(_))
})
}

/// Take a generated tree and create the corresponding S3 namespace (list of keys)
Expand Down

0 comments on commit fe1e797

Please sign in to comment.