Skip to content

Commit b7904e3

Browse files
committed
test: add test for new_common_exported_apps TOML generation
Add a test that verifies the mock exported apps command generates valid TOML that can be parsed by the same DesktopFiles deserializer used for real output. This ensures the NullWorking store type will work correctly with the application listing feature.
1 parent 422bb08 commit b7904e3

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/backends/distrobox/distrobox.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,4 +1323,56 @@ Categories=Utility;Security;";
13231323
17 | Crystal Linux | Created 2 minutes ago | docker.io/library/crystal-linux:latest\n"
13241324
);
13251325
}
1326+
1327+
#[test]
1328+
fn stub_exported_apps_generates_valid_toml() {
1329+
// Verify that new_common_exported_apps generates valid TOML that can be parsed
1330+
let exported_apps = DistroboxCommandRunnerResponse::new_common_exported_apps();
1331+
let commands = exported_apps.to_commands();
1332+
1333+
// Find the command that should contain TOML output (distrobox enter ... sh -c ...)
1334+
let toml_command = commands
1335+
.iter()
1336+
.find(|(cmd, _)| {
1337+
cmd.program.to_string_lossy().contains("distrobox")
1338+
&& cmd.args.iter().any(|arg| arg.to_string_lossy() == "enter")
1339+
})
1340+
.expect("Should have a TOML-generating command");
1341+
1342+
let toml_output = toml_command.1().expect("Should generate output");
1343+
1344+
// Verify the TOML is parseable
1345+
let desktop_files: DesktopFiles = toml::from_str(&toml_output)
1346+
.expect("Generated TOML should be valid and parseable");
1347+
1348+
// Verify home_dir is set
1349+
assert_eq!(
1350+
desktop_files.home_dir.to_string_lossy(),
1351+
"/home/me",
1352+
"home_dir should be /home/me"
1353+
);
1354+
1355+
// Verify we have system files (the mock apps should be in system)
1356+
assert!(
1357+
!desktop_files.system.is_empty(),
1358+
"Should have system desktop files"
1359+
);
1360+
1361+
// Verify all system files are valid desktop entries
1362+
for (path, content) in &desktop_files.system {
1363+
assert!(
1364+
path.to_string_lossy().ends_with(".desktop"),
1365+
"Path should end with .desktop: {:?}",
1366+
path
1367+
);
1368+
assert!(
1369+
content.contains("[Desktop Entry]"),
1370+
"Content should be a valid desktop entry"
1371+
);
1372+
assert!(
1373+
content.contains("Name="),
1374+
"Content should have a Name field"
1375+
);
1376+
}
1377+
}
13261378
}

0 commit comments

Comments
 (0)