MCPcopy Create free account
hub / github.com/bootc-dev/bootc / test_runtime_only_dirs

Function test_runtime_only_dirs

crates/lib/src/lints.rs:1115–1190  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1113
1114 #[test]
1115 fn test_runtime_only_dirs() -> Result<()> {
1116 let root = &fixture()?;
1117 let config = &LintExecutionConfig::default();
1118
1119 root.create_dir_all("run")?;
1120 root.create_dir_all("tmp")?;
1121
1122 // Simulate the exact scenario from https://github.com/bootc-dev/bootc/issues/2050:
1123 // podman creates /run/systemd/resolve/stub-resolv.conf as a bind mount
1124 // for DNS, leaving the directory tree behind. When /run/systemd/resolve
1125 // only contains the known runtime file (or is empty because the file is
1126 // a mount point that was filtered), the whole tree should be pruned.
1127 root.create_dir_all("run/systemd/resolve")?;
1128 check_runtime_only_dirs(root, config).unwrap().unwrap();
1129
1130 // Same but with the stub-resolv.conf file actually present
1131 root.write("run/systemd/resolve/stub-resolv.conf", "data")?;
1132 check_runtime_only_dirs(root, config).unwrap().unwrap();
1133 root.remove_file("run/systemd/resolve/stub-resolv.conf")?;
1134
1135 // If there's *other* content under /run/systemd, we should still warn
1136 // about it (the pruning only removes dirs that are solely parents of
1137 // known runtime files).
1138 root.write("run/systemd/resolve/something-else", "data")?;
1139 let Err(e) = check_runtime_only_dirs(root, config).unwrap() else {
1140 unreachable!("expected warning for unknown file under /run/systemd")
1141 };
1142 let msg = e.to_string();
1143 assert!(
1144 msg.contains("/run/systemd/resolve/something-else"),
1145 "should warn about the unknown file: {msg}"
1146 );
1147 // The parent dirs should still appear since they have real children
1148 assert!(
1149 msg.contains("/run/systemd"),
1150 "parent dirs with real children should appear: {msg}"
1151 );
1152 root.remove_file("run/systemd/resolve/something-else")?;
1153
1154 // Unknown directories should still warn
1155 root.create_dir("run/dnf")?;
1156 let Err(e) = check_runtime_only_dirs(root, config).unwrap() else {
1157 unreachable!("expected warning for /run/dnf")
1158 };
1159 let msg = e.to_string();
1160 assert!(
1161 msg.contains("/run/dnf"),
1162 "should warn about /run/dnf: {msg}"
1163 );
1164 assert!(
1165 !msg.contains("/run/systemd"),
1166 "should not mention /run/systemd: {msg}"
1167 );
1168 root.remove_dir("run/dnf")?;
1169
1170 // Files in /run should warn
1171 root.write("run/leaked-file", "data")?;
1172 let Err(e) = check_runtime_only_dirs(root, config).unwrap() else {

Callers

nothing calls this directly

Calls 2

check_runtime_only_dirsFunction · 0.85
fixtureFunction · 0.70

Tested by

no test coverage detected