|
| 1 | +open Pkg_mgr |
| 2 | + |
| 3 | +let format_cmd cmd_line' = |
| 4 | + let {cmd; params} = cmd_line' in |
| 5 | + Printf.sprintf "%s:%s" cmd (String.concat " " params) |
| 6 | + |
| 7 | +let check exp ac () = |
| 8 | + let exp_str = format_cmd exp in |
| 9 | + let ac_str = ac |> format_cmd in |
| 10 | + let msg = Printf.sprintf "%s -- %s" exp_str ac_str in |
| 11 | + Alcotest.(check string) msg exp_str ac_str |
| 12 | + |
| 13 | +let test_dnf_repo_query_installed = |
| 14 | + [ |
| 15 | + ( "<null>" |
| 16 | + , `Quick |
| 17 | + , check |
| 18 | + { |
| 19 | + cmd= !Xapi_globs.dnf_cmd |
| 20 | + ; params= |
| 21 | + [ |
| 22 | + "repoquery" |
| 23 | + ; "-a" |
| 24 | + ; "--qf" |
| 25 | + ; "%{name}:|%{epoch}:|%{version}:|%{release}:|%{arch}:|%{repoid}" |
| 26 | + ; "--installed" |
| 27 | + ] |
| 28 | + } |
| 29 | + (Pkg_mgr.Dnf_cmd.repoquery_installed ()) |
| 30 | + ) |
| 31 | + ] |
| 32 | + |
| 33 | +let test_dnf_repo_query_updates = |
| 34 | + [ |
| 35 | + ( "<null>" |
| 36 | + , `Quick |
| 37 | + , check |
| 38 | + { |
| 39 | + cmd= !Xapi_globs.dnf_cmd |
| 40 | + ; params= |
| 41 | + [ |
| 42 | + "repoquery" |
| 43 | + ; "-a" |
| 44 | + ; "--disablerepo=*" |
| 45 | + ; "--enablerepo=testrepo1,testrepo2" |
| 46 | + ; "--qf" |
| 47 | + ; "%{name}:|%{epoch}:|%{version}:|%{release}:|%{arch}:|%{repoid}" |
| 48 | + ; "--upgrades" |
| 49 | + ] |
| 50 | + } |
| 51 | + (Pkg_mgr.Dnf_cmd.repoquery_updates |
| 52 | + ~repositories:["testrepo1"; "testrepo2"] |
| 53 | + ) |
| 54 | + ) |
| 55 | + ] |
| 56 | + |
| 57 | +let test_dnf_clean_all_cache = |
| 58 | + [ |
| 59 | + ( "<null>" |
| 60 | + , `Quick |
| 61 | + , check |
| 62 | + {cmd= !Xapi_globs.dnf_cmd; params= ["clean"; "all"]} |
| 63 | + (Pkg_mgr.Dnf_cmd.clean_cache ~repo_name:"*") |
| 64 | + ) |
| 65 | + ] |
| 66 | + |
| 67 | +let test_dnf_clean_repo_cache = |
| 68 | + [ |
| 69 | + ( "<null>" |
| 70 | + , `Quick |
| 71 | + , check |
| 72 | + { |
| 73 | + cmd= !Xapi_globs.dnf_cmd |
| 74 | + ; params= ["--disablerepo=*"; "--enablerepo=test_repo"; "clean"; "all"] |
| 75 | + } |
| 76 | + (Pkg_mgr.Dnf_cmd.clean_cache ~repo_name:"test_repo") |
| 77 | + ) |
| 78 | + ] |
| 79 | + |
| 80 | +let test_dnf_get_pkgs_from_updateinfo = |
| 81 | + let sub_command = "upgrades" in |
| 82 | + let repositories = ["testrepo1"; "testrepo2"] in |
| 83 | + [ |
| 84 | + ( "<null>" |
| 85 | + , `Quick |
| 86 | + , check |
| 87 | + { |
| 88 | + cmd= !Xapi_globs.dnf_cmd |
| 89 | + ; params= |
| 90 | + [ |
| 91 | + "-q" |
| 92 | + ; "--disablerepo=*" |
| 93 | + ; "--enablerepo=testrepo1,testrepo2" |
| 94 | + ; "updateinfo" |
| 95 | + ; "list" |
| 96 | + ; "upgrades" |
| 97 | + ] |
| 98 | + } |
| 99 | + (Pkg_mgr.Dnf_cmd.get_pkgs_from_updateinfo ~sub_command ~repositories) |
| 100 | + ) |
| 101 | + ] |
| 102 | + |
| 103 | +let test_dnf_config_repo = |
| 104 | + let config = ["--setopt=testrepo.accesstoken=file:///some/path"] in |
| 105 | + [ |
| 106 | + ( "<null>" |
| 107 | + , `Quick |
| 108 | + , check |
| 109 | + { |
| 110 | + cmd= !Xapi_globs.dnf_cmd |
| 111 | + ; params= |
| 112 | + [ |
| 113 | + "config-manager" |
| 114 | + ; "--setopt=testrepo.accesstoken=file:///some/path" |
| 115 | + ; "testrepo" |
| 116 | + ] |
| 117 | + } |
| 118 | + (Pkg_mgr.Dnf_cmd.config_repo ~repo_name:"testrepo" ~config) |
| 119 | + ) |
| 120 | + ] |
| 121 | + |
| 122 | +let test_dnf_sync_repo = |
| 123 | + [ |
| 124 | + ( "<null>" |
| 125 | + , `Quick |
| 126 | + , check |
| 127 | + { |
| 128 | + cmd= !Xapi_globs.dnf_cmd |
| 129 | + ; params= |
| 130 | + [ |
| 131 | + "reposync" |
| 132 | + ; "-p" |
| 133 | + ; !Xapi_globs.local_pool_repo_dir |
| 134 | + ; "--downloadcomps" |
| 135 | + ; "--download-metadata" |
| 136 | + ; "--delete" |
| 137 | + ; "--newest-only" |
| 138 | + ; "--repoid=testrepo" |
| 139 | + ] |
| 140 | + } |
| 141 | + (Pkg_mgr.Dnf_cmd.sync_repo ~repo_name:"testrepo") |
| 142 | + ) |
| 143 | + ] |
| 144 | + |
| 145 | +let test_dnf_apply_upgrades = |
| 146 | + [ |
| 147 | + ( "<null>" |
| 148 | + , `Quick |
| 149 | + , check |
| 150 | + { |
| 151 | + cmd= !Xapi_globs.dnf_cmd |
| 152 | + ; params= |
| 153 | + [ |
| 154 | + "-y" |
| 155 | + ; "--disablerepo=*" |
| 156 | + ; "--enablerepo=testrepo1,testrepo2" |
| 157 | + ; "upgrade" |
| 158 | + ] |
| 159 | + } |
| 160 | + (Pkg_mgr.Dnf_cmd.apply_upgrade ~repositories:["testrepo1"; "testrepo2"]) |
| 161 | + ) |
| 162 | + ] |
| 163 | + |
| 164 | +let test_yum_repo_query_installed = |
| 165 | + [ |
| 166 | + ( "<null>" |
| 167 | + , `Quick |
| 168 | + , check |
| 169 | + { |
| 170 | + cmd= !Xapi_globs.repoquery_cmd |
| 171 | + ; params= |
| 172 | + [ |
| 173 | + "-a" |
| 174 | + ; "--pkgnarrow=installed" |
| 175 | + ; "--qf" |
| 176 | + ; "%{name}:|%{epoch}:|%{version}:|%{release}:|%{arch}:|%{repoid}" |
| 177 | + ] |
| 178 | + } |
| 179 | + (Pkg_mgr.Yum_cmd.repoquery_installed ()) |
| 180 | + ) |
| 181 | + ] |
| 182 | + |
| 183 | +let test_yum_clean_all_cache = |
| 184 | + [ |
| 185 | + ( "<null>" |
| 186 | + , `Quick |
| 187 | + , check |
| 188 | + {cmd= !Xapi_globs.yum_cmd; params= ["clean"; "all"]} |
| 189 | + (Pkg_mgr.Yum_cmd.clean_cache ~repo_name:"*") |
| 190 | + ) |
| 191 | + ] |
| 192 | + |
| 193 | +let test_yum_clean_repo_cache = |
| 194 | + [ |
| 195 | + ( "<null>" |
| 196 | + , `Quick |
| 197 | + , check |
| 198 | + { |
| 199 | + cmd= !Xapi_globs.yum_cmd |
| 200 | + ; params= ["--disablerepo=*"; "--enablerepo=test_repo"; "clean"; "all"] |
| 201 | + } |
| 202 | + (Pkg_mgr.Yum_cmd.clean_cache ~repo_name:"test_repo") |
| 203 | + ) |
| 204 | + ] |
| 205 | + |
| 206 | +let test_yum_get_pkgs_from_updateinfo = |
| 207 | + let sub_command = "updates" in |
| 208 | + let repositories = ["testrepo1"; "testrepo2"] in |
| 209 | + [ |
| 210 | + ( "<null>" |
| 211 | + , `Quick |
| 212 | + , check |
| 213 | + { |
| 214 | + cmd= !Xapi_globs.yum_cmd |
| 215 | + ; params= |
| 216 | + [ |
| 217 | + "-q" |
| 218 | + ; "--disablerepo=*" |
| 219 | + ; "--enablerepo=testrepo1,testrepo2" |
| 220 | + ; "updateinfo" |
| 221 | + ; "list" |
| 222 | + ; "updates" |
| 223 | + ] |
| 224 | + } |
| 225 | + (Pkg_mgr.Yum_cmd.get_pkgs_from_updateinfo ~sub_command ~repositories) |
| 226 | + ) |
| 227 | + ] |
| 228 | + |
| 229 | +let test_yum_config_repo = |
| 230 | + let config = ["--setopt=testrepo.accesstoken=file:///some/path"] in |
| 231 | + [ |
| 232 | + ( "<null>" |
| 233 | + , `Quick |
| 234 | + , check |
| 235 | + { |
| 236 | + cmd= !Xapi_globs.yum_config_manager_cmd |
| 237 | + ; params= |
| 238 | + ["--setopt=testrepo.accesstoken=file:///some/path"; "testrepo"] |
| 239 | + } |
| 240 | + (Pkg_mgr.Yum_cmd.config_repo ~repo_name:"testrepo" ~config) |
| 241 | + ) |
| 242 | + ] |
| 243 | + |
| 244 | +let test_yum_sync_repo = |
| 245 | + [ |
| 246 | + ( "<null>" |
| 247 | + , `Quick |
| 248 | + , check |
| 249 | + { |
| 250 | + cmd= !Xapi_globs.reposync_cmd |
| 251 | + ; params= |
| 252 | + [ |
| 253 | + "-p" |
| 254 | + ; !Xapi_globs.local_pool_repo_dir |
| 255 | + ; "--downloadcomps" |
| 256 | + ; "--download-metadata" |
| 257 | + ; "--delete" |
| 258 | + ; "--newest-only" |
| 259 | + ; "--repoid=testrepo" |
| 260 | + ; "--plugins" |
| 261 | + ] |
| 262 | + } |
| 263 | + (Pkg_mgr.Yum_cmd.sync_repo ~repo_name:"testrepo") |
| 264 | + ) |
| 265 | + ] |
| 266 | + |
| 267 | +let test_yum_apply_upgrades = |
| 268 | + [ |
| 269 | + ( "<null>" |
| 270 | + , `Quick |
| 271 | + , check |
| 272 | + { |
| 273 | + cmd= !Xapi_globs.yum_cmd |
| 274 | + ; params= |
| 275 | + [ |
| 276 | + "-y" |
| 277 | + ; "--disablerepo=*" |
| 278 | + ; "--enablerepo=testrepo1,testrepo2" |
| 279 | + ; "upgrade" |
| 280 | + ] |
| 281 | + } |
| 282 | + (Pkg_mgr.Yum_cmd.apply_upgrade ~repositories:["testrepo1"; "testrepo2"]) |
| 283 | + ) |
| 284 | + ] |
| 285 | + |
| 286 | +let test_yum_repo_query_updates = |
| 287 | + [ |
| 288 | + ( "<null>" |
| 289 | + , `Quick |
| 290 | + , check |
| 291 | + { |
| 292 | + cmd= !Xapi_globs.repoquery_cmd |
| 293 | + ; params= |
| 294 | + [ |
| 295 | + "-a" |
| 296 | + ; "--disablerepo=*" |
| 297 | + ; "--enablerepo=testrepo1,testrepo2" |
| 298 | + ; "--qf" |
| 299 | + ; "%{name}:|%{epoch}:|%{version}:|%{release}:|%{arch}:|%{repoid}" |
| 300 | + ; "--pkgnarrow updates" |
| 301 | + ; "--plugins" |
| 302 | + ] |
| 303 | + } |
| 304 | + (Pkg_mgr.Yum_cmd.repoquery_updates |
| 305 | + ~repositories:["testrepo1"; "testrepo2"] |
| 306 | + ) |
| 307 | + ) |
| 308 | + ] |
| 309 | + |
| 310 | +let tests = |
| 311 | + [ |
| 312 | + ("test_dnf_repo_query_installed", test_dnf_repo_query_installed) |
| 313 | + ; ("test_dnf_repo_query_updates", test_dnf_repo_query_updates) |
| 314 | + ; ("test_dnf_clean_all_cache", test_dnf_clean_all_cache) |
| 315 | + ; ("test_dnf_clean_repo_cache", test_dnf_clean_repo_cache) |
| 316 | + ; ("test_dnf_get_pkgs_from_updateinfo", test_dnf_get_pkgs_from_updateinfo) |
| 317 | + ; ("test_dnf_cofig_repo", test_dnf_config_repo) |
| 318 | + ; ("test_dnf_sync_repo", test_dnf_sync_repo) |
| 319 | + ; ("test_dnf_apply_upgrades", test_dnf_apply_upgrades) |
| 320 | + ; ("test_yum_repo_query_installed", test_yum_repo_query_installed) |
| 321 | + ; ("test_yum_clean_all_cache", test_yum_clean_all_cache) |
| 322 | + ; ("test_yum_clean_repo_cache", test_yum_clean_repo_cache) |
| 323 | + ; ("test_yum_get_pkgs_from_updateinfo", test_yum_get_pkgs_from_updateinfo) |
| 324 | + ; ("test_yum_cofig_repo", test_yum_config_repo) |
| 325 | + ; ("test_yum_sync_repo", test_yum_sync_repo) |
| 326 | + ; ("test_yum_apply_upgrades", test_yum_apply_upgrades) |
| 327 | + ; ("test_yum_repo_query_updates", test_yum_repo_query_updates) |
| 328 | + ] |
| 329 | + |
| 330 | +let () = Alcotest.run "Pkg_mgr suite" tests |
0 commit comments