@@ -1056,6 +1056,32 @@ mod tests {
10561056 use super :: * ;
10571057 use smol:: block_on;
10581058
1059+ /// Helper to encode a string as hex (matching the shell script's base16 function)
1060+ fn to_hex ( s : & str ) -> String {
1061+ s. bytes ( ) . map ( |b| format ! ( "{:02x}" , b) ) . collect ( )
1062+ }
1063+
1064+ /// Helper to generate TOML output matching the shell script format
1065+ fn make_desktop_files_toml (
1066+ home_dir : & str ,
1067+ system_files : & [ ( & str , & str ) ] ,
1068+ user_files : & [ ( & str , & str ) ] ,
1069+ ) -> String {
1070+ let mut toml = format ! ( "home_dir=\" {}\" \n " , to_hex( home_dir) ) ;
1071+
1072+ toml. push_str ( "[system]\n " ) ;
1073+ for ( path, content) in system_files {
1074+ toml. push_str ( & format ! ( "\" {}\" =\" {}\" \n " , to_hex( path) , to_hex( content) ) ) ;
1075+ }
1076+
1077+ toml. push_str ( "[user]\n " ) ;
1078+ for ( path, content) in user_files {
1079+ toml. push_str ( & format ! ( "\" {}\" =\" {}\" \n " , to_hex( path) , to_hex( content) ) ) ;
1080+ }
1081+
1082+ toml
1083+ }
1084+
10591085 #[ test]
10601086 fn list ( ) -> Result < ( ) , Error > {
10611087 block_on ( async {
@@ -1098,6 +1124,31 @@ d24405b14180 | ubuntu | Created | ghcr.io/ublue-os/ubun
10981124
10991125 #[ test]
11001126 fn list_apps ( ) -> Result < ( ) , Error > {
1127+ let vim_desktop = "[Desktop Entry]
1128+ Type=Application
1129+ Name=Vim
1130+ Exec=/path/to/vim
1131+ Icon=/path/to/icon.png
1132+ Comment=A brief description of my application
1133+ Categories=Utility;Network;" ;
1134+
1135+ let fish_desktop = "[Desktop Entry]
1136+ Type=Application
1137+ Name=Fish
1138+ Exec=/path/to/fish
1139+ Icon=/path/to/icon.png
1140+ Comment=A brief description of my application
1141+ Categories=Utility;Network;" ;
1142+
1143+ let desktop_files_toml = make_desktop_files_toml (
1144+ "/home/me" ,
1145+ & [
1146+ ( "/usr/share/applications/vim.desktop" , vim_desktop) ,
1147+ ( "/usr/share/applications/fish.desktop" , fish_desktop) ,
1148+ ] ,
1149+ & [ ] ,
1150+ ) ;
1151+
11011152 let db = Distrobox :: new (
11021153 NullCommandRunnerBuilder :: new ( )
11031154 . cmd ( & [ "sh" , "-c" , "echo $XDG_DATA_HOME" ] , "" )
@@ -1116,40 +1167,40 @@ d24405b14180 | ubuntu | Created | ghcr.io/ublue-os/ubun
11161167 "-c" ,
11171168 POSIX_FIND_AND_CONCAT_DESKTOP_FILES ,
11181169 ] ,
1119- "# START FILE /usr/share/applications/vim.desktop
1120- [Desktop Entry]
1121- Type=Application
1122- Name=Vim
1123- Exec=/path/to/vim
1124- Icon=/path/to/icon.png
1125- Comment=A brief description of my application
1126- Categories=Utility;Network;
1127- # START FILE /usr/share/applications/fish.desktop
1128- [Desktop Entry]
1129- Type=Application
1130- Name=Fish
1131- Exec=/path/to/fish
1132- Icon=/path/to/icon.png
1133- Comment=A brief description of my application
1134- Categories=Utility;Network;
1135- " ,
1170+ & desktop_files_toml,
11361171 )
11371172 . build ( ) ,
11381173 ) ;
11391174
11401175 let apps = block_on ( db. list_apps ( "ubuntu" ) ) ?;
1141- assert_eq ! ( & apps[ 0 ] . entry. name, "Vim " ) ;
1142- assert_eq ! ( & apps[ 0 ] . entry. exec, "/path/to/vim " ) ;
1143- assert ! ( apps[ 0 ] . exported) ;
1144- assert_eq ! ( & apps[ 1 ] . entry. name, "Fish " ) ;
1145- assert_eq ! ( & apps[ 1 ] . entry. exec, "/path/to/fish " ) ;
1146- assert ! ( ! apps[ 1 ] . exported) ;
1176+ assert_eq ! ( & apps[ 0 ] . entry. name, "Fish " ) ;
1177+ assert_eq ! ( & apps[ 0 ] . entry. exec, "/path/to/fish " ) ;
1178+ assert ! ( ! apps[ 0 ] . exported) ;
1179+ assert_eq ! ( & apps[ 1 ] . entry. name, "Vim " ) ;
1180+ assert_eq ! ( & apps[ 1 ] . entry. exec, "/path/to/vim " ) ;
1181+ assert ! ( apps[ 1 ] . exported) ;
11471182 Ok ( ( ) )
11481183 }
11491184
11501185 #[ test]
11511186 fn list_apps_with_space_in_filename ( ) -> Result < ( ) , Error > {
11521187 // Simulate a desktop file with a space in its filename and ensure it's parsed/export-detected correctly
1188+ let proton_desktop = "[Desktop Entry]
1189+ Type=Application
1190+ Name=Proton Authenticator
1191+ Exec=/usr/bin/proton-authenticator %u
1192+ Icon=proton-authenticator
1193+ Categories=Utility;Security;" ;
1194+
1195+ let desktop_files_toml = make_desktop_files_toml (
1196+ "/home/me" ,
1197+ & [ (
1198+ "/usr/share/applications/Proton Authenticator.desktop" ,
1199+ proton_desktop,
1200+ ) ] ,
1201+ & [ ] ,
1202+ ) ;
1203+
11531204 let db = Distrobox :: new (
11541205 NullCommandRunnerBuilder :: new ( )
11551206 . cmd ( & [ "sh" , "-c" , "echo $XDG_DATA_HOME" ] , "" )
@@ -1168,13 +1219,7 @@ Categories=Utility;Network;
11681219 "-c" ,
11691220 POSIX_FIND_AND_CONCAT_DESKTOP_FILES ,
11701221 ] ,
1171- "# START FILE /usr/share/applications/Proton Authenticator.desktop
1172- [Desktop Entry]
1173- Type=Application
1174- Name=Proton Authenticator
1175- Exec=/usr/bin/proton-authenticator %u
1176- Icon=proton-authenticator
1177- Categories=Utility;Security;" ,
1222+ & desktop_files_toml,
11781223 )
11791224 . build ( ) ,
11801225 ) ;
0 commit comments