MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / test_readdir

Function test_readdir

crates/test-programs/src/bin/p3_readdir.rs:38–74  ·  view source on GitHub ↗
(dir: &Descriptor)

Source from the content-addressed store, hash-verified

36}
37
38async fn test_readdir(dir: &Descriptor) {
39 // Check the behavior in an empty directory
40 assert_empty_dir(dir).await;
41
42 dir.open_at(
43 PathFlags::empty(),
44 "file".to_string(),
45 OpenFlags::CREATE,
46 DescriptorFlags::READ | DescriptorFlags::WRITE,
47 )
48 .await
49 .unwrap();
50
51 dir.create_directory_at("nested".to_string()).await.unwrap();
52 let nested = dir
53 .open_at(
54 PathFlags::empty(),
55 "nested".to_string(),
56 OpenFlags::DIRECTORY,
57 DescriptorFlags::empty(),
58 )
59 .await
60 .unwrap();
61
62 let entries = read_dir(dir).await;
63 assert_eq!(entries.len(), 2);
64 assert_eq!(entries[0].name, "file");
65 assert!(matches!(entries[0].type_, DescriptorType::RegularFile));
66 assert_eq!(entries[1].name, "nested");
67 assert!(matches!(entries[1].type_, DescriptorType::Directory));
68
69 assert_empty_dir(&nested).await;
70 drop(nested);
71
72 dir.unlink_file_at("file".to_string()).await.unwrap();
73 dir.remove_directory_at("nested".to_string()).await.unwrap();
74}
75
76async fn test_readdir_lots(dir: &Descriptor) {
77 for count in 0..1000 {

Callers 1

runMethod · 0.85

Calls 10

read_dirFunction · 0.85
assert_empty_dirFunction · 0.70
emptyFunction · 0.50
dropFunction · 0.50
unwrapMethod · 0.45
open_atMethod · 0.45
to_stringMethod · 0.45
create_directory_atMethod · 0.45
unlink_file_atMethod · 0.45
remove_directory_atMethod · 0.45

Tested by

no test coverage detected